Exemplo n.º 1
0
def test_spa_python_numba_physical_dst(expected_solpos, golden):
    times = pd.date_range(datetime.datetime(2003, 10, 17, 13, 30, 30),
                          periods=1,
                          freq='D',
                          tz=golden.tz)

    with warnings.catch_warnings():
        # don't warn on method reload or num threads
        warnings.simplefilter("ignore")
        ephem_data = solarposition.spa_python(times,
                                              golden.latitude,
                                              golden.longitude,
                                              pressure=82000,
                                              temperature=11,
                                              delta_t=67,
                                              atmos_refract=0.5667,
                                              how='numba',
                                              numthreads=1)
    expected_solpos.index = times
    assert_frame_equal(expected_solpos, ephem_data[expected_solpos.columns])

    with pytest.warns(UserWarning):
        # test that we get a warning when reloading to use numpy only
        ephem_data = solarposition.spa_python(times,
                                              golden.latitude,
                                              golden.longitude,
                                              pressure=82000,
                                              temperature=11,
                                              delta_t=67,
                                              atmos_refract=0.5667,
                                              how='numpy',
                                              numthreads=1)
Exemplo n.º 2
0
def test_spa_python_numba_physical(expected_solpos, golden_mst):
    times = pd.date_range(datetime.datetime(2003, 10, 17, 12, 30, 30),
                          periods=1,
                          freq='D',
                          tz=golden_mst.tz)
    with warnings.catch_warnings():
        # don't warn on method reload or num threads
        # ensure that numpy is the most recently used method so that
        # we can use the warns filter below
        warnings.simplefilter("ignore")
        ephem_data = solarposition.spa_python(times,
                                              golden_mst.latitude,
                                              golden_mst.longitude,
                                              pressure=82000,
                                              temperature=11,
                                              delta_t=67,
                                              atmos_refract=0.5667,
                                              how='numpy',
                                              numthreads=1)
    with pytest.warns(UserWarning):
        ephem_data = solarposition.spa_python(times,
                                              golden_mst.latitude,
                                              golden_mst.longitude,
                                              pressure=82000,
                                              temperature=11,
                                              delta_t=67,
                                              atmos_refract=0.5667,
                                              how='numba',
                                              numthreads=1)
    expected_solpos.index = times
    assert_frame_equal(expected_solpos, ephem_data[expected_solpos.columns])
def test_spa_python_numba_physical_dst():
    try:
        import numba
    except ImportError:
        raise SkipTest
    vers = numba.__version__.split('.')
    if int(vers[0] + vers[1]) < 17:
        raise SkipTest

    times = pd.date_range(datetime.datetime(2003, 10, 17, 13, 30, 30),
                          periods=1,
                          freq='D',
                          tz=golden.tz)
    ephem_data = solarposition.spa_python(times,
                                          golden.latitude,
                                          golden.longitude,
                                          pressure=82000,
                                          temperature=11,
                                          delta_t=67,
                                          atmos_refract=0.5667,
                                          how='numba',
                                          numthreads=1)
    this_expected = expected.copy()
    this_expected.index = times
    assert_frame_equal(this_expected, ephem_data[expected.columns])
Exemplo n.º 4
0
def test_analytical_azimuth():
    times = pd.DatetimeIndex(start="1/1/2015 0:00", end="12/31/2015 23:00",
                             freq="H").tz_localize('Etc/GMT+8')
    lat, lon = 37.8, -122.25
    lat_rad = np.deg2rad(lat)
    output = solarposition.spa_python(times, lat, lon, 100)
    solar_azimuth = np.deg2rad(output['azimuth'])  # spa
    solar_zenith = np.deg2rad(output['zenith'])
    # spencer
    eot = solarposition.equation_of_time_spencer71(times.dayofyear)
    hour_angle = np.deg2rad(solarposition.hour_angle(times, lon, eot))
    decl = solarposition.declination_spencer71(times.dayofyear)
    zenith = solarposition.solar_zenith_analytical(lat_rad, hour_angle, decl)
    azimuth_1 = solarposition.solar_azimuth_analytical(lat_rad, hour_angle,
                                                       decl, zenith)
    # pvcdrom and cooper
    eot = solarposition.equation_of_time_pvcdrom(times.dayofyear)
    hour_angle = np.deg2rad(solarposition.hour_angle(times, lon, eot))
    decl = solarposition.declination_cooper69(times.dayofyear)
    zenith = solarposition.solar_zenith_analytical(lat_rad, hour_angle, decl)
    azimuth_2 = solarposition.solar_azimuth_analytical(lat_rad, hour_angle,
                                                       decl, zenith)

    idx = np.where(solar_zenith < np.pi/2)
    assert np.allclose(azimuth_1[idx], solar_azimuth.as_matrix()[idx],
                       atol=0.01)
    assert np.allclose(azimuth_2[idx], solar_azimuth.as_matrix()[idx],
                       atol=0.017)
Exemplo n.º 5
0
def test_analytical_azimuth():
    times = pd.DatetimeIndex(start="1/1/2015 0:00", end="12/31/2015 23:00",
                             freq="H").tz_localize('Etc/GMT+8')
    lat, lon = 37.8, -122.25
    lat_rad = np.deg2rad(lat)
    output = solarposition.spa_python(times, lat, lon, 100)
    solar_azimuth = np.deg2rad(output['azimuth'])  # spa
    solar_zenith = np.deg2rad(output['zenith'])
    # spencer
    eot = solarposition.equation_of_time_spencer71(times.dayofyear)
    hour_angle = np.deg2rad(solarposition.hour_angle(times, lon, eot))
    decl = solarposition.declination_spencer71(times.dayofyear)
    zenith = solarposition.solar_zenith_analytical(lat_rad, hour_angle, decl)
    azimuth_1 = solarposition.solar_azimuth_analytical(lat_rad, hour_angle,
                                                       decl, zenith)
    # pvcdrom and cooper
    eot = solarposition.equation_of_time_pvcdrom(times.dayofyear)
    hour_angle = np.deg2rad(solarposition.hour_angle(times, lon, eot))
    decl = solarposition.declination_cooper69(times.dayofyear)
    zenith = solarposition.solar_zenith_analytical(lat_rad, hour_angle, decl)
    azimuth_2 = solarposition.solar_azimuth_analytical(lat_rad, hour_angle,
                                                       decl, zenith)

    idx = np.where(solar_zenith < np.pi/2)
    assert np.allclose(azimuth_1[idx], solar_azimuth.as_matrix()[idx],
                       atol=0.01)
    assert np.allclose(azimuth_2[idx], solar_azimuth.as_matrix()[idx],
                       atol=0.017)
Exemplo n.º 6
0
def test_spa_python_numpy_physical_dst():
    times = pd.date_range(datetime.datetime(2003,10,17,13,30,30), periods=1, freq='D')
    ephem_data = solarposition.spa_python(times, golden, pressure=82000, 
                                          temperature=11, delta_t=67, 
                                          atmos_refract=0.5667,
                                          how='numpy').ix[0]
    assert_almost_equals(50.111622, ephem_data['apparent_zenith'], 6)
    assert_almost_equals(194.340241, ephem_data['azimuth'], 6)
    assert_almost_equals(39.888378, ephem_data['apparent_elevation'], 6)
Exemplo n.º 7
0
def test_equation_of_time():
    times = pd.DatetimeIndex(start="1/1/2015 0:00", end="12/31/2015 23:00",
                             freq="H")
    output = solarposition.spa_python(times, 37.8, -122.25, 100)
    eot = output['equation_of_time']
    eot_rng = eot.max() - eot.min()  # range of values, around 30 minutes
    eot_1 = solarposition.equation_of_time_spencer71(times.dayofyear)
    eot_2 = solarposition.equation_of_time_pvcdrom(times.dayofyear)
    assert np.allclose(eot_1 / eot_rng, eot / eot_rng, atol=0.3)  # spencer
    assert np.allclose(eot_2 / eot_rng, eot / eot_rng, atol=0.4)  # pvcdrom
Exemplo n.º 8
0
def test_spa_python_numba_physical_dst(expected_solpos):
    times = pd.date_range(datetime.datetime(2003,10,17,13,30,30),
                          periods=1, freq='D', tz=golden.tz)
    ephem_data = solarposition.spa_python(times, golden.latitude,
                                          golden.longitude, pressure=82000,
                                          temperature=11, delta_t=67,
                                          atmos_refract=0.5667,
                                          how='numba', numthreads=1)
    expected_solpos.index = times
    assert_frame_equal(expected_solpos, ephem_data[expected_solpos.columns])
Exemplo n.º 9
0
def test_spa_python_numba_physical_dst(expected_solpos):
    times = pd.date_range(datetime.datetime(2003,10,17,13,30,30),
                          periods=1, freq='D', tz=golden.tz)
    ephem_data = solarposition.spa_python(times, golden.latitude,
                                          golden.longitude, pressure=82000,
                                          temperature=11, delta_t=67,
                                          atmos_refract=0.5667,
                                          how='numba', numthreads=1)
    expected_solpos.index = times
    assert_frame_equal(expected_solpos, ephem_data[expected_solpos.columns])
Exemplo n.º 10
0
def test_equation_of_time():
    times = pd.DatetimeIndex(start="1/1/2015 0:00", end="12/31/2015 23:00",
                             freq="H")
    output = solarposition.spa_python(times, 37.8, -122.25, 100)
    eot = output['equation_of_time']
    eot_rng = eot.max() - eot.min()  # range of values, around 30 minutes
    eot_1 = solarposition.equation_of_time_spencer71(times.dayofyear)
    eot_2 = solarposition.equation_of_time_pvcdrom(times.dayofyear)
    assert np.allclose(eot_1 / eot_rng, eot / eot_rng, atol=0.3)  # spencer
    assert np.allclose(eot_2 / eot_rng, eot / eot_rng, atol=0.4)  # pvcdrom
Exemplo n.º 11
0
    def sun_angle(self):
        """Return sun angles as calculated by pvlib.

        could be omitted if rewriting the is_up function
        """
        angles = spa_python(self.date, self.loc[0], self.loc[1])
        self.altitude = angles['elevation'][0]
        azimuth = angles['azimuth'][0]
        # map astronomical to navigational az
        self.azimuth = azimuth + (azimuth < 0) * 360 - 180
        """
def test_spa_python_numpy_physical():
    times = pd.date_range(datetime.datetime(2003,10,17,12,30,30),
                          periods=1, freq='D', tz=golden_mst.tz)
    ephem_data = solarposition.spa_python(times, golden_mst.latitude,
                                          golden_mst.longitude,
                                          pressure=82000,
                                          temperature=11, delta_t=67,
                                          atmos_refract=0.5667,
                                          how='numpy')
    this_expected = expected.copy()
    this_expected.index = times
    assert_frame_equal(this_expected, ephem_data[expected.columns])
Exemplo n.º 13
0
def test_analytical_azimuth():
    times = pd.DatetimeIndex(start="1/1/2015 0:00", end="12/31/2015 23:00",
                             freq="H").tz_localize('Etc/GMT+8')
    lat, lon = 37.8, -122.25
    lat_rad = np.deg2rad(lat)
    output = solarposition.spa_python(times, lat, lon, 100)
    solar_azimuth = np.deg2rad(output['azimuth'])  # spa
    solar_zenith = np.deg2rad(output['zenith'])
    # spencer
    eot = solarposition.equation_of_time_spencer71(times.dayofyear)
    hour_angle = np.deg2rad(solarposition.hour_angle(times, lon, eot))
    decl = solarposition.declination_spencer71(times.dayofyear)
    zenith = solarposition.solar_zenith_analytical(lat_rad, hour_angle, decl)
    azimuth_1 = solarposition.solar_azimuth_analytical(lat_rad, hour_angle,
                                                       decl, zenith)
    # pvcdrom and cooper
    eot = solarposition.equation_of_time_pvcdrom(times.dayofyear)
    hour_angle = np.deg2rad(solarposition.hour_angle(times, lon, eot))
    decl = solarposition.declination_cooper69(times.dayofyear)
    zenith = solarposition.solar_zenith_analytical(lat_rad, hour_angle, decl)
    azimuth_2 = solarposition.solar_azimuth_analytical(lat_rad, hour_angle,
                                                       decl, zenith)

    idx = np.where(solar_zenith < np.pi/2)
    assert np.allclose(azimuth_1[idx], solar_azimuth.as_matrix()[idx],
                       atol=0.01)
    assert np.allclose(azimuth_2[idx], solar_azimuth.as_matrix()[idx],
                       atol=0.017)

    # test for NaN values at boundary conditions (PR #431)
    test_angles = np.radians(np.array(
                   [[   0., -180.,  -20.],
                    [   0.,    0.,   -5.],
                    [   0.,    0.,    0.],
                    [   0.,    0.,   15.],
                    [   0.,  180.,   20.],
                    [  30.,    0.,  -20.],
                    [  30.,    0.,   -5.],
                    [  30.,    0.,    0.],
                    [  30.,  180.,    5.],
                    [  30.,    0.,   10.],
                    [ -30.,    0.,  -20.],
                    [ -30.,    0.,  -15.],
                    [ -30.,    0.,    0.],
                    [ -30., -180.,    5.],
                    [ -30.,  180.,   10.]]))

    zeniths  = solarposition.solar_zenith_analytical(*test_angles.T)
    azimuths = solarposition.solar_azimuth_analytical(*test_angles.T, zenith=zeniths)

    assert not np.isnan(azimuths).any()
Exemplo n.º 14
0
def test_analytical_azimuth():
    times = pd.DatetimeIndex(start="1/1/2015 0:00", end="12/31/2015 23:00",
                             freq="H").tz_localize('Etc/GMT+8')
    lat, lon = 37.8, -122.25
    lat_rad = np.deg2rad(lat)
    output = solarposition.spa_python(times, lat, lon, 100)
    solar_azimuth = np.deg2rad(output['azimuth'])  # spa
    solar_zenith = np.deg2rad(output['zenith'])
    # spencer
    eot = solarposition.equation_of_time_spencer71(times.dayofyear)
    hour_angle = np.deg2rad(solarposition.hour_angle(times, lon, eot))
    decl = solarposition.declination_spencer71(times.dayofyear)
    zenith = solarposition.solar_zenith_analytical(lat_rad, hour_angle, decl)
    azimuth_1 = solarposition.solar_azimuth_analytical(lat_rad, hour_angle,
                                                       decl, zenith)
    # pvcdrom and cooper
    eot = solarposition.equation_of_time_pvcdrom(times.dayofyear)
    hour_angle = np.deg2rad(solarposition.hour_angle(times, lon, eot))
    decl = solarposition.declination_cooper69(times.dayofyear)
    zenith = solarposition.solar_zenith_analytical(lat_rad, hour_angle, decl)
    azimuth_2 = solarposition.solar_azimuth_analytical(lat_rad, hour_angle,
                                                       decl, zenith)

    idx = np.where(solar_zenith < np.pi/2)
    assert np.allclose(azimuth_1[idx], solar_azimuth.values[idx], atol=0.01)
    assert np.allclose(azimuth_2[idx], solar_azimuth.values[idx], atol=0.017)

    # test for NaN values at boundary conditions (PR #431)
    test_angles = np.radians(np.array(
                   [[   0., -180.,  -20.],
                    [   0.,    0.,   -5.],
                    [   0.,    0.,    0.],
                    [   0.,    0.,   15.],
                    [   0.,  180.,   20.],
                    [  30.,    0.,  -20.],
                    [  30.,    0.,   -5.],
                    [  30.,    0.,    0.],
                    [  30.,  180.,    5.],
                    [  30.,    0.,   10.],
                    [ -30.,    0.,  -20.],
                    [ -30.,    0.,  -15.],
                    [ -30.,    0.,    0.],
                    [ -30., -180.,    5.],
                    [ -30.,  180.,   10.]]))

    zeniths = solarposition.solar_zenith_analytical(*test_angles.T)
    azimuths = solarposition.solar_azimuth_analytical(*test_angles.T,
                                                      zenith=zeniths)

    assert not np.isnan(azimuths).any()
Exemplo n.º 15
0
def test_spa_python_numpy_physical():
    times = pd.date_range(datetime.datetime(2003, 10, 17, 12, 30, 30),
                          periods=1,
                          freq='D',
                          tz=golden_mst.tz)
    ephem_data = solarposition.spa_python(times,
                                          golden_mst.latitude,
                                          golden_mst.longitude,
                                          pressure=82000,
                                          temperature=11,
                                          delta_t=67,
                                          atmos_refract=0.5667,
                                          how='numpy')
    this_expected = expected.copy()
    this_expected.index = times
    assert_frame_equal(this_expected, ephem_data[expected.columns])
Exemplo n.º 16
0
def test_spa_python_numba_physical_dst():
    try:
        import numba
    except ImportError:
        raise SkipTest
    vers = numba.__version__.split('.')
    if int(vers[0] + vers[1]) < 17:
        raise SkipTest

    times = pd.date_range(datetime.datetime(2003,10,17,13,30,30), periods=1, freq='D')
    ephem_data = solarposition.spa_python(times, golden, pressure=82000, 
                                          temperature=11, delta_t=67, 
                                          atmos_refract=0.5667,
                                          how='numba', numthreads=1).ix[0]
    assert_almost_equals(50.111622, ephem_data['apparent_zenith'], 6)
    assert_almost_equals(194.340241, ephem_data['azimuth'], 6)
    assert_almost_equals(39.888378, ephem_data['apparent_elevation'], 6)
Exemplo n.º 17
0
    def __init__(self,
                 location: List[float],
                 horizon=None,
                 start_year: int = 2006,
                 end_year: int = 2007,
                 timestep: int = 600):
        """Initialize.

        Args:
            location (List[float,float]): Location on the ground
            horizon (np.ndarray): Horizon at location. Defaults to None.
            start_year (int): Inital year of the calculation.
                Defaults to '2006'.
            end_year (int): End year of the calculation.
                Defaults to '2007'.
            timestep (int): Timestep of the simulation. Defaults to 6e2.

        """
        self.location = location
        self.timestep = timestep
        self.dates = pd.date_range(str(start_year),
                                   str(end_year),
                                   freq="{}s".format(int(timestep)))
        if not (isinstance(horizon, interp1d)):
            self.horizon = interp1d(horizon[:, 0],
                                    horizon[:, 1],
                                    bounds_error=False)
        else:
            self.horizon = horizon
        suns = spa_python(self.dates, *self.location)
        suns.azimuth = suns.azimuth.map(lambda azimuth: azimuth +
                                        (azimuth < 0) * 360 - 180)
        up = suns.elevation > self.horizon(suns.azimuth)
        suns.insert(column="is_up", value=up, loc=0)
        self.start_year = int(start_year)
        self.end_year = (end_year)
        self.data = suns
        self._timestamp_begin = self.dates[0].timestamp()
        self._timestamp_end = self.dates[-1].timestamp()
        self._len_timeframe = self._timestamp_end - self._timestamp_begin
        self._columns = list(self.data.columns)
        self._index = self.data.index.values.astype(np.int64) * 1e-9
        self._values = self.data.values
def test_spa_python_numba_physical_dst():
    try:
        import numba
    except ImportError:
        raise SkipTest
    vers = numba.__version__.split('.')
    if int(vers[0] + vers[1]) < 17:
        raise SkipTest

    times = pd.date_range(datetime.datetime(2003,10,17,13,30,30),
                          periods=1, freq='D', tz=golden.tz)
    ephem_data = solarposition.spa_python(times, golden.latitude,
                                          golden.longitude, pressure=82000,
                                          temperature=11, delta_t=67,
                                          atmos_refract=0.5667,
                                          how='numba', numthreads=1)
    this_expected = expected.copy()
    this_expected.index = times
    assert_frame_equal(this_expected, ephem_data[expected.columns])
Exemplo n.º 19
0
def test_analytical_zenith():
    times = pd.date_range(start="1/1/2015 0:00", end="12/31/2015 23:00",
                          freq="H").tz_localize('Etc/GMT+8')
    lat, lon = 37.8, -122.25
    lat_rad = np.deg2rad(lat)
    output = solarposition.spa_python(times, lat, lon, 100)
    solar_zenith = np.deg2rad(output['zenith'])  # spa
    # spencer
    eot = solarposition.equation_of_time_spencer71(times.dayofyear)
    hour_angle = np.deg2rad(solarposition.hour_angle(times, lon, eot))
    decl = solarposition.declination_spencer71(times.dayofyear)
    zenith_1 = solarposition.solar_zenith_analytical(lat_rad, hour_angle, decl)
    # pvcdrom and cooper
    eot = solarposition.equation_of_time_pvcdrom(times.dayofyear)
    hour_angle = np.deg2rad(solarposition.hour_angle(times, lon, eot))
    decl = solarposition.declination_cooper69(times.dayofyear)
    zenith_2 = solarposition.solar_zenith_analytical(lat_rad, hour_angle, decl)
    assert np.allclose(zenith_1, solar_zenith, atol=0.015)
    assert np.allclose(zenith_2, solar_zenith, atol=0.025)
Exemplo n.º 20
0
    def calculate(self):
        date = str(self.dateEdit.date().year()) + '-' + str(
            self.dateEdit.date().month()) + '-' + str(
                self.dateEdit.date().day())
        time = str(self.timeEdit.time().hour()) + ':' + str(
            self.timeEdit.time().minute()) + ':' + str(
                self.timeEdit.time().second()) + '.' + str(
                    self.timeEdit.time().msec())

        self.now = pd.Timestamp(date + ' ' + time)

        self.lat = self.spinBox_latitude.value()
        self.lon = self.spinBox_longitude.value()

        self.solpos = solarposition.spa_python(self.now, self.lat, self.lon)

        self.lcdNumber_azimuth.display(self.solpos.azimuth.array[0])
        self.lcdNumber_elevation.display(self.solpos.elevation.array[0])

        self.calculate_sunRise_sunSet_sunNoon()
Exemplo n.º 21
0
def test_analytical_zenith():
    times = pd.date_range(start="1/1/2015 0:00",
                          end="12/31/2015 23:00",
                          freq="H").tz_localize('Etc/GMT+8')
    lat, lon = 37.8, -122.25
    lat_rad = np.deg2rad(lat)
    output = solarposition.spa_python(times, lat, lon, 100)
    solar_zenith = np.deg2rad(output['zenith'])  # spa
    # spencer
    eot = solarposition.equation_of_time_spencer71(times.dayofyear)
    hour_angle = np.deg2rad(solarposition.hour_angle(times, lon, eot))
    decl = solarposition.declination_spencer71(times.dayofyear)
    zenith_1 = solarposition.solar_zenith_analytical(lat_rad, hour_angle, decl)
    # pvcdrom and cooper
    eot = solarposition.equation_of_time_pvcdrom(times.dayofyear)
    hour_angle = np.deg2rad(solarposition.hour_angle(times, lon, eot))
    decl = solarposition.declination_cooper69(times.dayofyear)
    zenith_2 = solarposition.solar_zenith_analytical(lat_rad, hour_angle, decl)
    assert np.allclose(zenith_1, solar_zenith, atol=0.015)
    assert np.allclose(zenith_2, solar_zenith, atol=0.025)
Exemplo n.º 22
0
 def time_spa_python(self, ndays):
     solarposition.spa_python(self.times_localized, self.lat, self.lon)
Exemplo n.º 23
0
def test_spa_python_localization():    
    assert_frame_equal(solarposition.spa_python(times, tus), 
                       solarposition.spa_python(times_localized, tus))