def test_add_strat_tes_calculate_losses_saved_file(self): original_storage_xx_data = pd.read_csv( self.filename_storage_xx, header=0, index_col=0 ) sts.add_strat_tes( weather=self.weather, lat=self.lat, lon=self.lon, user_inputs_pvcompare_directory=TEST_USER_INPUTS_PVCOMPARE, user_inputs_mvs_directory=TEST_USER_INPUTS_MVS_SECTOR_COUPLING, overwrite_tes_parameters=False, ) assert os.path.exists( os.path.join( TEST_USER_INPUTS_MVS_SECTOR_COUPLING, "time_series", "fixed_thermal_losses_absolute_2017_53.2_13.2_40.0.csv", ) ) assert os.path.exists( os.path.join( TEST_USER_INPUTS_MVS_SECTOR_COUPLING, "time_series", "fixed_thermal_losses_relative_2017_53.2_13.2_40.0.csv", ) ) original_storage_xx_data.to_csv(self.filename_storage_xx, na_rep="NaN")
def test_add_sector_coupling_strat_tes_file_non_existent(self, select_conv_tech): original_storage_xx_data = pd.read_csv( self.filename_storage_xx, header=0, index_col=0 ) select_conv_tech(columns="storage capacity") sts.add_strat_tes( weather=self.weather_2017, lat=self.lat, lon=self.lon, user_inputs_pvcompare_directory=TEST_USER_INPUTS_PVCOMPARE, user_inputs_mvs_directory=TEST_USER_INPUTS_MVS_SECTOR_COUPLING, overwrite_tes_parameters=False, ) # no file created filename = os.path.join( TEST_USER_INPUTS_MVS_SECTOR_COUPLING, "time_series", "fixed_thermal_losses_absolute_2018_53.2_13.2_40.0.csv", ) assert os.path.exists(filename) == False # filename in storage_TES.csv does not change df = pd.read_csv(self.filename_storage_xx, header=0, index_col=0) assert ( "fixed_thermal_losses_absolute_2017_53.2_13.2_40.0.csv" in df.loc["fixed_thermal_losses_absolute"].item() ) == True original_storage_xx_data.to_csv(self.filename_storage_xx, na_rep="NaN")
def test_add_sector_coupling_strat_tes_file_const_losses(self, select_conv_tech): energy_storage_file_path = os.path.join( TEST_USER_INPUTS_MVS_SECTOR_COUPLING, "csv_elements", "energyStorage.csv" ) energy_storage_original = pd.read_csv( energy_storage_file_path, header=0, index_col=0 ) energy_storage = energy_storage_original.copy() energy_storage.at[ "storage_filename", "storage_TES" ] = "storage_TES_const_losses.csv" energy_storage.to_csv(energy_storage_file_path, na_rep="NaN") select_conv_tech(columns="storage capacity") sts.add_strat_tes( weather=self.weather, lat=self.lat, lon=self.lon, user_inputs_pvcompare_directory=TEST_USER_INPUTS_PVCOMPARE, user_inputs_mvs_directory=TEST_USER_INPUTS_MVS_SECTOR_COUPLING, overwrite_tes_parameters=False, ) # no file created filename = os.path.join( TEST_USER_INPUTS_MVS_SECTOR_COUPLING, "time_series", "fixed_thermal_losses_absolute_2017_53.2_13.2_40.0.csv", ) assert os.path.exists(filename) == False # check efficiency df = pd.read_csv(self.filename_storage_TES, header=0, index_col=0) assert float(df.loc["efficiency"].item()) == 0.99907726890329 assert float(df.loc["fixed_thermal_losses_relative"].item()) == 0.0016 assert float(df.loc["fixed_thermal_losses_absolute"].item()) == 0.0003 energy_storage_original.to_csv(energy_storage_file_path, na_rep="NaN")
def apply_pvcompare( storeys, country=None, latitude=None, longitude=None, year=None, static_inputs_directory=None, user_inputs_pvcompare_directory=None, user_inputs_mvs_directory=None, collections_mvs_inputs_directory=None, plot=False, pv_setup=None, overwrite_grid_parameters=True, overwrite_pv_parameters=True, overwrite_heat_parameters=True, ): r""" Runs the main functionalities of pvcompare. Loads weather data for the given year and location, calculates pv feed-in time series, as well as the nominal values /installation capacities based on the building parameters. Additionally, COPs are calculated if a heat pump is added to the energy system. Parameters ---------- storeys: int Number of storeys for which the demand is calculated. country: Country of the location. Default: None. latitude: float or None Latitude of country location in `country`. Default: None. longitude: float or None Longitude of country location in `country`. Default: None. year: int Year of the simulation. Default: None. static_inputs_directory: str or None Path to pvcompare static inputs. If None, `constants.DEFAULT_STATIC_INPUTS_DIRECTORY` is used. Default: None. user_inputs_pvcompare_directory: str or None Path to user input directory. If None, `constants.DEFAULT_USER_INPUTS_PVCOMPARE_DIRECTORY` is used. Default: None. user_inputs_mvs_directory: str or None Path to input directory containing files that describe the energy system and that are an input to MVS. If None, `constants.DEFAULT_USER_INPUTS_MVS_DIRECTORY` is used. Default: None. collections_mvs_inputs_directory: str or None Path to input data collection. Used in :py:func:`~.check_inputs.overwrite_mvs_energy_production_file`, there if None, it is set to `constants.DEFAULT_COLLECTION_MVS_INPUTS_DIRECTORY`. plot: bool If True, plots of the PV feed-in time series are created in :py:func:`~.pv_feedin.create_pv_components`. Default: False. pv_setup: dict or None Specifies the PV technologies and their installation details used in the simulation. The dictionary contains columns: surface_type, technology, surface_azimuth, surface_tilt. A tilt of 0 resembles a vertical orientation. If `pv_setup` is None, it is loaded from the `user_inputs_pvcompare_directory/pv_setup.cvs`. Default: None. overwrite_grid_parameters: bool If True, the following grid parameters are inserted into the MVS input csvs automatically: electricity price, feed-in tariff, CO2 emissions, renewable share, gas price. Default: True. overwrite_pv_parameters: bool If True, the pv components in 'energyProduction.csv' are overwritten with default values from 'data/user_inputs_collection/' according to the pv plants defined in 'pv_setup'. Default: True. overwrite_heat_parameters: bool If True, existing COP time series of the heat pump will be overwritten with calculated time series of COP and existing fixed thermal losses absolute and relative will be overwritten with calculated time series of fixed thermal losses relative and absolute. Default: True. Returns ------- None Saves calculated time series to `timeseries` folder in `user_inputs_mvs_directory` and updates csv files in `csv_elements` folder. """ if static_inputs_directory == None: static_inputs_directory = constants.DEFAULT_STATIC_INPUTS_DIRECTORY if user_inputs_pvcompare_directory == None: user_inputs_pvcompare_directory = ( constants.DEFAULT_USER_INPUTS_PVCOMPARE_DIRECTORY) if user_inputs_mvs_directory == None: user_inputs_mvs_directory = constants.DEFAULT_USER_INPUTS_MVS_DIRECTORY # add location and year to project data ( latitude, longitude, country, year, ) = check_inputs.add_location_and_year_to_project_data( user_inputs_mvs_directory, static_inputs_directory, latitude, longitude, country, year, ) # add grid parameters specified by country if overwrite_grid_parameters == True: check_inputs.add_local_grid_parameters( static_inputs_directory=static_inputs_directory, user_inputs_mvs_directory=user_inputs_mvs_directory, ) # check if weather data already exists weather_file = os.path.join( static_inputs_directory, f"weatherdata_{latitude}_{longitude}_{year}.csv") if os.path.isfile(weather_file): weather = pd.read_csv( weather_file, index_col=0, ) else: # if era5 import works this line can be used weather = era5.load_era5_weatherdata(lat=latitude, lon=longitude, year=year) weather.to_csv(weather_file) # add datetimeindex weather.index = pd.to_datetime(weather.index) # check energyProduction.csv file for the correct pv technology check_inputs.overwrite_mvs_energy_production_file( pv_setup=pv_setup, user_inputs_mvs_directory=user_inputs_mvs_directory, user_inputs_pvcompare_directory=user_inputs_pvcompare_directory, collections_mvs_inputs_directory=collections_mvs_inputs_directory, overwrite_pv_parameters=overwrite_pv_parameters, ) pv_feedin.create_pv_components( lat=latitude, lon=longitude, weather=weather, storeys=storeys, pv_setup=pv_setup, plot=plot, user_inputs_pvcompare_directory=user_inputs_pvcompare_directory, user_inputs_mvs_directory=user_inputs_mvs_directory, year=year, normalization=True, ) # add sector coupling in case heat pump or chiller exists in energyConversion.csv # note: chiller was not tested, yet. heat_pump_and_chiller.add_sector_coupling( user_inputs_mvs_directory=user_inputs_mvs_directory, user_inputs_pvcompare_directory=user_inputs_pvcompare_directory, weather=weather, lat=latitude, lon=longitude, overwrite_hp_parameters=overwrite_heat_parameters, ) demand.calculate_load_profiles( country=country, lat=latitude, lon=longitude, storeys=storeys, year=year, static_inputs_directory=static_inputs_directory, user_inputs_pvcompare_directory=user_inputs_pvcompare_directory, user_inputs_mvs_directory=user_inputs_mvs_directory, weather=weather, ) stratified_thermal_storage.add_strat_tes( weather=weather, lat=latitude, lon=longitude, user_inputs_pvcompare_directory=user_inputs_pvcompare_directory, user_inputs_mvs_directory=user_inputs_mvs_directory, overwrite_tes_parameters=overwrite_heat_parameters, )