{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Flag Sunny Days for a Fixed-Tilt System\n\nFlag sunny days for a fixed-tilt PV system.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Identifying and masking sunny days for a fixed-tilt system is important\nwhen performing future analyses that require filtered sunny day data.\nFor this example we will use data from the fixed-tilt NREL SERF East system\nlocated on the NREL campus in Colorado, USA, and generate a sunny day mask.\nThis data set is publicly available via the PVDAQ database in the\nDOE Open Energy Data Initiative (OEDI)\n(https://data.openei.org/submissions/4568), as system ID 50.\nThis data is timezone-localized.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import pvanalytics\nfrom pvanalytics.features import daytime as day\nfrom pvanalytics.features.orientation import fixed_nrel\nimport matplotlib.pyplot as plt\nimport pandas as pd\nimport pathlib"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "First, read in data from the NREL SERF East fixed-tilt system. This data\nset contains 15-minute interval AC power data.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "pvanalytics_dir = pathlib.Path(pvanalytics.__file__).parent\nfile = pvanalytics_dir / 'data' / 'serf_east_15min_ac_power.csv'\ndata = pd.read_csv(file, index_col=0, parse_dates=True)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Mask day-night periods using the\n:py:func:`pvanalytics.features.daytime.power_or_irradiance` function.\nThen apply :py:func:`pvanalytics.features.orientation.fixed_nrel`\nto the AC power stream and mask the sunny days in the time series.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "daytime_mask = day.power_or_irradiance(data['ac_power'])\n\nfixed_sunny_days = fixed_nrel(data['ac_power'],\n                              daytime_mask)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Plot the AC power stream with the sunny day mask applied to it.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "data['ac_power'].plot()\ndata.loc[fixed_sunny_days, 'ac_power'].plot(ls='', marker='.')\nplt.legend(labels=[\"AC Power\", \"Sunny Day\"],\n           loc=\"upper left\")\nplt.xlabel(\"Date\")\nplt.ylabel(\"AC Power (kW)\")\nplt.tight_layout()\nplt.show()"
      ]
    }
  ],
  "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
}