{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# HSU Soiling Model Example\n\nExample of soiling using the HSU model.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "This example shows basic usage of pvlib's HSU Soiling model [1]_ with\n:py:func:`pvlib.soiling.hsu`.\n\n## References\n.. [1] M. Coello and L. Boyle, \"Simple Model For Predicting Time Series\n   Soiling of Photovoltaic Panels,\" in IEEE Journal of Photovoltaics.\n   doi: 10.1109/JPHOTOV.2019.2919628\n\nThis example recreates figure 3A in [1]_ for the Fixed Settling\nVelocity case.\nRainfall data comes from Imperial County, CA TMY3 file\nPM2.5 and PM10 data come from the EPA. First, let's read in the\nweather data and run the HSU soiling model:\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import pathlib\nfrom matplotlib import pyplot as plt\nfrom pvlib import soiling\nimport pvlib\nimport pandas as pd\n\n# get full path to the data directory\nDATA_DIR = pathlib.Path(pvlib.__file__).parent / 'data'\n\n# read rainfall, PM2.5, and PM10 data from file\nimperial_county = pd.read_csv(DATA_DIR / 'soiling_hsu_example_inputs.csv',\n                              index_col=0, parse_dates=True)\nrainfall = imperial_county['rain']\ndepo_veloc = {'2_5': 0.0009, '10': 0.004}  # default values from [1] (m/s)\nrain_accum_period = pd.Timedelta('1h')     # default\ncleaning_threshold = 0.5\ntilt = 30\npm2_5 = imperial_county['PM2_5'].values\npm10 = imperial_county['PM10'].values\n# run the hsu soiling model\nsoiling_ratio = soiling.hsu(rainfall, cleaning_threshold, tilt, pm2_5, pm10,\n                            depo_veloc=depo_veloc,\n                            rain_accum_period=rain_accum_period)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "And now we'll plot the modeled daily soiling ratios and compare\nwith Coello and Boyle Fig 3A:\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "daily_soiling_ratio = soiling_ratio.resample('d').mean()\nfig, ax1 = plt.subplots(figsize=(8, 2))\nax1.plot(daily_soiling_ratio.index, daily_soiling_ratio, marker='.',\n         c='r', label='hsu function output')\nax1.set_ylabel('Daily Soiling Ratio')\nax1.set_ylim(0.79, 1.01)\nax1.set_title('Imperial County TMY')\nax1.legend(loc='center left')\n\ndaily_rain = rainfall.resample('d').sum()\nax2 = ax1.twinx()\nax2.plot(daily_rain.index, daily_rain, marker='.',\n         c='c', label='daily rainfall')\nax2.set_ylabel('Daily Rain (mm)')\nax2.set_ylim(-10, 210)\nax2.legend(loc='center right')\nfig.tight_layout()\nfig.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Here is the original figure from [1]_ for comparison:\n\n<img src=\"file://../../_images/Coello_Boyle_2019_Fig3.png\" alt=\"Figure 3A from the paper showing a simulated soiling signal.\">\n\nNote that this figure shows additional timeseries not calculated here:\nmodeled soiling ratio using the 2015 PRISM rainfall dataset (orange)\nand measured soiling ratio (dashed green).\n\n"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.7.9"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}