Esempio n. 1
0
def test_ineichen_nans():
    length = 4

    apparent_zenith = np.full(length, 10.)
    apparent_zenith[0] = np.nan

    linke_turbidity = np.full(length, 3.)
    linke_turbidity[1] = np.nan

    dni_extra = np.full(length, 1370.)
    dni_extra[2] = np.nan

    airmass_absolute = np.full(length, 1.)

    expected = OrderedDict()
    expected['ghi'] = np.full(length, np.nan)
    expected['dni'] = np.full(length, np.nan)
    expected['dhi'] = np.full(length, np.nan)

    expected['ghi'][length-1] = 1042.72590228
    expected['dni'][length-1] = 946.35279683
    expected['dhi'][length-1] = 110.75033088

    out = clearsky.ineichen(apparent_zenith, airmass_absolute,
                            linke_turbidity, dni_extra=dni_extra)

    for k, v in expected.items():
        assert_allclose(expected[k], out[k])
Esempio n. 2
0
    def get_clearsky(self, times, model='ineichen', **kwargs):
        """
        Calculate the clear sky estimates of GHI, DNI, and/or DHI
        at this location.
        
        Parameters
        ----------
        times : DatetimeIndex
        
        model : str
            The clear sky model to use.
        
        kwargs passed to the relevant function(s).
        
        Returns
        -------
        clearsky : DataFrame
            Column names are: ``ghi, dni, dhi``.
        """
        
        if model == 'ineichen':
            cs = clearsky.ineichen(times, latitude=self.latitude,
                                   longitude=self.longitude,
                                   altitude=self.altitude,
                                   **kwargs)
        elif model == 'haurwitz':
            solpos = self.get_solarposition(times, **kwargs)
            cs = clearsky.haurwitz(solpos['apparent_zenith'])
        else:
            raise ValueError('{} is not a valid clear sky model'
                             .format(model))

        return cs
Esempio n. 3
0
def test_ineichen_altitude():
    expected = pd.DataFrame(
        np.array([[1134.24312405,  994.95377835,  154.40492924]]),
        columns=['ghi', 'dni', 'dhi'])

    out = clearsky.ineichen(10, 1, 3, altitude=pd.Series(2000))
    assert_frame_equal(expected, out)
Esempio n. 4
0
def test_ineichen_altitude():
    expected = pd.DataFrame(
        np.array([[ 1145.64245696,   994.95377835,   165.80426215]]),
        columns=['ghi', 'dni', 'dhi'])

    out = clearsky.ineichen(10, 1, 3, altitude=pd.Series(2000))
    assert_frame_equal(expected, out)
Esempio n. 5
0
def test_ineichen_dni_extra():
    expected = pd.DataFrame(
        np.array([[ 1053.20547182,   946.35279683,   121.22990042]]),
        columns=['ghi', 'dni', 'dhi'])

    out = clearsky.ineichen(10, 1, 3, dni_extra=pd.Series(1370))
    assert_frame_equal(expected, out)
Esempio n. 6
0
def test_disc_keys():
    clearsky_data = clearsky.ineichen(times, tus, linke_turbidity=3)
    disc_data = irradiance.disc(clearsky_data['ghi'], ephem_data['zenith'], 
                              ephem_data.index)
    assert 'dni' in disc_data.columns
    assert 'kt' in disc_data.columns
    assert 'airmass' in disc_data.columns
Esempio n. 7
0
def test_disc_keys():
    clearsky_data = clearsky.ineichen(times, tus, linke_turbidity=3)
    disc_data = irradiance.disc(clearsky_data['GHI'], ephem_data['zenith'], 
                              ephem_data.index)
    assert 'DNI_gen_DISC' in disc_data.columns
    assert 'Kt_gen_DISC' in disc_data.columns
    assert 'AM' in disc_data.columns
Esempio n. 8
0
def test_ineichen_dni_extra():
    expected = pd.DataFrame(
        np.array([[1042.72590228,  946.35279683,  110.75033088]]),
        columns=['ghi', 'dni', 'dhi'])

    out = clearsky.ineichen(10, 1, 3, dni_extra=pd.Series(1370))
    assert_frame_equal(expected, out)
Esempio n. 9
0
def test_ineichen_series():
    times = pd.date_range(start='2014-06-24', end='2014-06-25', freq='3h',
                          tz='America/Phoenix')
    apparent_zenith = pd.Series(np.array(
        [124.0390863, 113.38779941, 82.85457044, 46.0467599, 10.56413562,
         34.86074109, 72.41687122, 105.69538659, 124.05614124]),
        index=times)
    am = pd.Series(np.array(
        [nan, nan, 6.97935524, 1.32355476, 0.93527685,
         1.12008114, 3.01614096, nan, nan]),
        index=times)
    expected = pd.DataFrame(np.
        array([[   0.        ,    0.        ,    0.        ],
               [   0.        ,    0.        ,    0.        ],
               [  65.49426624,  321.16092181,   25.54562017],
               [ 704.6968125 ,  888.90147035,   87.73601277],
               [1044.1230677 ,  953.24925854,  107.03109696],
               [ 853.02065704,  922.06124712,   96.42909484],
               [ 251.99427693,  655.44925241,   53.9901349 ],
               [   0.        ,    0.        ,    0.        ],
               [   0.        ,    0.        ,    0.        ]]),
                            columns=['ghi', 'dni', 'dhi'],
                            index=times)

    out = clearsky.ineichen(apparent_zenith, am, 3)
    assert_frame_equal(expected, out)
Esempio n. 10
0
def test_ineichen_series_perez_enhancement():
    times = pd.date_range(start='2014-06-24', end='2014-06-25', freq='3h',
                          tz='America/Phoenix')
    apparent_zenith = pd.Series(np.array(
        [124.0390863, 113.38779941, 82.85457044, 46.0467599, 10.56413562,
         34.86074109, 72.41687122, 105.69538659, 124.05614124]),
        index=times)
    am = pd.Series(np.array(
        [nan, nan, 6.97935524, 1.32355476, 0.93527685,
         1.12008114, 3.01614096, nan, nan]),
        index=times)
    expected = pd.DataFrame(np.
        array([[   0.        ,    0.        ,    0.        ],
               [   0.        ,    0.        ,    0.        ],
               [  91.1249279 ,  321.16092171,   51.17628184],
               [ 716.46580547,  888.9014706 ,   99.50500553],
               [1053.42066073,  953.24925905,  116.3286895 ],
               [ 863.54692748,  922.06124652,  106.9553658 ],
               [ 271.06382275,  655.44925213,   73.05968076],
               [   0.        ,    0.        ,    0.        ],
               [   0.        ,    0.        ,    0.        ]]),
                            columns=['ghi', 'dni', 'dhi'],
                            index=times)

    out = clearsky.ineichen(apparent_zenith, am, 3, perez_enhancement=True)
    assert_frame_equal(expected, out)
Esempio n. 11
0
    def get_clearsky(self, times, model='ineichen', **kwargs):
        """
        Calculate the clear sky estimates of GHI, DNI, and/or DHI
        at this location.

        Parameters
        ----------
        times : DatetimeIndex

        model : str
            The clear sky model to use. Must be one of
            'ineichen', 'haurwitz', 'simplified_solis'.

        kwargs passed to the relevant functions. Climatological values
        are assumed in many cases. See code for details.

        Returns
        -------
        clearsky : DataFrame
            Column names are: ``ghi, dni, dhi``.
        """

        if model == 'ineichen':
            cs = clearsky.ineichen(times, latitude=self.latitude,
                                   longitude=self.longitude,
                                   altitude=self.altitude,
                                   **kwargs)
        elif model == 'haurwitz':
            solpos = self.get_solarposition(times, **kwargs)
            cs = clearsky.haurwitz(solpos['apparent_zenith'])
        elif model == 'simplified_solis':

            # these try/excepts define default values that are only
            # evaluated if necessary. ineichen does some of this internally
            try:
                dni_extra = kwargs.pop('dni_extra')
            except KeyError:
                dni_extra = irradiance.extraradiation(times.dayofyear)

            try:
                pressure = kwargs.pop('pressure')
            except KeyError:
                pressure = atmosphere.alt2pres(self.altitude)

            try:
                apparent_elevation = kwargs.pop('apparent_elevation')
            except KeyError:
                solpos = self.get_solarposition(
                    times, pressure=pressure, **kwargs)
                apparent_elevation = solpos['apparent_elevation']

            cs = clearsky.simplified_solis(
                apparent_elevation, pressure=pressure, dni_extra=dni_extra,
                **kwargs)
        else:
            raise ValueError('{} is not a valid clear sky model'
                             .format(model))

        return cs
Esempio n. 12
0
def test_ineichen_scalar_input():
    expected = OrderedDict()
    expected['ghi'] = 1048.592893113678
    expected['dni'] = 942.2081860378344
    expected['dhi'] = 120.6989665520498

    out = clearsky.ineichen(10., 1., 3.)
    for k, v in expected.items():
        assert_allclose(expected[k], out[k])
Esempio n. 13
0
def test_ineichen_scalar_input():
    expected = OrderedDict()
    expected['ghi'] = 1038.159219
    expected['dni'] = 942.2081860378344
    expected['dhi'] = 110.26529293612793

    out = clearsky.ineichen(10., 1., 3.)
    for k, v in expected.items():
        assert_allclose(expected[k], out[k])
Esempio n. 14
0
def test_ineichen_arrays():
    expected = OrderedDict()

    expected['ghi'] = (np.
        array([[[ 1106.78342709,  1064.7691287 ,  1024.34972343],
                [  847.84529406,   815.66047425,   784.69741345],
                [  192.19092519,   184.89521884,   177.87646277]],

               [[  959.12310134,   775.2374976 ,   626.60692548],
                [  734.73092205,   593.86637713,   480.00875328],
                [  166.54997871,   134.61857872,   108.80915072]],

               [[ 1026.15144142,   696.85030591,   473.22483724],
                [  786.0776095 ,   533.81830453,   362.51125692],
                [  178.18932781,   121.00678573,    82.17463061]]]))

    expected['dni'] = (np.
        array([[[ 1024.58284359,   942.20818604,   861.11344424],
                [ 1024.58284359,   942.20818604,   861.11344424],
                [ 1024.58284359,   942.20818604,   861.11344424]],

               [[  687.61305142,   419.14891162,   255.50098235],
                [  687.61305142,   419.14891162,   255.50098235],
                [  687.61305142,   419.14891162,   255.50098235]],

               [[  458.62196014,   186.46177428,    75.80970012],
                [  458.62196014,   186.46177428,    75.80970012],
                [  458.62196014,   186.46177428,    75.80970012]]]))

    expected['dhi'] = (np.
            array([[[  82.20058349,  122.56094266,  163.23627919],
                    [  62.96930021,   93.88712907,  125.04624459],
                    [  14.27398153,   21.28248435,   28.34568241]],

                   [[ 271.51004993,  356.08858598,  371.10594313],
                    [ 207.988765  ,  272.77968255,  284.28364554],
                    [  47.14722539,   61.83413404,   64.44187075]],

                   [[ 567.52948128,  510.38853163,  397.41513712],
                    [ 434.75280544,  390.98029849,  304.4376574 ],
                    [  98.5504602 ,   88.62803842,   69.01041434]]]))

    apparent_zenith = np.linspace(0, 80, 3)
    airmass_absolute = np.linspace(1, 10, 3)
    linke_turbidity = np.linspace(2, 4, 3)

    apparent_zenith, airmass_absolute, linke_turbidity = \
        np.meshgrid(apparent_zenith, airmass_absolute, linke_turbidity)

    out = clearsky.ineichen(apparent_zenith, airmass_absolute, linke_turbidity)

    for k, v in expected.items():
        assert_allclose(expected[k], out[k])
Esempio n. 15
0
def test_ineichen_arrays():
    expected = OrderedDict()

    expected['ghi'] = (np.
        array([[[1095.77074798, 1054.17449885, 1014.15727338],
                [ 839.40909243,  807.54451692,  776.88954373],
                [ 190.27859353,  183.05548067,  176.10656239]],

               [[ 773.49041181,  625.19479557,  505.33080493],
                [ 592.52803177,  478.92699901,  387.10585505],
                [ 134.31520045,  108.56393694,   87.74977339]],

               [[ 545.9968869 ,  370.78162375,  251.79449885],
                [ 418.25788117,  284.03520249,  192.88577665],
                [  94.81136442,   64.38555328,   43.72365587]]]))

    expected['dni'] = (np.
        array([[[1014.38807396,  942.20818604,  861.11344424],
                [1014.38807396,  942.20818604,  861.11344424],
                [1014.38807396,  942.20818604,  861.11344424]],

               [[ 687.61305142,  419.14891162,  255.50098235],
                [ 687.61305142,  419.14891162,  255.50098235],
                [ 687.61305142,  419.14891162,  255.50098235]],

               [[ 458.62196014,  186.46177428,   75.80970012],
                [ 458.62196014,  186.46177428,   75.80970012],
                [ 458.62196014,  186.46177428,   75.80970012]]]))

    expected['dhi'] = (np.
        array([[[ 81.38267402, 111.96631281, 153.04382915],
                [ 62.3427452 ,  85.77117175, 117.23837487],
                [ 14.13195304,  19.44274618,  26.57578203]],

               [[ 85.87736039, 206.04588395, 249.82982258],
                [ 65.78587472, 157.84030442, 191.38074731],
                [ 14.91244713,  35.77949226,  43.38249342]],

               [[ 87.37492676, 184.31984947, 175.98479873],
                [ 66.93307711, 141.19719644, 134.81217714],
                [ 15.17249681,  32.00680597,  30.5594396 ]]]))

    apparent_zenith = np.linspace(0, 80, 3)
    airmass_absolute = np.linspace(1, 10, 3)
    linke_turbidity = np.linspace(2, 4, 3)

    apparent_zenith, airmass_absolute, linke_turbidity = \
        np.meshgrid(apparent_zenith, airmass_absolute, linke_turbidity)

    out = clearsky.ineichen(apparent_zenith, airmass_absolute, linke_turbidity)

    for k, v in expected.items():
        assert_allclose(expected[k], out[k])
Esempio n. 16
0
def test_ineichen_supply_linke():
    expected = pd.DataFrame(np.array([[0.,0.,0.],
                                      [0.,0.,0.],
                                      [40.18673553,322.0649964,80.23287692],
                                      [95.14405816,876.49507151,703.48596755],
                                      [118.45873721,939.81653473,1042.34531752],
                                      [105.36671577,909.113377,851.3283881],
                                      [61.91607984,647.40869542,257.47471759],
                                      [0.,0.,0.],
                                      [0.,0.,0.]]),
                            columns=['dhi', 'dni', 'ghi'],
                            index=times_localized)
    out = clearsky.ineichen(times, tus, linke_turbidity=3)
    assert_frame_equal(expected, out)
Esempio n. 17
0
def test_ineichen_airmass():
    expected = pd.DataFrame(np.array([[0.,0.,0.],
                                      [0.,0.,0.],
                                      [41.70761136,293.72203458,78.22953786],
                                      [95.20590465,876.1650047,703.31872722],
                                      [118.46089555,939.8078753,1042.33896321],
                                      [105.39577655,908.97804342,851.24640259],
                                      [62.35382269,642.91022293,256.55363539],
                                      [0.,0.,0.],
                                      [0.,0.,0.]]),
                            columns=['dhi', 'dni', 'ghi'],
                            index=times_localized)
    out = clearsky.ineichen(times, tus, linke_turbidity=3,
                            airmass_model='simple')
    assert_frame_equal(expected, out)
Esempio n. 18
0
def test_ineichen_required():
    # the clearsky function should call lookup_linke_turbidity by default
    # will fail without scipy
    expected = pd.DataFrame(np.array([[0.,0.,0.],
                                      [0.,0.,0.],
                                      [40.53660309,302.47614235,78.1470311],
                                      [98.88372629,865.98938602,699.93403875],
                                      [122.57870881,931.83716051,1038.62116584],
                                      [109.30270612,899.88002304,847.68806472],
                                      [64.25699595,629.91187925,254.53048144],
                                      [0.,0.,0.],
                                      [0.,0.,0.]]),
                            columns=['dhi', 'dni', 'ghi'],
                            index=times_localized)
    out = clearsky.ineichen(times, tus)
    assert_frame_equal(expected, out)
Esempio n. 19
0
def test_ineichen_required():
    # the clearsky function should call lookup_linke_turbidity by default
    expected = pd.DataFrame(
        np.array([[    0.        ,     0.        ,     0.        ],
                  [    0.        ,     0.        ,     0.        ],
                  [   51.47811191,   265.33462162,    84.48262202],
                  [  105.008507  ,   832.29100407,   682.67761951],
                  [  121.97988054,   901.31821834,  1008.02102657],
                  [  112.57957512,   867.76297247,   824.61702926],
                  [   76.69672675,   588.8462898 ,   254.5808329 ],
                  [    0.        ,     0.        ,     0.        ],
                  [    0.        ,     0.        ,     0.        ]]),
                            columns=['dhi', 'dni', 'ghi'],
                            index=times_localized)
    out = clearsky.ineichen(times_localized, tus.latitude, tus.longitude)
    assert_frame_equal(expected, out)
Esempio n. 20
0
def test_ineichen_supply_linke():
    expected = pd.DataFrame(np.array(
        [[    0.        ,     0.        ,     0.        ],
         [    0.        ,     0.        ,     0.        ],
         [   40.16490879,   321.71856556,    80.12815294],
         [   95.14336873,   876.49252839,   703.47605855],
         [  118.4587024 ,   939.81646535,  1042.34480815],
         [  105.36645492,   909.11265773,   851.32459694],
         [   61.91187639,   647.35889938,   257.42691896],
         [    0.        ,     0.        ,     0.        ],
         [    0.        ,     0.        ,     0.        ]]),
                            columns=['dhi', 'dni', 'ghi'],
                            index=times_localized)
    out = clearsky.ineichen(times_localized, tus.latitude, tus.longitude,
                            altitude=tus.altitude,
                            linke_turbidity=3)
    assert_frame_equal(expected, out)
Esempio n. 21
0
def test_ineichen_airmass():
    expected = pd.DataFrame(
        np.array([[    0.        ,     0.        ,     0.        ],
                  [    0.        ,     0.        ,     0.        ],
                  [   53.90422388,   257.01655613,    85.87406435],
                  [  101.34055688,   842.92925705,   686.39337307],
                  [  117.7573735 ,   909.70367947,  1012.04184961],
                  [  108.6233401 ,   877.30589626,   828.49118038],
                  [   75.23108133,   602.06895546,   257.10961202],
                  [    0.        ,     0.        ,     0.        ],
                  [    0.        ,     0.        ,     0.        ]]),
                            columns=['dhi', 'dni', 'ghi'],
                            index=times_localized)
    out = clearsky.ineichen(times_localized, tus.latitude, tus.longitude,
                            linke_turbidity=3,
                            airmass_model='simple')
    assert_frame_equal(expected, out)
Esempio n. 22
0
def test_ineichen_series():
    tus = Location(32.2, -111, 'US/Arizona', 700)
    times = pd.date_range(start='2014-06-24', end='2014-06-25', freq='3h')
    times_localized = times.tz_localize(tus.tz)
    ephem_data = solarposition.get_solarposition(times_localized, tus.latitude,
                                                 tus.longitude)
    am = atmosphere.relativeairmass(ephem_data['apparent_zenith'])
    am = atmosphere.absoluteairmass(am, atmosphere.alt2pres(tus.altitude))
    expected = pd.DataFrame(np.
        array([[    0.        ,     0.        ,     0.        ],
               [    0.        ,     0.        ,     0.        ],
               [   91.12492792,   321.16092181,    51.17628184],
               [  716.46580533,   888.90147035,    99.5050056 ],
               [ 1053.42066043,   953.24925854,   116.32868969],
               [  863.54692781,   922.06124712,   106.95536561],
               [  271.06382274,   655.44925241,    73.05968071],
               [    0.        ,     0.        ,     0.        ],
               [    0.        ,     0.        ,     0.        ]]),
                            columns=['ghi', 'dni', 'dhi'],
                            index=times_localized)

    out = clearsky.ineichen(ephem_data['apparent_zenith'], am, 3)
    assert_frame_equal(expected, out)
Esempio n. 23
0
def test_ineichen_airmass():
    clearsky.ineichen(times, tus, linke_turbidity=3, airmass_model='simple')
Esempio n. 24
0
def test_ineichen_solpos():
    clearsky.ineichen(times,
                      tus,
                      linke_turbidity=3,
                      solarposition_method='pyephem')
Esempio n. 25
0
from pvlib import irradiance
from pvlib import atmosphere

# setup times and location to be tested.
times = pd.date_range(start=datetime.datetime(2014, 6, 24),
                      end=datetime.datetime(2014, 6, 26),
                      freq='1Min')

tus = Location(32.2, -111, 'US/Arizona', 700)

times_localized = times.tz_localize(tus.tz)

ephem_data = solarposition.get_solarposition(times, tus, method='pyephem')

irrad_data = clearsky.ineichen(times,
                               tus,
                               linke_turbidity=3,
                               solarposition_method='pyephem')

dni_et = irradiance.extraradiation(times.dayofyear)

ghi = irrad_data['GHI']

# the test functions. these are almost all functional tests.
# need to add physical tests.


def test_extraradiation():
    assert_almost_equals(1382, irradiance.extraradiation(300), -1)


def test_extraradiation_dtindex():
Esempio n. 26
0
def test_ineichen_keys():
    clearsky_data = clearsky.ineichen(times, tus, linke_turbidity=3)
    assert 'GHI' in clearsky_data.columns
    assert 'DNI' in clearsky_data.columns
    assert 'DHI' in clearsky_data.columns
Esempio n. 27
0
def test_ineichen_supply_linke():
    clearsky.ineichen(times, tus, linke_turbidity=3)
Esempio n. 28
0
from nose.tools import assert_equals, assert_almost_equals

from pvlib import tmy
from pvlib import pvsystem
from pvlib import clearsky
from pvlib import irradiance
from pvlib import atmosphere
from pvlib import solarposition
from pvlib.location import Location

tus = Location(32.2, -111, 'US/Arizona', 700, 'Tucson')
times = pd.date_range(start=datetime.datetime(2014, 1, 1),
                      end=datetime.datetime(2014, 1, 2),
                      freq='1Min')
ephem_data = solarposition.get_solarposition(times, tus, method='pyephem')
irrad_data = clearsky.ineichen(times, tus, solarposition_method='pyephem')
aoi = irradiance.aoi(0, 0, ephem_data['apparent_zenith'],
                     ephem_data['apparent_azimuth'])
am = atmosphere.relativeairmass(ephem_data.apparent_zenith)

pvlib_abspath = os.path.dirname(os.path.abspath(inspect.getfile(tmy)))

tmy3_testfile = os.path.join(pvlib_abspath, 'data', '703165TY.csv')
tmy2_testfile = os.path.join(pvlib_abspath, 'data', '12839.tm2')

tmy3_data, tmy3_metadata = tmy.readtmy3(tmy3_testfile)
tmy2_data, tmy2_metadata = tmy.readtmy2(tmy2_testfile)


def test_systemdef_tmy3():
    expected = {
Esempio n. 29
0
from nose.tools import assert_equals, assert_almost_equals

from pvlib import tmy
from pvlib import pvsystem
from pvlib import clearsky
from pvlib import irradiance
from pvlib import atmosphere
from pvlib import solarposition
from pvlib.location import Location

tus = Location(32.2, -111, 'US/Arizona', 700, 'Tucson')
times = pd.date_range(start=datetime.datetime(2014,1,1),
                      end=datetime.datetime(2014,1,2), freq='1Min')
ephem_data = solarposition.get_solarposition(times, tus, method='pyephem')
irrad_data = clearsky.ineichen(times, tus, linke_turbidity=3,
                               solarposition_method='pyephem')
aoi = irradiance.aoi(0, 0, ephem_data['apparent_zenith'],
                     ephem_data['apparent_azimuth'])
am = atmosphere.relativeairmass(ephem_data.apparent_zenith)

meta = {'latitude': 37.8,
        'longitude': -122.3,
        'altitude': 10,
        'Name': 'Oakland',
        'State': 'CA',
        'TZ': -8}

pvlib_abspath = os.path.dirname(os.path.abspath(inspect.getfile(tmy)))

tmy3_testfile = os.path.join(pvlib_abspath, 'data', '703165TY.csv')
tmy2_testfile = os.path.join(pvlib_abspath, 'data', '12839.tm2')
Esempio n. 30
0
def test_ineichen_supply_linke():
    clearsky.ineichen(times, tus, linke_turbidity=3)
from pvlib import clearsky
from pvlib import solarposition
from pvlib import irradiance
from pvlib import atmosphere

# setup times and location to be tested.
times = pd.date_range(start=datetime.datetime(2014,6,24), 
                      end=datetime.datetime(2014,6,26), freq='1Min')

tus = Location(32.2, -111, 'US/Arizona', 700)

times_localized = times.tz_localize(tus.tz)

ephem_data = solarposition.get_solarposition(times, tus, method='pyephem')

irrad_data = clearsky.ineichen(times, tus, solarposition_method='pyephem')

dni_et = irradiance.extraradiation(times.dayofyear)

ghi = irrad_data['GHI']


# the test functions. these are almost all functional tests.
# need to add physical tests.

def test_extraradiation():
    assert_almost_equals(1382, irradiance.extraradiation(300), -1)
    
def test_extraradiation_dtindex():
    irradiance.extraradiation(times)
    
Esempio n. 32
0
def test_ineichen_airmass():
    clearsky.ineichen(times, tus, linke_turbidity=3, airmass_model="simple")
Esempio n. 33
0
def test_dirint():
    clearsky_data = clearsky.ineichen(times, tus.latitude, tus.longitude,
                                      linke_turbidity=3)
    pressure = 93193.
    dirint_data = irradiance.dirint(clearsky_data['ghi'], ephem_data['zenith'], 
                                    ephem_data.index, pressure=pressure)
Esempio n. 34
0
    def get_clearsky(self,
                     times,
                     model='ineichen',
                     solar_position=None,
                     dni_extra=None,
                     **kwargs):
        """
        Calculate the clear sky estimates of GHI, DNI, and/or DHI
        at this location.

        Parameters
        ----------
        times: DatetimeIndex
        model: str, default 'ineichen'
            The clear sky model to use. Must be one of
            'ineichen', 'haurwitz', 'simplified_solis'.
        solar_position : None or DataFrame, default None
            DataFrame with columns 'apparent_zenith', 'zenith',
            'apparent_elevation'.
        dni_extra: None or numeric, default None
            If None, will be calculated from times.

        kwargs
            Extra parameters passed to the relevant functions. Climatological
            values are assumed in many cases. See source code for details!

        Returns
        -------
        clearsky : DataFrame
            Column names are: ``ghi, dni, dhi``.
        """
        if dni_extra is None:
            dni_extra = irradiance.get_extra_radiation(times)

        try:
            pressure = kwargs.pop('pressure')
        except KeyError:
            pressure = atmosphere.alt2pres(self.altitude)

        if solar_position is None:
            solar_position = self.get_solarposition(times,
                                                    pressure=pressure,
                                                    **kwargs)

        apparent_zenith = solar_position['apparent_zenith']
        apparent_elevation = solar_position['apparent_elevation']

        if model == 'ineichen':
            try:
                linke_turbidity = kwargs.pop('linke_turbidity')
            except KeyError:
                interp_turbidity = kwargs.pop('interp_turbidity', True)
                linke_turbidity = clearsky.lookup_linke_turbidity(
                    times,
                    self.latitude,
                    self.longitude,
                    interp_turbidity=interp_turbidity)

            try:
                airmass_absolute = kwargs.pop('airmass_absolute')
            except KeyError:
                airmass_absolute = self.get_airmass(
                    times, solar_position=solar_position)['airmass_absolute']

            cs = clearsky.ineichen(apparent_zenith,
                                   airmass_absolute,
                                   linke_turbidity,
                                   altitude=self.altitude,
                                   dni_extra=dni_extra,
                                   **kwargs)
        elif model == 'haurwitz':
            cs = clearsky.haurwitz(apparent_zenith)
        elif model == 'simplified_solis':
            cs = clearsky.simplified_solis(apparent_elevation,
                                           pressure=pressure,
                                           dni_extra=dni_extra,
                                           **kwargs)
        else:
            raise ValueError(
                '{} is not a valid clear sky model. Must be '
                'one of ineichen, simplified_solis, haurwitz'.format(model))

        return cs
Esempio n. 35
0
def test_ineichen_required():
    # the clearsky function should lookup the linke turbidity on its own
    # will fail without scipy
    clearsky.ineichen(times, tus)
Esempio n. 36
0
from pvlib import irradiance
from pvlib import atmosphere
from pvlib import solarposition
from pvlib.location import Location

latitude = 32.2
longitude = -111
tus = Location(latitude, longitude, 'US/Arizona', 700, 'Tucson')
times = pd.date_range(start=datetime.datetime(2014,1,1),
                      end=datetime.datetime(2014,1,2), freq='1Min')
ephem_data = solarposition.get_solarposition(times,
                                             latitude=latitude,
                                             longitude=longitude,
                                             method='nrel_numpy')
irrad_data = clearsky.ineichen(times, latitude=latitude, longitude=longitude,
                               linke_turbidity=3,
                               solarposition_method='nrel_numpy')
aoi = irradiance.aoi(0, 0, ephem_data['apparent_zenith'],
                     ephem_data['azimuth'])
am = atmosphere.relativeairmass(ephem_data.apparent_zenith)

meta = {'latitude': 37.8,
        'longitude': -122.3,
        'altitude': 10,
        'Name': 'Oakland',
        'State': 'CA',
        'TZ': -8}

pvlib_abspath = os.path.dirname(os.path.abspath(inspect.getfile(tmy)))

tmy3_testfile = os.path.join(pvlib_abspath, 'data', '703165TY.csv')
Esempio n. 37
0
def basic_chain(times,
                latitude,
                longitude,
                module_parameters,
                inverter_parameters,
                irradiance=None,
                weather=None,
                surface_tilt=None,
                surface_azimuth=None,
                orientation_strategy=None,
                transposition_model='haydavies',
                solar_position_method='nrel_numpy',
                airmass_model='kastenyoung1989',
                altitude=None,
                pressure=None,
                **kwargs):
    """
    An experimental function that computes all of the modeling steps
    necessary for calculating power or energy for a PV system at a given
    location.

    Parameters
    ----------
    times : DatetimeIndex
        Times at which to evaluate the model.

    latitude : float.
        Positive is north of the equator.
        Use decimal degrees notation.

    longitude : float.
        Positive is east of the prime meridian.
        Use decimal degrees notation.

    module_parameters : None, dict or Series
        Module parameters as defined by the SAPM.

    inverter_parameters : None, dict or Series
        Inverter parameters as defined by the CEC.

    irradiance : None or DataFrame, default None
        If None, calculates clear sky data.
        Columns must be 'dni', 'ghi', 'dhi'.

    weather : None or DataFrame, default None
        If None, assumes air temperature is 20 C and
        wind speed is 0 m/s.
        Columns must be 'wind_speed', 'temp_air'.

    surface_tilt : None, float or Series, default None
        Surface tilt angles in decimal degrees.
        The tilt angle is defined as degrees from horizontal
        (e.g. surface facing up = 0, surface facing horizon = 90)

    surface_azimuth : None, float or Series, default None
        Surface azimuth angles in decimal degrees.
        The azimuth convention is defined
        as degrees east of north
        (North=0, South=180, East=90, West=270).

    orientation_strategy : None or str, default None
        The strategy for aligning the modules.
        If not None, sets the ``surface_azimuth`` and ``surface_tilt``
        properties of the ``system``. Allowed strategies include 'flat',
        'south_at_latitude_tilt'. Ignored for SingleAxisTracker systems.

    transposition_model : str, default 'haydavies'
        Passed to system.get_irradiance.

    solar_position_method : str, default 'nrel_numpy'
        Passed to solarposition.get_solarposition.

    airmass_model : str, default 'kastenyoung1989'
        Passed to atmosphere.relativeairmass.

    altitude : None or float, default None
        If None, computed from pressure. Assumed to be 0 m
        if pressure is also None.

    pressure : None or float, default None
        If None, computed from altitude. Assumed to be 101325 Pa
        if altitude is also None.

    **kwargs
        Arbitrary keyword arguments.
        See code for details.

    Returns
    -------
    output : (dc, ac)
        Tuple of DC power (with SAPM parameters) (DataFrame) and AC
        power (Series).
    """

    # use surface_tilt and surface_azimuth if provided,
    # otherwise set them using the orientation_strategy
    if surface_tilt is not None and surface_azimuth is not None:
        pass
    elif orientation_strategy is not None:
        surface_tilt, surface_azimuth = \
            get_orientation(orientation_strategy, latitude=latitude)
    else:
        raise ValueError('orientation_strategy or surface_tilt and '
                         'surface_azimuth must be provided')

    times = times

    if altitude is None and pressure is None:
        altitude = 0.
        pressure = 101325.
    elif altitude is None:
        altitude = atmosphere.pres2alt(pressure)
    elif pressure is None:
        pressure = atmosphere.alt2pres(altitude)

    solar_position = solarposition.get_solarposition(
        times,
        latitude,
        longitude,
        altitude=altitude,
        pressure=pressure,
        method=solar_position_method,
        **kwargs)

    # possible error with using apparent zenith with some models
    airmass = atmosphere.relativeairmass(solar_position['apparent_zenith'],
                                         model=airmass_model)
    airmass = atmosphere.absoluteairmass(airmass, pressure)
    dni_extra = pvlib.irradiance.extraradiation(solar_position.index)
    dni_extra = pd.Series(dni_extra, index=solar_position.index)

    aoi = pvlib.irradiance.aoi(surface_tilt, surface_azimuth,
                               solar_position['apparent_zenith'],
                               solar_position['azimuth'])

    if irradiance is None:
        linke_turbidity = clearsky.lookup_linke_turbidity(
            solar_position.index, latitude, longitude)
        irradiance = clearsky.ineichen(solar_position['apparent_zenith'],
                                       airmass,
                                       linke_turbidity,
                                       altitude=altitude,
                                       dni_extra=dni_extra)

    total_irrad = pvlib.irradiance.total_irrad(
        surface_tilt,
        surface_azimuth,
        solar_position['apparent_zenith'],
        solar_position['azimuth'],
        irradiance['dni'],
        irradiance['ghi'],
        irradiance['dhi'],
        model=transposition_model,
        dni_extra=dni_extra)

    if weather is None:
        weather = {'wind_speed': 0, 'temp_air': 20}

    temps = pvsystem.sapm_celltemp(total_irrad['poa_global'],
                                   weather['wind_speed'], weather['temp_air'])

    effective_irradiance = pvsystem.sapm_effective_irradiance(
        total_irrad['poa_direct'], total_irrad['poa_diffuse'], airmass, aoi,
        module_parameters)

    dc = pvsystem.sapm(effective_irradiance, temps['temp_cell'],
                       module_parameters)

    ac = pvsystem.snlinverter(dc['v_mp'], dc['p_mp'], inverter_parameters)

    return dc, ac
Esempio n. 38
0
def test_ineichen_required():
    # the clearsky function should lookup the linke turbidity on its own
    # will fail without scipy
    clearsky.ineichen(times, tus)
Esempio n. 39
0
from conftest import needs_numpy_1_10, requires_scipy

latitude = 32.2
longitude = -111
tus = Location(latitude, longitude, 'US/Arizona', 700, 'Tucson')
times = pd.date_range(start=datetime.datetime(2014, 1, 1),
                      end=datetime.datetime(2014, 1, 2),
                      freq='1Min')
ephem_data = solarposition.get_solarposition(times,
                                             latitude=latitude,
                                             longitude=longitude,
                                             method='nrel_numpy')
am = atmosphere.relativeairmass(ephem_data.apparent_zenith)
irrad_data = clearsky.ineichen(ephem_data['apparent_zenith'],
                               am,
                               linke_turbidity=3)
aoi = irradiance.aoi(0, 0, ephem_data['apparent_zenith'],
                     ephem_data['azimuth'])

meta = {
    'latitude': 37.8,
    'longitude': -122.3,
    'altitude': 10,
    'Name': 'Oakland',
    'State': 'CA',
    'TZ': -8
}

pvlib_abspath = os.path.dirname(os.path.abspath(inspect.getfile(tmy)))
Esempio n. 40
0
def test_ineichen_solpos():
    clearsky.ineichen(times, tus, linke_turbidity=3, solarposition_method="pyephem")
Esempio n. 41
0
from . import requires_ephem

# setup times and location to be tested.
tus = Location(32.2, -111, 'US/Arizona', 700)

# must include night values
times = pd.date_range(start='20140624', end='20140626', freq='1Min', tz=tus.tz)

ephem_data = solarposition.get_solarposition(times,
                                             tus.latitude,
                                             tus.longitude,
                                             method='nrel_numpy')

irrad_data = clearsky.ineichen(times,
                               tus.latitude,
                               tus.longitude,
                               altitude=tus.altitude,
                               linke_turbidity=3,
                               solarposition_method='nrel_numpy')

dni_et = irradiance.extraradiation(times.dayofyear)

ghi = irrad_data['ghi']

# the test functions. these are almost all functional tests.
# need to add physical tests.


def test_extraradiation():
    assert_almost_equals(1382, irradiance.extraradiation(300), -1)

Esempio n. 42
0
def test_ineichen_keys():
    clearsky_data = clearsky.ineichen(times, tus, linke_turbidity=3)
    assert "ghi" in clearsky_data.columns
    assert "dni" in clearsky_data.columns
    assert "dhi" in clearsky_data.columns
Esempio n. 43
0
def test_ineichen_solpos():
    clearsky.ineichen(times_localized,
                      tus.latitude,
                      tus.longitude,
                      linke_turbidity=3,
                      solarposition_method='ephemeris')