def test_simplified_solis_series_elevation(): expected = pd.DataFrame(np.array([[959.335463, 1064.653145, 129.125602]]), columns=['dni', 'ghi', 'dhi']) expected = expected[['ghi', 'dni', 'dhi']] out = clearsky.simplified_solis(pd.Series(80)) assert_frame_equal(expected, out)
def test_simplified_solis_dni_extra(): expected = pd.DataFrame(np.array([[963.555414, 1069.33637, 129.693603]]), columns=['dni', 'ghi', 'dhi']) expected = expected[['ghi', 'dni', 'dhi']] out = clearsky.simplified_solis(80, dni_extra=pd.Series(1370)) assert_frame_equal(expected, out)
def test_simplified_solis_series_elevation(): expected = pd.DataFrame(np.array([[959.335463, 1064.653145, 129.125602]]), columns=['dni', 'ghi', 'dhi']) expected = expected[['ghi', 'dni', 'dhi']] out = clearsky.simplified_solis(pd.Series(80)) assert_frame_equal(expected, out)
def solar_input_calculator(latitude=55.571831046, longitude=12.822830042, tz='Europe/Vatican', name='Oresund', start_date='2014-04-01', end_date='2014-10-01', freq='15Min', normalized=True): altitude = 0 times = pd.date_range(start=start_date, end=end_date, freq=freq, tz=tz) solpos = pvlib.solarposition.get_solarposition(times, latitude, longitude) apparent_elevation = solpos['apparent_elevation'] aod700 = 0.1 precipitable_water = 1 pressure = pvlib.atmosphere.alt2pres(altitude) dni_extra = pvlib.irradiance.get_extra_radiation(times) # an input is a Series, so solis is a DataFrame solis = clearsky.simplified_solis(apparent_elevation, aod700, precipitable_water, pressure, dni_extra) if normalized is True: return solis.dhi.values / np.max(solis.dhi.values) else: return solis.dhi.values
def test_simplified_solis_dni_extra(): expected = pd.DataFrame(np.array([[963.555414, 1069.33637, 129.693603]]), columns=['dni', 'ghi', 'dhi']) expected = expected[['ghi', 'dni', 'dhi']] out = clearsky.simplified_solis(80, dni_extra=pd.Series(1370)) assert_frame_equal(expected, out)
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
def test_simplified_solis_scalar_elevation(): expected = OrderedDict() expected['ghi'] = 1064.653145 expected['dni'] = 959.335463 expected['dhi'] = 129.125602 out = clearsky.simplified_solis(80) for k, v in expected.items(): assert_allclose(expected[k], out[k])
def test_simplified_solis_scalar_elevation(): expected = OrderedDict() expected['ghi'] = 1064.653145 expected['dni'] = 959.335463 expected['dhi'] = 129.125602 out = clearsky.simplified_solis(80) for k, v in expected.items(): assert_allclose(expected[k], out[k])
def test_simplified_solis_scalar_neg_elevation(): expected = OrderedDict() expected['ghi'] = 0 expected['dni'] = 0 expected['dhi'] = 0 out = clearsky.simplified_solis(-10) for k, v in expected.items(): assert_allclose(expected[k], out[k])
def test_simplified_solis_scalar_neg_elevation(): expected = OrderedDict() expected['ghi'] = 0 expected['dni'] = 0 expected['dhi'] = 0 out = clearsky.simplified_solis(-10) for k, v in expected.items(): assert_allclose(expected[k], out[k])
def test_simplified_solis_small_scalar_pw(): expected = OrderedDict() expected['ghi'] = 1107.84678941 expected['dni'] = 1001.15353307 expected['dhi'] = 128.58887606 out = clearsky.simplified_solis(80, precipitable_water=0.1) for k, v in expected.items(): assert_allclose(expected[k], out[k])
def test_simplified_solis_small_scalar_pw(): expected = OrderedDict() expected['ghi'] = 1107.84678941 expected['dni'] = 1001.15353307 expected['dhi'] = 128.58887606 out = clearsky.simplified_solis(80, precipitable_water=0.1) for k, v in expected.items(): assert_allclose(expected[k], out[k])
def test_simplified_solis_pressure(): expected = pd.DataFrame(np. array([[ 964.26930718, 1067.96543669, 127.22841797], [ 961.88811874, 1066.36847963, 128.1402539 ], [ 959.58112234, 1064.81837558, 129.0304193 ]]), columns=['dni', 'ghi', 'dhi']) expected = expected[['ghi', 'dni', 'dhi']] out = clearsky.simplified_solis( 80, pressure=pd.Series([95000, 98000, 101000])) assert_frame_equal(expected, out)
def test_simplified_solis_pressure(): expected = pd.DataFrame(np. array([[ 964.26930718, 1067.96543669, 127.22841797], [ 961.88811874, 1066.36847963, 128.1402539 ], [ 959.58112234, 1064.81837558, 129.0304193 ]]), columns=['dni', 'ghi', 'dhi']) expected = expected[['ghi', 'dni', 'dhi']] out = clearsky.simplified_solis( 80, pressure=pd.Series([95000, 98000, 101000])) assert_frame_equal(expected, out)
def test_simplified_solis_aod700(): expected = pd.DataFrame(np. array([[ 1056.61710493, 1105.7229086 , 64.41747323], [ 1007.50558875, 1085.74139063, 102.96233698], [ 959.3354628 , 1064.65314509, 129.12560167], [ 342.45810926, 638.63409683, 77.71786575], [ 55.24140911, 7.5413313 , 0. ]]), columns=['dni', 'ghi', 'dhi']) expected = expected[['ghi', 'dni', 'dhi']] aod700 = pd.Series([0.0, 0.05, 0.1, 1, 10]) out = clearsky.simplified_solis(80, aod700=aod700) assert_frame_equal(expected, out)
def test_simplified_solis_precipitable_water(): expected = pd.DataFrame(np. array([[ 1001.15353307, 1107.84678941, 128.58887606], [ 1001.15353307, 1107.84678941, 128.58887606], [ 983.51027357, 1089.62306672, 129.08755996], [ 959.3354628 , 1064.65314509, 129.12560167], [ 872.02335029, 974.18046717, 125.63581346]]), columns=['dni', 'ghi', 'dhi']) expected = expected[['ghi', 'dni', 'dhi']] out = clearsky.simplified_solis( 80, precipitable_water=pd.Series([0.0, 0.2, 0.5, 1.0, 5.0])) assert_frame_equal(expected, out)
def test_simplified_solis_precipitable_water(): expected = pd.DataFrame(np. array([[ 1001.15353307, 1107.84678941, 128.58887606], [ 1001.15353307, 1107.84678941, 128.58887606], [ 983.51027357, 1089.62306672, 129.08755996], [ 959.3354628 , 1064.65314509, 129.12560167], [ 872.02335029, 974.18046717, 125.63581346]]), columns=['dni', 'ghi', 'dhi']) expected = expected[['ghi', 'dni', 'dhi']] out = clearsky.simplified_solis( 80, precipitable_water=pd.Series([0.0, 0.2, 0.5, 1.0, 5.0])) assert_frame_equal(expected, out)
def test_simplified_solis_aod700(): expected = pd.DataFrame(np. array([[ 1056.61710493, 1105.7229086 , 64.41747323], [ 1007.50558875, 1085.74139063, 102.96233698], [ 959.3354628 , 1064.65314509, 129.12560167], [ 342.45810926, 638.63409683, 77.71786575], [ 55.24140911, 7.5413313 , 0. ]]), columns=['dni', 'ghi', 'dhi']) expected = expected[['ghi', 'dni', 'dhi']] aod700 = pd.Series([0.0, 0.05, 0.1, 1, 10]) out = clearsky.simplified_solis(80, aod700=aod700) assert_frame_equal(expected, out)
def setup(self, ndays): self.times = pd.date_range(start='20180601', freq='1min', periods=1440*ndays) self.lat = 35.1 self.lon = -106.6 self.solar_position = solarposition.get_solarposition( self.times, self.lat, self.lon) clearsky_df = clearsky.simplified_solis( self.solar_position['apparent_elevation']) self.clearsky = clearsky_df['ghi'] measured_dni = clearsky_df['dni'].where( (self.times.hour % 2).astype(bool), 0) cos_zen = np.cos(np.deg2rad(self.solar_position['apparent_zenith'])) self.measured = measured_dni * cos_zen + clearsky_df['dhi'] self.measured *= 0.98 self.window_length = 10
def test_simplified_solis_series_elevation(): expected = pd.DataFrame( np.array([[ 0. , 0. , 0. ], [ 0. , 0. , 0. ], [ 377.80060035, 79.91931339, 42.77453223], [ 869.47538184, 706.37903999, 110.05635962], [ 958.89448856, 1062.44821373, 129.02349236], [ 913.3209839 , 860.48978599, 118.94598678], [ 634.01066762, 256.00505836, 72.18396705], [ 0. , 0. , 0. ], [ 0. , 0. , 0. ]]), columns=['dni', 'ghi', 'dhi'], index=times_localized) expected = expected[['dhi', 'dni', 'ghi']] out = clearsky.simplified_solis(ephem_data['apparent_elevation']) assert_frame_equal(expected, out)
def test_simplified_solis_series_elevation(): 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) expected = pd.DataFrame( np.array([[0., 0., 0.], [0., 0., 0.], [377.80060035, 79.91931339, 42.77453223], [869.47538184, 706.37903999, 110.05635962], [958.89448856, 1062.44821373, 129.02349236], [913.3209839, 860.48978599, 118.94598678], [634.01066762, 256.00505836, 72.18396705], [0., 0., 0.], [0., 0., 0.]]), columns=['dni', 'ghi', 'dhi'], index=times_localized) expected = expected[['dhi', 'dni', 'ghi']] out = clearsky.simplified_solis(ephem_data['apparent_elevation']) assert_frame_equal(expected, out)
def test_simplified_solis_return_arrays(): expected = OrderedDict() expected['ghi'] = np.array([[ 1148.40081325, 913.42330823], [ 965.48550828, 760.04527609]]) expected['dni'] = np.array([[ 1099.25706525, 656.24601381], [ 915.31689149, 530.31697378]]) expected['dhi'] = np.array([[ 64.1063074 , 254.6186615 ], [ 62.75642216, 232.21931597]]) aod700 = np.linspace(0, 0.5, 2) precipitable_water = np.linspace(0, 10, 2) aod700, precipitable_water = np.meshgrid(aod700, precipitable_water) out = clearsky.simplified_solis(80, aod700, precipitable_water) for k, v in expected.items(): assert_allclose(expected[k], out[k])
def test_simplified_solis_return_arrays(): expected = OrderedDict() expected['ghi'] = np.array([[ 1148.40081325, 913.42330823], [ 965.48550828, 760.04527609]]) expected['dni'] = np.array([[ 1099.25706525, 656.24601381], [ 915.31689149, 530.31697378]]) expected['dhi'] = np.array([[ 64.1063074 , 254.6186615 ], [ 62.75642216, 232.21931597]]) aod700 = np.linspace(0, 0.5, 2) precipitable_water = np.linspace(0, 10, 2) aod700, precipitable_water = np.meshgrid(aod700, precipitable_water) out = clearsky.simplified_solis(80, aod700, precipitable_water) for k, v in expected.items(): assert_allclose(expected[k], out[k])
def test_simplified_solis_series_elevation(): 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) expected = pd.DataFrame( np.array([[ 0. , 0. , 0. ], [ 0. , 0. , 0. ], [ 377.80060035, 79.91931339, 42.77453223], [ 869.47538184, 706.37903999, 110.05635962], [ 958.89448856, 1062.44821373, 129.02349236], [ 913.3209839 , 860.48978599, 118.94598678], [ 634.01066762, 256.00505836, 72.18396705], [ 0. , 0. , 0. ], [ 0. , 0. , 0. ]]), columns=['dni', 'ghi', 'dhi'], index=times_localized) expected = expected[['dhi', 'dni', 'ghi']] out = clearsky.simplified_solis(ephem_data['apparent_elevation']) assert_frame_equal(expected, out)
def test_simplified_solis_nans_series(): # construct input arrays that each have 1 nan offset from each other, # the last point is valid for all arrays length = 6 apparent_elevation = pd.Series(np.full(length, 80.)) apparent_elevation[0] = np.nan aod700 = np.full(length, 0.1) aod700[1] = np.nan precipitable_water = np.full(length, 0.5) precipitable_water[2] = np.nan pressure = np.full(length, 98000.) pressure[3] = np.nan dni_extra = np.full(length, 1370.) dni_extra[4] = np.nan 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] = 1096.022736 expected['dni'][length-1] = 990.306854 expected['dhi'][length-1] = 128.664594 expected = pd.DataFrame.from_dict(expected) out = clearsky.simplified_solis(apparent_elevation, aod700, precipitable_water, pressure, dni_extra) assert_frame_equal(expected, out)
def test_simplified_solis_nans_series(): # construct input arrays that each have 1 nan offset from each other, # the last point is valid for all arrays length = 6 apparent_elevation = pd.Series(np.full(length, 80.)) apparent_elevation[0] = np.nan aod700 = np.full(length, 0.1) aod700[1] = np.nan precipitable_water = np.full(length, 0.5) precipitable_water[2] = np.nan pressure = np.full(length, 98000.) pressure[3] = np.nan dni_extra = np.full(length, 1370.) dni_extra[4] = np.nan 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] = 1096.022736 expected['dni'][length-1] = 990.306854 expected['dhi'][length-1] = 128.664594 expected = pd.DataFrame.from_dict(expected) out = clearsky.simplified_solis(apparent_elevation, aod700, precipitable_water, pressure, dni_extra) assert_frame_equal(expected, out)
def test_simplified_solis_nans_arrays(): # construct input arrays that each have 1 nan offset from each other, # the last point is valid for all arrays length = 6 apparent_elevation = np.full(length, 80.) apparent_elevation[0] = np.nan aod700 = np.full(length, 0.1) aod700[1] = np.nan precipitable_water = np.full(length, 0.5) precipitable_water[2] = np.nan pressure = np.full(length, 98000.) pressure[3] = np.nan dni_extra = np.full(length, 1370.) dni_extra[4] = np.nan 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] = 1096.022736 expected['dni'][length-1] = 990.306854 expected['dhi'][length-1] = 128.664594 out = clearsky.simplified_solis(apparent_elevation, aod700, precipitable_water, pressure, dni_extra) for k, v in expected.items(): assert_allclose(expected[k], out[k])
def test_simplified_solis_nans_arrays(): # construct input arrays that each have 1 nan offset from each other, # the last point is valid for all arrays length = 6 apparent_elevation = np.full(length, 80.) apparent_elevation[0] = np.nan aod700 = np.full(length, 0.1) aod700[1] = np.nan precipitable_water = np.full(length, 0.5) precipitable_water[2] = np.nan pressure = np.full(length, 98000.) pressure[3] = np.nan dni_extra = np.full(length, 1370.) dni_extra[4] = np.nan 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] = 1096.022736 expected['dni'][length-1] = 990.306854 expected['dhi'][length-1] = 128.664594 out = clearsky.simplified_solis(apparent_elevation, aod700, precipitable_water, pressure, dni_extra) for k, v in expected.items(): assert_allclose(expected[k], out[k])
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 The clear sky model to use. Must be one of 'ineichen', 'haurwitz', 'simplified_solis'. solar_position : None or DataFrame DataFrame with with columns 'apparent_zenith', 'zenith', 'apparent_elevation'. dni_extra: None or numeric If None, will be calculated from times. kwargs 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.extraradiation(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) 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
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
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 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