def pvlib(self, dates, lat, lon, method="ineichen"): from pvlib import clearsky, solarposition from pvlib.location import Location from pandas import DatetimeIndex times = DatetimeIndex(dates) loc = Location(lat, lon) clear = loc.get_clearsky(times, model=method) return clear['ghi'], clear['dhi'], clear['dni']
def test_get_clearsky_haurwitz(): tus = Location(32.2, -111, 'US/Arizona', 700, 'Tucson') times = pd.DatetimeIndex(start='20160101T0600-0700', end='20160101T1800-0700', freq='3H') clearsky = tus.get_clearsky(times, model='haurwitz') expected = pd.DataFrame(data=np.array([[0.], [242.30085588], [559.38247117], [384.6873791], [0.]]), columns=['ghi'], index=times) assert_frame_equal(expected, clearsky)
def test_get_clearsky_haurwitz(times): tus = Location(32.2, -111, 'US/Arizona', 700, 'Tucson') clearsky = tus.get_clearsky(times, model='haurwitz') expected = pd.DataFrame(data=np.array( [[ 0. ], [ 242.30085588], [ 559.38247117], [ 384.6873791 ], [ 0. ]]), columns=['ghi'], index=times) assert_frame_equal(expected, clearsky)
def test_Location___repr__(): tus = Location(32.2, -111, 'US/Arizona', 700, 'Tucson') expected = '\n'.join([ 'Location: ', ' name: Tucson', ' latitude: 32.2', ' longitude: -111', ' altitude: 700', ' tz: US/Arizona' ]) assert tus.__repr__() == expected
def test_get_clearsky(mocker, times): tus = Location(32.2, -111, 'US/Arizona', 700, 'Tucson') m = mocker.spy(pvlib.clearsky, 'ineichen') out = tus.get_clearsky(times) assert m.call_count == 1 assert_index_equal(out.index, times) # check that values are 0 before sunrise and after sunset assert out.iloc[0, :].sum().sum() == 0 assert out.iloc[-1:, :].sum().sum() == 0 # check that values are > 0 during the day assert (out.iloc[1:-1, :] > 0).all().all() assert (out.columns.values == ['ghi', 'dni', 'dhi']).all()
def test_SingleAxisTracker_localize_location(): system = tracking.SingleAxisTracker(max_angle=45, gcr=.25, module='blah', inverter='blarg') location = Location(latitude=32, longitude=-111) localized_system = system.localize(location=location) assert localized_system.module == 'blah' assert localized_system.inverter == 'blarg' assert localized_system.latitude == 32 assert localized_system.longitude == -111
def test_sun_rise_set_transit_spa(expected_rise_set_spa, golden): # solution from NREL SAP web calculator south = Location(-35.0, 0.0, tz='UTC') times = pd.DatetimeIndex( [datetime.datetime(1996, 7, 5, 0), datetime.datetime(2004, 12, 4, 0)]).tz_localize('UTC') sunrise = pd.DatetimeIndex([ datetime.datetime(1996, 7, 5, 7, 8, 15), datetime.datetime(2004, 12, 4, 4, 38, 57) ]).tz_localize('UTC').tolist() sunset = pd.DatetimeIndex([ datetime.datetime(1996, 7, 5, 17, 1, 4), datetime.datetime(2004, 12, 4, 19, 2, 3) ]).tz_localize('UTC').tolist() transit = pd.DatetimeIndex([ datetime.datetime(1996, 7, 5, 12, 4, 36), datetime.datetime(2004, 12, 4, 11, 50, 22) ]).tz_localize('UTC').tolist() frame = pd.DataFrame( { 'sunrise': sunrise, 'sunset': sunset, 'transit': transit }, index=times) result = solarposition.sun_rise_set_transit_spa(times, south.latitude, south.longitude, delta_t=65.0) result_rounded = pd.DataFrame(index=result.index) # need to iterate because to_datetime does not accept 2D data # the rounding fails on pandas < 0.17 for col, data in result.iteritems(): result_rounded[col] = data.dt.round('1s') assert_frame_equal(frame, result_rounded) # test for Golden, CO compare to NREL SPA result = solarposition.sun_rise_set_transit_spa( expected_rise_set_spa.index, golden.latitude, golden.longitude, delta_t=65.0) # round to nearest minute result_rounded = pd.DataFrame(index=result.index) # need to iterate because to_datetime does not accept 2D data for col, data in result.iteritems(): result_rounded[col] = data.dt.round('s').tz_convert('MST') assert_frame_equal(expected_rise_set_spa, result_rounded)
def __init__(self,muni_obj): self.coordinates = muni_obj.coor self.tobis_magic_constant = 0.449568 self.instp = muni_obj.instp self.hours = muni_obj.hours loc_temp = {} for nr in muni_obj.muninr: #import location object for each minicpilaty loc_temp[nr] = Location(muni_obj.coor.loc[nr][0], muni_obj.coor.loc[nr][1], timezone = "Europe/Copenhagen", altitude = 10, name = "Denmark") self.location = loc_temp
def test_get_clearsky_simplified_solis_pressure(times): tus = Location(32.2, -111, 'US/Arizona', 700, 'Tucson') clearsky = tus.get_clearsky(times, model='simplified_solis', pressure=95000) expected = pd.DataFrame(data=np.array( [[0., 0., 0.], [70.20556637, 635.53091983, 236.17716435], [102.08954904, 850.49502085, 576.28465815], [86.46561686, 753.70744638, 384.90537859], [0., 0., 0.]]), columns=['dhi', 'dni', 'ghi'], index=times) expected = expected[['ghi', 'dni', 'dhi']] assert_frame_equal(expected, clearsky, check_less_precise=2)
def test_get_clearsky(): tus = Location(32.2, -111, 'US/Arizona', 700, 'Tucson') times = pd.DatetimeIndex(start='20160101T0600-0700', end='20160101T1800-0700', freq='3H') clearsky = tus.get_clearsky(times) expected = pd.DataFrame(data=np.array( [[0., 0., 0.], [258.60422702, 761.57329257, 50.1235982], [611.96347869, 956.95353414, 70.8232806], [415.10904044, 878.52649603, 59.07820922], [0., 0., 0.]]), columns=['ghi', 'dni', 'dhi'], index=times) assert_frame_equal(expected, clearsky, check_less_precise=2)
def test_get_clearsky_simplified_solis(times): tus = Location(32.2, -111, 'US/Arizona', 700, 'Tucson') clearsky = tus.get_clearsky(times, model='simplified_solis') expected = pd.DataFrame(data=np. array([[ 0. , 0. , 0. ], [ 70.00146271, 638.01145669, 236.71136245], [ 101.69729217, 852.51950946, 577.1117803 ], [ 86.1679965 , 755.98048017, 385.59586091], [ 0. , 0. , 0. ]]), columns=['dhi', 'dni', 'ghi'], index=times) expected = expected[['ghi', 'dni', 'dhi']] assert_frame_equal(expected, clearsky, check_less_precise=2)
def test_get_clearsky_simplified_solis_dni_extra(times): tus = Location(32.2, -111, 'US/Arizona', 700, 'Tucson') clearsky = tus.get_clearsky(times, model='simplified_solis', dni_extra=1370) expected = pd.DataFrame(data=np.array( [[0., 0., 0.], [67.82281485, 618.15469596, 229.34422063], [98.53217848, 825.98663808, 559.15039353], [83.48619937, 732.45218243, 373.59500313], [0., 0., 0.]]), columns=['dhi', 'dni', 'ghi'], index=times) expected = expected[['ghi', 'dni', 'dhi']] assert_frame_equal(expected, clearsky)
def setup_year_ghi(self): self.count = 0 times = pd.date_range( start='%d-01-01' % (self.start_year), end='%d-01-01' % (self.start_year + 1), freq='15Min', tz='utc' ) location = Location( self.opts.lat, self.opts.lon, altitude=self.opts.alt ) self.cs = location.get_clearsky(times)
def setup_pvlib_location_object(): """ Sets up pvlib Location object for HTW. Returns ------- :pvlib:`Location` """ return Location(latitude=HTW_LAT, longitude=HTW_LON, tz='Europe/Berlin', altitude=80, name='HTW Berlin')
def test_get_clearsky_simplified_solis_aod_pw(times): tus = Location(32.2, -111, 'US/Arizona', 700, 'Tucson') clearsky = tus.get_clearsky(times, model='simplified_solis', aod700=0.25, precipitable_water=2.) expected = pd.DataFrame(data=np.array( [[0., 0., 0.], [85.77821205, 374.58084365, 179.48483117], [143.52743364, 625.91745295, 490.06254157], [114.63275842, 506.52275195, 312.24711495], [0., 0., 0.]]), columns=['dhi', 'dni', 'ghi'], index=times) expected = expected[['ghi', 'dni', 'dhi']] assert_frame_equal(expected, clearsky, check_less_precise=2)
def compute_irradiance(latitude: float, longitude: float, dt: datetime, cloud_coverage: float) -> float: """Compute the irradiance received on a location at a specific time. This uses pvlib to 1) compute clear-sky irradiance as Global Horizontal Irradiance (GHI), which includes both Direct Normal Irradiance (DNI) and Diffuse Horizontal Irradiance (DHI). 2) adjust the GHI for cloud coverage """ site = Location(latitude, longitude, tz=dt.tzinfo) solpos = site.get_solarposition(pd.DatetimeIndex([dt])) ghi_clear = site.get_clearsky(pd.DatetimeIndex([dt]), solar_position=solpos).loc[dt]["ghi"] return ghi_clear_to_ghi(ghi_clear, cloud_coverage)
def test_haurwitz(): 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.], [82.85934048], [699.74514735], [1016.50198354], [838.32103769], [271.90853863], [0.], [0.]]), columns=['ghi'], index=times_localized) out = clearsky.haurwitz(ephem_data['zenith']) assert_frame_equal(expected, out)
def test_ModelChain___repr__(): system = PVSystem() location = Location(32.2, -111, altitude=700) strategy = 'south_at_latitude_tilt' mc = ModelChain(system, location, orientation_strategy=strategy) # the || accounts for the coercion of 'None' to None assert mc.__repr__() == ( 'ModelChain for: PVSystem with tilt:32.2 and ' + 'azimuth: 180 with Module: None and Inverter: None ' + 'orientation_startegy: south_at_latitude_tilt clearsky_model: ' + 'ineichentransposition_model: haydavies solar_position_method: ' + 'nrel_numpyairmass_model: kastenyoung1989')
def _configure(self, configs: Configurations, **kwargs) -> None: super()._configure(configs, **kwargs) if configs.has_section('Location'): from pvlib.location import Location self.location = Location(configs.getfloat('Location', 'latitude'), configs.getfloat('Location', 'longitude'), tz=configs.get('Location', 'timezone', fallback='UTC'), altitude=configs.getfloat('Location', 'altitude', fallback=0), name=self.name, **kwargs)
def test_get_clearsky_ineichen_supply_linke(mocker): tus = Location(32.2, -111, 'US/Arizona', 700) times = pd.date_range(start='2014-06-24-0700', end='2014-06-25-0700', freq='3h') mocker.spy(pvlib.clearsky, 'ineichen') out = tus.get_clearsky(times, linke_turbidity=3) # we only care that the LT is passed in this test pvlib.clearsky.ineichen.assert_called_once_with(ANY, ANY, 3, ANY, ANY) assert_index_equal(out.index, times) # check that values are 0 before sunrise and after sunset assert out.iloc[0:2, :].sum().sum() == 0 assert out.iloc[-2:, :].sum().sum() == 0 # check that values are > 0 during the day assert (out.iloc[2:-2, :] > 0).all().all() assert (out.columns.values == ['ghi', 'dni', 'dhi']).all()
def simulate(self): place = Location(self._latitude, self._longtitude, 'Europe/Paris', self._height, 'Heidelberg') #tus = Location(49.4, 8.67, 'Europe/Paris', 114, 'Heidelberg') times = pd.date_range(start=self._dateStart, end=self._dateEnd, freq=self._freq, tz=place.tz) #times = pd.date_range(start='2020-03-01', end='2020-03-02', freq='5s', tz=tus.tz) cs = place.get_clearsky(times) c = cs.dni for t in range(len(times)): #print(times[t], c[t],times[t].time().second) self._time.append(times[t]) self._power.append(c[t] * self._deviceSize)
def test_get_clearsky(): tus = Location(32.2, -111, 'US/Arizona', 700, 'Tucson') times = pd.DatetimeIndex(start='20160101T0600-0700', end='20160101T1800-0700', freq='3H') clearsky = tus.get_clearsky(times) expected = pd.DataFrame(data=np.array( [(0.0, 0.0, 0.0), (262.77734276159333, 791.1972825869296, 46.18714900637892), (616.764693938387, 974.9610353623959, 65.44157429054201), (419.6512657626518, 901.6234995035793, 54.26016437839348), (0.0, 0.0, 0.0)], dtype=[('ghi', '<f8'), ('dni', '<f8'), ('dhi', '<f8')]), index=times) assert_frame_equal(expected, clearsky, check_less_precise=2)
def load_katherine_5s(): log.info("Reading Katherine 5-second irradiance file...") loc = Location(-14.4747, 132.3050, altitude=108.0, tz="Australia/Darwin", name='Katherine') df = pd.concat([ pd.read_csv(_find_prefixed_dat_files("KTR"), index_col='Time', parse_dates=True) ])[['GHI', 'DNI']].asfreq('5S') df.index = df.index.tz_localize(loc.tz) df.columns = ['ghi', 'dni'] return IrradianceDataset(df, location=loc)
def load_darwin_5s(): log.info("Reading Darwin 5-second irradiance file...") loc = Location(-12.4417, 130.9215, altitude=10.0, tz="Australia/Darwin", name='Darwin') df = pd.concat([ pd.read_csv(_find_prefixed_dat_files("DRW"), index_col='Time', parse_dates=True) ])[['GHI', 'DNI']].asfreq('5S') df.index = df.index.tz_localize(loc.tz) df.columns = ['ghi'] return IrradianceDataset(df, location=loc)
def load_alice_5s(): log.info("Reading Alice Springs 5-second irradiance file...") loc = Location(-23.7624, 133.8754, altitude=580.0, tz="Australia/Darwin", name='Alice Springs') df = pd.concat([ pd.read_csv(_find_prefixed_dat_files("ASP"), index_col='Time', parse_dates=True) ])[['GHI', 'DNI']].asfreq('5S') df.index = df.index.tz_localize(loc.tz) df.columns = ['ghi', 'dni'] return IrradianceDataset(df, location=loc)
def test_get_clearsky_simplified_solis_apparent_elevation(times): tus = Location(32.2, -111, 'US/Arizona', 700, 'Tucson') solar_position = {'apparent_elevation': pd.Series(80, index=times), 'apparent_zenith': pd.Series(10, index=times)} clearsky = tus.get_clearsky(times, model='simplified_solis', solar_position=solar_position) expected = pd.DataFrame(data=np. array([[ 131.3124497 , 1001.14754036, 1108.14147919], [ 131.3124497 , 1001.14754036, 1108.14147919], [ 131.3124497 , 1001.14754036, 1108.14147919], [ 131.3124497 , 1001.14754036, 1108.14147919], [ 131.3124497 , 1001.14754036, 1108.14147919]]), columns=['dhi', 'dni', 'ghi'], index=times) expected = expected[['ghi', 'dni', 'dhi']] assert_frame_equal(expected, clearsky, check_less_precise=2)
def test_get_clearsky_ineichen_supply_linke(): 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) expected = pd.DataFrame( np.array([[0., 0., 0.], [0., 0., 0.], [79.73090244, 316.16436502, 40.45759009], [703.43653498, 876.41452667, 95.15798252], [1042.37962396, 939.86391062, 118.44687715], [851.32411813, 909.11186737, 105.36662462], [257.18266827, 646.16644264, 62.02777094], [0., 0., 0.], [0., 0., 0.]]), columns=['ghi', 'dni', 'dhi'], index=times_localized) out = tus.get_clearsky(times_localized, linke_turbidity=3) assert_frame_equal(expected, out, check_less_precise=2)
def test_deprecated_clearsky_07(): # explicit system creation call because fail_on_pvlib_version # does not support decorators. system = PVSystem(module_parameters={'pdc0': 1, 'gamma_pdc': -0.003}) location = Location(32.2, -110.9) mc = ModelChain(system, location, dc_model='pvwatts', ac_model='pvwatts', aoi_model='no_loss', spectral_model='no_loss') times = pd.date_range(start='20160101 1200-0700', end='20160101 1800-0700', freq='6H') with pytest.warns(pvlibDeprecationWarning): mc.prepare_inputs(times=times)
def mc_setup(): # limit network usage try: modules = sam_data['sandiamod'] except KeyError: retrieve_sam_network() modules = sam_data['sandiamod'] module = modules.Canadian_Solar_CS5P_220M___2009_.copy() inverters = sam_data['cecinverter'] inverter = inverters['ABB__MICRO_0_25_I_OUTD_US_208_208V__CEC_2014_'].copy() system = PVSystem(module_parameters=module, inverter_parameters=inverter) location = Location(32.2, -111, altitude=700) return system, location
def set_location(self, tz, latitude, longitude): ''' Sets the location for the query. Parameters ---------- tz: tzinfo Timezone of the query latitude: float Latitude of the query longitude: float Longitude of the query Notes ----- Assigns ``self.location``. ''' self.location = Location(latitude, longitude, tz=tz)