def get_pv_feedin(filename='data/Lifuka_weather_2005.csv'): """ This function converts the FeedinWeather object built in Scrip_Merra2 into a feed-in-timeseries (PV_feedin) of a PV module with the help of PVLib's ModelChain, Location, PVSystem parameters: filename as string (including the full path of the Merra2- FeedinWeather object) out/res: PV_feedin as Pandas.Series [W/Wp] """ weather = pd.read_csv(filename) weather.rename(columns={'v_wind': 'wind_speed'}, inplace=True) weather.set_index(pd.to_datetime(weather['timestamp']), inplace=True) times = weather.index # Initialize PV Module sandia_modules = pvlib.pvsystem.retrieve_sam('SandiaMod') sapm_inverters = pvlib.pvsystem.retrieve_sam('sandiainverter') # own module parameters invertername = 'ABB__MICRO_0_25_I_OUTD_US_240_240V__CEC_2014_' yingli230 = { 'module_parameters': sandia_modules['Yingli_Solar_YL230_29b_Module__2009__E__'], 'inverter_parameters': sapm_inverters[invertername], 'surface_azimuth': 0, 'surface_tilt': 25, 'albedo': 0.2 } location = { 'latitude': -20, 'longitude': -174.375, 'tz': 'Pacific/Tongatapu', 'altitude': 9.90, 'name': 'Lifuka' } mc = ModelChain(PVSystem(**yingli230), Location(**location), orientation_strategy='south_at_latitude_tilt') mc.complete_irradiance(times=times, weather=weather) mc.run_model() nominal_module_capacity = 230 res = pd.DataFrame() res['pv'] = mc.dc.p_mp.fillna(0) / nominal_module_capacity return res
def test_complete_irradiance_clean_run(system, location): """The DataFrame should not change if all columns are passed""" mc = ModelChain(system, location) times = pd.date_range('2010-07-05 9:00:00', periods=2, freq='H') i = pd.DataFrame({'dni': [2, 3], 'dhi': [4, 6], 'ghi': [9, 5]}, index=times) mc.complete_irradiance(times, weather=i) assert_series_equal(mc.weather['dni'], pd.Series([2, 3], index=times, name='dni')) assert_series_equal(mc.weather['dhi'], pd.Series([4, 6], index=times, name='dhi')) assert_series_equal(mc.weather['ghi'], pd.Series([9, 5], index=times, name='ghi'))
def test_complete_irradiance_clean_run(system, location): """The DataFrame should not change if all columns are passed""" mc = ModelChain(system, location) times = pd.date_range('2010-07-05 9:00:00', periods=2, freq='H') i = pd.DataFrame({'dni': [2, 3], 'dhi': [4, 6], 'ghi': [9, 5]}, index=times) mc.complete_irradiance(times, weather=i) assert_series_equal(mc.weather['dni'], pd.Series([2, 3], index=times, name='dni')) assert_series_equal(mc.weather['dhi'], pd.Series([4, 6], index=times, name='dhi')) assert_series_equal(mc.weather['ghi'], pd.Series([9, 5], index=times, name='ghi'))
def test_complete_irradiance(system, location): """Check calculations""" mc = ModelChain(system, location) times = pd.date_range('2010-07-05 9:00:00', periods=2, freq='H') i = pd.DataFrame( { 'dni': [30.354455, 77.22822], 'dhi': [372.103976116, 497.087579068], 'ghi': [356.543700, 465.44400] }, index=times) mc.complete_irradiance(times, weather=i[['ghi', 'dni']]) assert_series_equal( mc.weather['dhi'], pd.Series([372.103976116, 497.087579068], index=times, name='dhi')) mc.complete_irradiance(times, weather=i[['dhi', 'dni']]) assert_series_equal( mc.weather['ghi'], pd.Series([356.543700, 465.44400], index=times, name='ghi')) mc.complete_irradiance(times, weather=i[['dhi', 'ghi']]) assert_series_equal( mc.weather['dni'], pd.Series([30.354455, 77.22822], index=times, name='dni'))
def test_complete_irradiance(system, location): """Check calculations""" mc = ModelChain(system, location) times = pd.date_range('2010-07-05 7:00:00-0700', periods=2, freq='H') i = pd.DataFrame( { 'dni': [49.756966, 62.153947], 'ghi': [372.103976116, 497.087579068], 'dhi': [356.543700, 465.44400] }, index=times) with pytest.warns(UserWarning): mc.complete_irradiance(i[['ghi', 'dni']]) assert_series_equal( mc.weather['dhi'], pd.Series([356.543700, 465.44400], index=times, name='dhi')) with pytest.warns(UserWarning): mc.complete_irradiance(i[['dhi', 'dni']]) assert_series_equal( mc.weather['ghi'], pd.Series([372.103976116, 497.087579068], index=times, name='ghi')) mc.complete_irradiance(i[['dhi', 'ghi']]) assert_series_equal( mc.weather['dni'], pd.Series([49.756966, 62.153947], index=times, name='dni'))
def test_complete_irradiance(system, location): """Check calculations""" mc = ModelChain(system, location) times = pd.date_range('2010-07-05 9:00:00', periods=2, freq='H') i = pd.DataFrame({'dni': [30.354455, 77.22822], 'dhi': [372.103976116, 497.087579068], 'ghi': [356.543700, 465.44400]}, index=times) mc.complete_irradiance(times, weather=i[['ghi', 'dni']]) assert_series_equal(mc.weather['dhi'], pd.Series([372.103976116, 497.087579068], index=times, name='dhi')) mc.complete_irradiance(times, weather=i[['dhi', 'dni']]) assert_series_equal(mc.weather['ghi'], pd.Series([356.543700, 465.44400], index=times, name='ghi')) mc.complete_irradiance(times, weather=i[['dhi', 'ghi']]) assert_series_equal(mc.weather['dni'], pd.Series([30.354455, 77.22822], index=times, name='dni'))
def test_complete_irradiance_times(system, location): mc = ModelChain(system, location) times = pd.date_range('20160101 1200-0700', periods=2, freq='6H') irradiance = pd.DataFrame({'ghi': 600., 'dhi': 150.}, index=times) with pytest.warns(pvlibDeprecationWarning): mc.complete_irradiance(irradiance, times=times)
def feedin(self, weather, power_plant_parameters, **kwargs): r""" Calculates power plant feed-in in Watt. This function uses the :pvlib:`pvlib.ModelChain <pvlib.modelchain.\ ModelChain>` to calculate the feed-in for the given weather time series and PV system. By default the AC feed-in is returned. Set `mode` parameter to 'dc' to retrieve DC feed-in. Parameters ---------- weather : :pandas:`pandas.DataFrame<dataframe>` Weather time series used to calculate feed-in. See `weather` parameter in pvlib's Modelchain :pvlib:`run_model <pvlib.\ modelchain.ModelChain.run_model>` method for more information on required variables, units, etc. power_plant_parameters : dict Dictionary with power plant specifications. Keys of the dictionary are the power plant parameter names, values of the dictionary hold the corresponding value. The dictionary must at least contain the required power plant parameters (see :attr:`~.power_plant_requires`) and may further contain optional power plant parameters (see :pvlib:`pvlib.PVSystem <pvlib.\ pvsystem.PVSystem>`). location : :obj:`tuple` or :shapely:`Point` Geo location of the PV system. Can either be provided as a tuple with first entry being the latitude and second entry being the longitude or as a :shapely:`Point`. mode : str (optional) Can be used to specify whether AC or DC feed-in is returned. By default `mode` is 'ac'. To retrieve DC feed-in set `mode` to 'dc'. `mode` also influences the peak power of the PV system. See :attr:`~.pv_system_peak_power` for more information. **kwargs : Further keyword arguments can be used to overwrite :pvlib:`pvlib.\ ModelChain <pvlib.modelchain.ModelChain>` parameters. Returns ------- :pandas:`pandas.Series<series>` Power plant feed-in time series in Watt. """ self.mode = kwargs.pop("mode", "ac").lower() # ToDo Allow usage of feedinlib weather object which makes location # parameter obsolete location = kwargs.pop("location") # ToDo Allow location provided as shapely Point location = PvlibLocation(latitude=location[0], longitude=location[1], tz=weather.index.tz) self.power_plant = self.instantiate_module(**power_plant_parameters) mc = PvlibModelChain(self.power_plant, location, **kwargs) mc.complete_irradiance(weather=weather) mc.run_model(weather=weather) if self.mode == "ac": return mc.ac elif self.mode == "dc": return mc.dc.p_mp else: raise ValueError("{} is not a valid `mode`. `mode` must " "either be 'ac' or 'dc'.".format(self.mode))