{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\nGHI to POA Transposition\n=========================\n\nExample of generating clearsky GHI and POA irradiance.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "This example shows how to use the\n:py:meth:`pvlib.location.Location.get_clearsky` method to generate clearsky\nGHI data as well as how to use the\n:py:meth:`pvlib.irradiance.get_total_irradiance` function to transpose\nGHI data to Plane of Array (POA) irradiance.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "from pvlib import location\nfrom pvlib import irradiance\nimport pandas as pd\nfrom matplotlib import pyplot as plt\n\n# For this example, we will be using Golden, Colorado\ntz = 'MST'\nlat, lon = 39.755, -105.221\n\n# Create location object to store lat, lon, timezone\nsite = location.Location(lat, lon, tz=tz)\n\n\n# Calculate clear-sky GHI and transpose to plane of array\n# Define a function so that we can re-use the sequence of operations with\n# different locations\ndef get_irradiance(site_location, date, tilt, surface_azimuth):\n    # Creates one day's worth of 10 min intervals\n    times = pd.date_range(date, freq='10min', periods=6*24,\n                          tz=site_location.tz)\n    # Generate clearsky data using the Ineichen model, which is the default\n    # The get_clearsky method returns a dataframe with values for GHI, DNI,\n    # and DHI\n    clearsky = site_location.get_clearsky(times)\n    # Get solar azimuth and zenith to pass to the transposition function\n    solar_position = site_location.get_solarposition(times=times)\n    # Use the get_total_irradiance function to transpose the GHI to POA\n    POA_irradiance = irradiance.get_total_irradiance(\n        surface_tilt=tilt,\n        surface_azimuth=surface_azimuth,\n        dni=clearsky['dni'],\n        ghi=clearsky['ghi'],\n        dhi=clearsky['dhi'],\n        solar_zenith=solar_position['apparent_zenith'],\n        solar_azimuth=solar_position['azimuth'])\n    # Return DataFrame with only GHI and POA\n    return pd.DataFrame({'GHI': clearsky['ghi'],\n                         'POA': POA_irradiance['poa_global']})\n\n\n# Get irradiance data for summer and winter solstice, assuming 25 degree tilt\n# and a south facing array\nsummer_irradiance = get_irradiance(site, '06-20-2020', 25, 180)\nwinter_irradiance = get_irradiance(site, '12-21-2020', 25, 180)\n\n# Convert Dataframe Indexes to Hour:Minute format to make plotting easier\nsummer_irradiance.index = summer_irradiance.index.strftime(\"%H:%M\")\nwinter_irradiance.index = winter_irradiance.index.strftime(\"%H:%M\")\n\n# Plot GHI vs. POA for winter and summer\nfig, (ax1, ax2) = plt.subplots(1, 2, sharey=True)\nsummer_irradiance['GHI'].plot(ax=ax1, label='GHI')\nsummer_irradiance['POA'].plot(ax=ax1, label='POA')\nwinter_irradiance['GHI'].plot(ax=ax2, label='GHI')\nwinter_irradiance['POA'].plot(ax=ax2, label='POA')\nax1.set_xlabel('Time of day (Summer)')\nax2.set_xlabel('Time of day (Winter)')\nax1.set_ylabel('Irradiance ($W/m^2$)')\nax1.legend()\nax2.legend()\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Note that in Summer, there is not much gain when comparing POA irradiance to\nGHI. In the winter, however, POA irradiance is significantly higher than\nGHI. This is because, in winter, the sun is much lower in the sky, so a\ntilted array will be at a more optimal angle compared to a flat array.\nIn summer, the sun gets much higher in the sky, and there is very little\ngain for a tilted array compared to a flat array.\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.3"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}