From 23491544dd00e71793fec8d9ced36b2a7b9af5f2 Mon Sep 17 00:00:00 2001 From: "k.rieck" Date: Wed, 13 Nov 2024 16:51:37 +0100 Subject: [PATCH 1/2] add energy intensity in utsp --- .../loadprofilegenerator_utsp_connector.py | 156 ++++++------------ 1 file changed, 50 insertions(+), 106 deletions(-) diff --git a/hisim/components/loadprofilegenerator_utsp_connector.py b/hisim/components/loadprofilegenerator_utsp_connector.py index 8a3d10560..995056693 100644 --- a/hisim/components/loadprofilegenerator_utsp_connector.py +++ b/hisim/components/loadprofilegenerator_utsp_connector.py @@ -78,10 +78,7 @@ def get_main_classname(cls): return UtspLpgConnector.get_full_classname() @classmethod - def get_default_utsp_connector_config( - cls, - building_name: str = "BUI1", - ) -> Any: + def get_default_utsp_connector_config(cls, building_name: str = "BUI1",) -> Any: """Creates a default configuration. Chooses default values for the LPG parameters.""" config = UtspLpgConnectorConfig( @@ -160,18 +157,10 @@ def __init__( # Inputs - Not Mandatory self.ww_mass_input_channel: cp.ComponentInput = self.add_input( - self.component_name, - self.WW_MassInput, - lt.LoadTypes.WARM_WATER, - lt.Units.KG_PER_SEC, - False, + self.component_name, self.WW_MassInput, lt.LoadTypes.WARM_WATER, lt.Units.KG_PER_SEC, False, ) self.ww_temperature_input_channel: cp.ComponentInput = self.add_input( - self.component_name, - self.WW_TemperatureInput, - lt.LoadTypes.WARM_WATER, - lt.Units.CELSIUS, - False, + self.component_name, self.WW_TemperatureInput, lt.LoadTypes.WARM_WATER, lt.Units.CELSIUS, False, ) self.number_of_residents_channel: cp.ComponentOutput = self.add_output( @@ -310,7 +299,9 @@ def get_resolution(self) -> str: resolution = datetime.timedelta(seconds=seconds) return str(resolution) - def get_profiles_from_utsp(self, lpg_households: Union[JsonReference, List[JsonReference]], guid: str) -> Tuple[ + def get_profiles_from_utsp( + self, lpg_households: Union[JsonReference, List[JsonReference]], guid: str + ) -> Tuple[ Union[str, List], Union[str, List], Union[str, List], @@ -335,9 +326,7 @@ def get_profiles_from_utsp(self, lpg_households: Union[JsonReference, List[JsonR # choose if one lpg request should be made or several in parallel if isinstance(lpg_households, JsonReference): simulation_config = self.prepare_lpg_simulation_config_for_utsp_request( - start_date=start_date, - end_date=end_date, - household=lpg_households, + start_date=start_date, end_date=end_date, household=lpg_households, ) ( @@ -350,10 +339,7 @@ def get_profiles_from_utsp(self, lpg_households: Union[JsonReference, List[JsonR car_states_file, car_locations_file, driving_distances_file, - ) = self.calculate_one_lpg_request( - simulation_config=simulation_config, - guid=guid, - ) + ) = self.calculate_one_lpg_request(simulation_config=simulation_config, guid=guid,) elif isinstance(lpg_households, List): simulation_configs = [] @@ -374,10 +360,7 @@ def get_profiles_from_utsp(self, lpg_households: Union[JsonReference, List[JsonR car_locations_file, driving_distances_file, ) = self.calculate_multiple_lpg_requests( # type: ignore - url=self.utsp_url, - api_key=self.utsp_api_key, - lpg_configs=simulation_configs, - guid=guid, + url=self.utsp_url, api_key=self.utsp_api_key, lpg_configs=simulation_configs, guid=guid, ) else: @@ -397,9 +380,7 @@ def get_profiles_from_utsp(self, lpg_households: Union[JsonReference, List[JsonR driving_distances_file, ) - def get_profiles_from_predefined_profile( - self, - ) -> Tuple[str, str, str, str, str]: + def get_profiles_from_predefined_profile(self,) -> Tuple[str, str, str, str, str]: """Get the loadprofiles for a specific predefined profile from hisim/inputs/loadprofiles.""" predefined_profile_filepaths = utils.HISIMPATH["occupancy"][self.name_of_predefined_loadprofile] # get first bodily activity files @@ -594,8 +575,7 @@ def build(self): car_locations_file, driving_distances_file, ) = self.get_profiles_from_utsp( - lpg_households=new_unique_config.household, - guid=new_unique_config.guid, + lpg_households=new_unique_config.household, guid=new_unique_config.guid, ) # only one result obtained @@ -770,8 +750,7 @@ def build(self): if self.utsp_config.predictive: SingletonSimRepository().set_entry( - key=SingletonDictKeyEnum.HEATINGBYRESIDENTSYEARLYFORECAST, - entry=self.heating_by_residents, + key=SingletonDictKeyEnum.HEATINGBYRESIDENTSYEARLYFORECAST, entry=self.heating_by_residents, ) def get_result_lists_by_summing_over_value_dict( @@ -957,23 +936,13 @@ def calculate_multiple_lpg_requests( # Create all request objects all_requests: List[TimeSeriesRequest] = [ - TimeSeriesRequest( - config.to_json(), - "LPG", - required_result_files=result_files, - guid=guid, - ) + TimeSeriesRequest(config.to_json(), "LPG", required_result_files=result_files, guid=guid,) for config in lpg_configs ] log.information("Requesting LPG profiles from the UTSP for multiple household.") - results = calculate_multiple_requests( - url, - all_requests, - api_key, - raise_exceptions, - ) + results = calculate_multiple_requests(url, all_requests, api_key, raise_exceptions,) # append all results in lists electricity_file: List = [] @@ -1042,11 +1011,12 @@ def prepare_lpg_simulation_config_for_utsp_request( """Prepare lpg simulation config for the utsp request.""" simulation_config = lpg_helper.create_basic_lpg_config( - household, - HouseTypes.HT23_No_Infrastructure_at_all, - start_date, - end_date, - self.get_resolution(), + householdref=household, + housetype=HouseTypes.HT23_No_Infrastructure_at_all, + startdate=start_date, + enddate=end_date, + external_resolution=self.get_resolution(), + energy_intensity=self.utsp_config.energy_intensity, travel_route_set=self.utsp_config.travel_route_set, transportation_device_set=self.utsp_config.transportation_device_set, charging_station_set=self.utsp_config.charging_station_set, @@ -1071,8 +1041,7 @@ def define_required_result_files(self): # Define required result files electricity = result_file_filters.LPGFilters.sum_hh1( - LoadTypes.Electricity, - no_flex=not self.utsp_config.profile_with_washing_machine_and_dishwasher, + LoadTypes.Electricity, no_flex=not self.utsp_config.profile_with_washing_machine_and_dishwasher, ) warm_water = result_file_filters.LPGFilters.sum_hh1(LoadTypes.Warm_Water, no_flex=False) inner_device_heat_gains = result_file_filters.LPGFilters.sum_hh1( @@ -1166,31 +1135,22 @@ def load_result_files_and_transform_to_lists( if data_acquisition_mode == LpgDataAcquisitionMode.USE_UTSP: # load electricity consumption, water consumption and inner device heat gains electricity_data = io.StringIO(electricity) - pre_electricity_consumption = pd.read_csv( - electricity_data, - sep=";", - decimal=".", - encoding="cp1252", - ).loc[: (steps_desired_in_minutes - 1)] + pre_electricity_consumption = pd.read_csv(electricity_data, sep=";", decimal=".", encoding="cp1252",).loc[ + : (steps_desired_in_minutes - 1) + ] electricity_consumption_list = pd.to_numeric( pre_electricity_consumption["Sum [kWh]"] * 1000 * 60 ).tolist() # 1 kWh/min == 60W / min water_data = io.StringIO(warm_water) - pre_water_consumption = pd.read_csv( - water_data, - sep=";", - decimal=".", - encoding="cp1252", - ).loc[: (steps_desired_in_minutes - 1)] + pre_water_consumption = pd.read_csv(water_data, sep=";", decimal=".", encoding="cp1252",).loc[ + : (steps_desired_in_minutes - 1) + ] water_consumption_list = pd.to_numeric(pre_water_consumption["Sum [L]"]).tolist() inner_device_heat_gain_data = io.StringIO(inner_device_heat_gains) pre_inner_device_heat_gains = pd.read_csv( - inner_device_heat_gain_data, - sep=";", - decimal=".", - encoding="cp1252", + inner_device_heat_gain_data, sep=";", decimal=".", encoding="cp1252", ).loc[: (steps_desired_in_minutes - 1)] inner_device_heat_gains_list = pd.to_numeric( pre_inner_device_heat_gains["Sum [kWh]"] * 1000 * 60 @@ -1199,31 +1159,19 @@ def load_result_files_and_transform_to_lists( elif data_acquisition_mode == LpgDataAcquisitionMode.USE_PREDEFINED_PROFILE: # load electricity consumption, water consumption and inner device heat gains pre_electricity_consumption = pd.read_csv( - electricity, - sep=";", - decimal=".", - encoding="utf-8", - usecols=["Sum [kWh]"], + electricity, sep=";", decimal=".", encoding="utf-8", usecols=["Sum [kWh]"], ).loc[: (steps_desired_in_minutes - 1)] electricity_consumption_list = pd.to_numeric( pre_electricity_consumption.loc[:, "Sum [kWh]"] * 1000 * 60 ).tolist() # 1 kWh/min == 60 000 W / min pre_water_consumption = pd.read_csv( - warm_water, - sep=";", - decimal=".", - encoding="utf-8", - usecols=["Sum [L]"], + warm_water, sep=";", decimal=".", encoding="utf-8", usecols=["Sum [L]"], ).loc[: (steps_desired_in_minutes - 1)] water_consumption_list = pd.to_numeric(pre_water_consumption.loc[:, "Sum [L]"]).tolist() pre_inner_device_heat_gains = pd.read_csv( - inner_device_heat_gains, - sep=";", - decimal=".", - encoding="utf-8", - usecols=["Time", "Sum [kWh]"], + inner_device_heat_gains, sep=";", decimal=".", encoding="utf-8", usecols=["Time", "Sum [kWh]"], ).loc[: (steps_desired_in_minutes - 1)] inner_device_heat_gains_list = pd.to_numeric( pre_inner_device_heat_gains.loc[:, "Sum [kWh]"] * 1000 * 60 @@ -1374,23 +1322,17 @@ def transform_dict_values(self, dict_to_check: Dict) -> Dict: transformed_data[key] = transformed_value return transformed_data - def get_component_kpi_entries( - self, - all_outputs: List, - postprocessing_results: pd.DataFrame, - ) -> List[KpiEntry]: + def get_component_kpi_entries(self, all_outputs: List, postprocessing_results: pd.DataFrame,) -> List[KpiEntry]: """Calculates KPIs for the respective component and return all KPI entries as list.""" occupancy_total_electricity_consumption_in_kilowatt_hour: Optional[float] = None list_of_kpi_entries: List[KpiEntry] = [] for index, output in enumerate(all_outputs): if output.component_name == self.component_name: - if output.field_name == self.ElectricityOutput: + if output.field_name == self.ElectricityOutput and output.unit == lt.Units.WATT: occupancy_total_electricity_consumption_in_watt_series = postprocessing_results.iloc[:, index] - occupancy_total_electricity_consumption_in_kilowatt_hour = ( - KpiHelperClass.compute_total_energy_from_power_timeseries( - power_timeseries_in_watt=occupancy_total_electricity_consumption_in_watt_series, - timeresolution=self.my_simulation_parameters.seconds_per_timestep, - ) + occupancy_total_electricity_consumption_in_kilowatt_hour = KpiHelperClass.compute_total_energy_from_power_timeseries( + power_timeseries_in_watt=occupancy_total_electricity_consumption_in_watt_series, + timeresolution=self.my_simulation_parameters.seconds_per_timestep, ) break @@ -1400,23 +1342,21 @@ def get_component_kpi_entries( unit="kWh", value=occupancy_total_electricity_consumption_in_kilowatt_hour, tag=KpiTagEnumClass.RESIDENTS, - description=self.component_name + description=self.component_name, ) list_of_kpi_entries = [occupancy_total_electricity_consumption_entry] return list_of_kpi_entries @staticmethod - def get_cost_capex(config: UtspLpgConnectorConfig, simulation_parameters: SimulationParameters) -> cp.CapexCostDataClass: # pylint: disable=unused-argument + def get_cost_capex( + config: UtspLpgConnectorConfig, simulation_parameters: SimulationParameters + ) -> cp.CapexCostDataClass: # pylint: disable=unused-argument """Returns investment cost, CO2 emissions and lifetime.""" capex_cost_data_class = cp.CapexCostDataClass.get_default_capex_cost_data_class() return capex_cost_data_class - def get_cost_opex( - self, - all_outputs: List, - postprocessing_results: pd.DataFrame, - ) -> OpexCostDataClass: + def get_cost_opex(self, all_outputs: List, postprocessing_results: pd.DataFrame,) -> OpexCostDataClass: """Calculate OPEX costs, snd write total energy consumption to component-config. No electricity costs for components except for Electricity Meter, @@ -1424,12 +1364,16 @@ def get_cost_opex( """ consumption_in_kwh: float = 0.0 for index, output in enumerate(all_outputs): - if output.component_name == self.config.name and output.load_type == lt.LoadTypes.ELECTRICITY and output.field_name == self.ElectricityOutput: + if ( + output.component_name == self.config.name + and output.load_type == lt.LoadTypes.ELECTRICITY + and output.field_name == self.ElectricityOutput + and output.unit == lt.Units.WATT + ): occupancy_total_electricity_consumption_in_watt_series = postprocessing_results.iloc[:, index] - consumption_in_kwh = ( - KpiHelperClass.compute_total_energy_from_power_timeseries( + consumption_in_kwh = KpiHelperClass.compute_total_energy_from_power_timeseries( power_timeseries_in_watt=occupancy_total_electricity_consumption_in_watt_series, - timeresolution=self.my_simulation_parameters.seconds_per_timestep) + timeresolution=self.my_simulation_parameters.seconds_per_timestep, ) opex_cost_data_class = OpexCostDataClass( @@ -1438,7 +1382,7 @@ def get_cost_opex( co2_footprint_in_kg=0, consumption_in_kwh=consumption_in_kwh, loadtype=lt.LoadTypes.ELECTRICITY, - kpi_tag=KpiTagEnumClass.RESIDENTS + kpi_tag=KpiTagEnumClass.RESIDENTS, ) return opex_cost_data_class From 9520e8e89176d7d8acdbc820f25cfbbf5b2d18fa Mon Sep 17 00:00:00 2001 From: "k.rieck" Date: Wed, 13 Nov 2024 16:52:30 +0100 Subject: [PATCH 2/2] add energy intensity in utsp --- hisim/components/loadprofilegenerator_utsp_connector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hisim/components/loadprofilegenerator_utsp_connector.py b/hisim/components/loadprofilegenerator_utsp_connector.py index 995056693..b06aabd0c 100644 --- a/hisim/components/loadprofilegenerator_utsp_connector.py +++ b/hisim/components/loadprofilegenerator_utsp_connector.py @@ -469,7 +469,7 @@ def build(self): for list_index, list_item in enumerate(self.list_of_file_exists_and_cache_files): file_exists = list_item[0] cache_filepath = list_item[1] - print("lpg cache file", cache_filepath) + log.information("Lpg cache filepath " + cache_filepath) # a cache file exists if file_exists: