From c6d4feec8929cbac698b3c8b0a3df1aa13c7ece8 Mon Sep 17 00:00:00 2001 From: Saeed Ranjbar Date: Mon, 16 Oct 2023 16:44:53 -0400 Subject: [PATCH] Modified the classes and the north amercia catalog importer based on the changes Pilar made in the data model structure --- .../energy_systems/generation_system.py | 11 +- .../non_pv_generation_system.py | 4 +- .../energy_systems/pv_generation_system.py | 4 +- .../north_america_energy_system_catalog.py | 158 ++++++------------ .../energy_systems/north_america_systems.xml | 47 +++--- tests/test_systems_catalog.py | 20 ++- 6 files changed, 110 insertions(+), 134 deletions(-) diff --git a/hub/catalog_factories/data_models/energy_systems/generation_system.py b/hub/catalog_factories/data_models/energy_systems/generation_system.py index 1b43a183..cb4b1e9d 100644 --- a/hub/catalog_factories/data_models/energy_systems/generation_system.py +++ b/hub/catalog_factories/data_models/energy_systems/generation_system.py @@ -19,9 +19,10 @@ class GenerationSystem(ABC): Heat Generation system class """ - def __init__(self, system_id, model_name=None, manufacturer=None, fuel_type=None, + def __init__(self, system_id, name, model_name=None, manufacturer=None, fuel_type=None, distribution_systems=None, energy_storage_systems=None): self._system_id = system_id + self._name = name self._model_name = model_name self._manufacturer = manufacturer self._fuel_type = fuel_type @@ -36,6 +37,14 @@ class GenerationSystem(ABC): """ return self._system_id + @property + def name(self): + """ + Get system name + :return: string + """ + return self._name + @property def system_type(self): """ diff --git a/hub/catalog_factories/data_models/energy_systems/non_pv_generation_system.py b/hub/catalog_factories/data_models/energy_systems/non_pv_generation_system.py index 7f622382..a33490d4 100644 --- a/hub/catalog_factories/data_models/energy_systems/non_pv_generation_system.py +++ b/hub/catalog_factories/data_models/energy_systems/non_pv_generation_system.py @@ -16,7 +16,7 @@ class NonPvGenerationSystem(GenerationSystem): Non PV Generation system class """ - def __init__(self, system_id, system_type, model_name=None, manufacturer=None, fuel_type=None, + def __init__(self, system_id, name, system_type, model_name=None, manufacturer=None, fuel_type=None, nominal_heat_output=None, maximum_heat_output=None, minimum_heat_output=None, source_medium=None, supply_medium=None, heat_efficiency=None, nominal_cooling_output=None, maximum_cooling_output=None, minimum_cooling_output=None, cooling_efficiency=None, electricity_efficiency=None, @@ -26,7 +26,7 @@ class NonPvGenerationSystem(GenerationSystem): heat_fuel_consumption_curve=None, heat_efficiency_curve=None, cooling_output_curve=None, cooling_fuel_consumption_curve=None, cooling_efficiency_curve=None, distribution_systems=None, energy_storage_systems=None): - super().__init__(system_id=system_id, model_name=model_name, manufacturer=manufacturer, fuel_type=fuel_type, + super().__init__(system_id=system_id, name=name, model_name=model_name, manufacturer=manufacturer, fuel_type=fuel_type, distribution_systems=distribution_systems, energy_storage_systems=energy_storage_systems) self._system_type = system_type self._nominal_heat_output = nominal_heat_output diff --git a/hub/catalog_factories/data_models/energy_systems/pv_generation_system.py b/hub/catalog_factories/data_models/energy_systems/pv_generation_system.py index 5aa272b7..232d5402 100644 --- a/hub/catalog_factories/data_models/energy_systems/pv_generation_system.py +++ b/hub/catalog_factories/data_models/energy_systems/pv_generation_system.py @@ -14,12 +14,12 @@ class PvGenerationSystem(GenerationSystem): Electricity Generation system class """ - def __init__(self, system_id, model_name=None, manufacturer=None, electricity_efficiency=None, + def __init__(self, system_id, name, model_name=None, manufacturer=None, electricity_efficiency=None, nominal_electricity_output=None, nominal_ambient_temperature=None, nominal_cell_temperature=None, nominal_radiation=None, standard_test_condition_cell_temperature=None, standard_test_condition_maximum_power=None, cell_temperature_coefficient=None, width=None, height=None, distribution_systems=None, energy_storage_systems=None): - super().__init__(system_id=system_id, model_name=model_name, + super().__init__(system_id=system_id, name=name, model_name=model_name, manufacturer=manufacturer, fuel_type='renewable', distribution_systems=distribution_systems, energy_storage_systems=energy_storage_systems) self._system_type = 'PV system' diff --git a/hub/catalog_factories/energy_systems/north_america_energy_system_catalog.py b/hub/catalog_factories/energy_systems/north_america_energy_system_catalog.py index ee7873cc..55fa4bf4 100644 --- a/hub/catalog_factories/energy_systems/north_america_energy_system_catalog.py +++ b/hub/catalog_factories/energy_systems/north_america_energy_system_catalog.py @@ -28,8 +28,9 @@ class NorthAmericaEnergySystemCatalog(Catalog): path = str(path / 'north_america_systems.xml') with open(path, 'r', encoding='utf-8') as xml: self._archetypes = xmltodict.parse(xml.read(), force_list=['photovoltaicModules', 'templateStorages']) - self._generation_components = self._load_generation_components() + self._storage_components = self._load_storage_components() + self._generation_components = self._load_generation_components() self._systems = self._load_systems() self._system_archetypes = self._load_archetypes() self._content = Content(self._system_archetypes, @@ -39,12 +40,18 @@ class NorthAmericaEnergySystemCatalog(Catalog): def _load_generation_components(self): generation_components = [] boilers = self._archetypes['EnergySystemCatalog']['energy_generation_components']['boilers'] + print(len(boilers)) heat_pumps = self._archetypes['EnergySystemCatalog']['energy_generation_components']['heatPumps'] + print(len(heat_pumps)) photovoltaics = self._archetypes['EnergySystemCatalog']['energy_generation_components']['photovoltaicModules'] + print(len(photovoltaics)) templates = self._archetypes['EnergySystemCatalog']['energy_generation_components']['templateGenerationEquipments'] + print(len(templates)) for boiler in boilers: + print(boiler) boiler_id = boiler['@generation_id'] - system_type = boiler['@name'] + name = boiler['@name'] + system_type = 'Boiler' boiler_model_name = boiler['@modelName'] boiler_manufacturer = boiler['@manufacturer'] boiler_fuel_type = boiler['@fuel'] @@ -53,7 +60,8 @@ class NorthAmericaEnergySystemCatalog(Catalog): boiler_minimum_heat_output = float(boiler['@minimumHeatOutput']) boiler_heat_efficiency = float(boiler['@nominalEfficiency']) boiler_component = NonPvGenerationSystem(boiler_id, - system_type, + name=name, + system_type=system_type, model_name=boiler_model_name, manufacturer=boiler_manufacturer, fuel_type=boiler_fuel_type, @@ -64,7 +72,8 @@ class NorthAmericaEnergySystemCatalog(Catalog): generation_components.append(boiler_component) for heat_pump in heat_pumps: heat_pump_id = heat_pump['@generation_id'] - system_type = heat_pump['@name'] + name = heat_pump['@name'] + system_type = 'Heat Pump' heat_pump_model_name = heat_pump['@modelName'] heat_pump_manufacturer = heat_pump['@manufacturer'] heat_pump_fuel_type = heat_pump['@fuel'] @@ -85,7 +94,8 @@ class NorthAmericaEnergySystemCatalog(Catalog): cop_curve = PerformanceCurves(cop_curve_type, dependant_variable, parameters, coefficients) heat_pump_component = NonPvGenerationSystem(heat_pump_id, - system_type, + name=name, + system_type=system_type, model_name=heat_pump_model_name, manufacturer=heat_pump_manufacturer, fuel_type=heat_pump_fuel_type, @@ -103,6 +113,7 @@ class NorthAmericaEnergySystemCatalog(Catalog): generation_components.append(heat_pump_component) for pv in photovoltaics: pv_id = pv['@generation_id'] + name = pv['@name'] pv_model_name = pv['@modelName'] pv_manufacturer = pv['@manufacturer'] pv_electricity_efficiency = pv['@nominalEfficiency'] @@ -117,6 +128,7 @@ class NorthAmericaEnergySystemCatalog(Catalog): height = float(pv['@height']) pv_component = PvGenerationSystem(pv_id, + name=name, model_name=pv_model_name, manufacturer=pv_manufacturer, electricity_efficiency=pv_electricity_efficiency, @@ -130,45 +142,26 @@ class NorthAmericaEnergySystemCatalog(Catalog): width=width, height=height) generation_components.append(pv_component) + for template in templates: system_id = template['@generation_id'] system_name = template['@name'] + if 'storage_id' in template.keys(): + storage_component = template['storage_id'] + storage_systems = self._search_storage_equipment(self._load_storage_components(), storage_component) + energy_storage_system = storage_systems + else: + energy_storage_system = None if "Boiler" in system_name: system_type = 'boiler' fuel_type = template['@fuel'] heat_efficiency = float(template['@nominalEfficiency']) - source_medium = None - supply_medium = None - boiler_template = GenerationSystem(system_id, - system_name, - None, - None, - system_type, - fuel_type, - None, - None, - None, - source_medium, - supply_medium, - heat_efficiency, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None) + boiler_template = NonPvGenerationSystem(system_id=system_id, + name=system_name, + system_type=system_type, + fuel_type=fuel_type, + heat_efficiency=heat_efficiency, + energy_storage_systems=energy_storage_system) generation_components.append(boiler_template) elif "Heat Pump" in system_name: system_type = 'heat pump' @@ -176,55 +169,23 @@ class NorthAmericaEnergySystemCatalog(Catalog): heat_efficiency = template['@nominalCOP'] source_medium = template['@heatSource'] supply_medium = template['@supply_medium'] - heat_pump_template = GenerationSystem(system_id, - system_name, - None, - None, - system_type, - fuel_type, - None, - None, - None, - source_medium, - supply_medium, - heat_efficiency, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None, - None) + heat_pump_template = NonPvGenerationSystem(system_id=system_id, + name=system_name, + system_type=system_type, + source_medium=source_medium, + supply_medium=supply_medium, + fuel_type=fuel_type, + heat_efficiency=heat_efficiency) generation_components.append(heat_pump_template) else: electricity_efficiency = float(template['@nominalEfficiency']) height = float(template['@height']) width = float(template['@width']) - pv_template = PvGenerationSystem(system_id, - system_name, - None, - None, - electricity_efficiency, - None, - None, - None, - None, - None, - None, - None, - width, - height) + pv_template = PvGenerationSystem(system_id=system_id, + name=system_name, + electricity_efficiency=electricity_efficiency, + width=width, + height=height) generation_components.append(pv_template) return generation_components @@ -235,7 +196,6 @@ class NorthAmericaEnergySystemCatalog(Catalog): template_storages = self._archetypes['EnergySystemCatalog']['energy_storage_components']['templateStorages'] for tes in thermal_storages: storage_id = tes['@storage_id'] - name = tes['@name'] model_name = tes['@modelName'] manufacturer = tes['@manufacturer'] storage_type = 'sensible' @@ -254,7 +214,6 @@ class NorthAmericaEnergySystemCatalog(Catalog): # the convention is from outside to inside layers = [insulation_layer, tank_layer] storage_component = ThermalStorageSystem(storage_id, - name, model_name, manufacturer, storage_type, @@ -268,7 +227,6 @@ class NorthAmericaEnergySystemCatalog(Catalog): for template in template_storages: storage_id = template['@storage_id'] - name = template['@name'] storage_type = 'sensible' maximum_temperature = template['@maxTemp'] height = template['physical_characteristics']['@height'] @@ -284,7 +242,6 @@ class NorthAmericaEnergySystemCatalog(Catalog): # the convention is from outside to inside layers = [insulation_layer, tank_layer] storage_component = ThermalStorageSystem(storage_id, - name, None, None, storage_type, @@ -306,19 +263,12 @@ class NorthAmericaEnergySystemCatalog(Catalog): demands = system['demands']['demand'] generation_components = system['components']['generation_id'] generation_systems = self._search_generation_equipment(self._load_generation_components(), generation_components) - if 'storage_id' in system['components'].keys(): - storage_components = system['components']['storage_id'] - storage_systems = self._search_storage_equipment(self._load_storage_components(), storage_components) - else: - storage_systems = None - energy_system = System(None, - system_id, - name, - demands, - generation_systems, - None, - None, - storage_systems) + energy_system = System(system_id=system_id, + name=name, + demand_types=demands, + generation_systems=generation_systems, + distribution_systems=None, + configuration_schema=None) _catalog_systems.append(energy_system) return _catalog_systems @@ -333,7 +283,7 @@ class NorthAmericaEnergySystemCatalog(Catalog): for system_archetype in self._systems: if int(system_archetype.id) in integer_system_ids: _systems.append(system_archetype) - _system_archetypes.append(Archetype(None, name, _systems)) + _system_archetypes.append(Archetype(name=name, systems=_systems)) return _system_archetypes def _load_materials(self): @@ -411,8 +361,6 @@ class NorthAmericaEnergySystemCatalog(Catalog): _names['systems'].append(system.name) for equipment in self._content.generation_equipments: _names['generation_equipments'].append(equipment.name) - for equipment in self._content.storage_equipments: - _names['storage_equipments'].append(equipment.name) else: _names = {category: []} if category.lower() == 'archetypes': @@ -424,9 +372,6 @@ class NorthAmericaEnergySystemCatalog(Catalog): elif category.lower() == 'generation_equipments': for system in self._content.generation_equipments: _names[category].append(system.name) - elif category.lower() == 'storage_equipments': - for system in self._content.storage_equipments: - _names[category].append(system.name) else: raise ValueError(f'Unknown category [{category}]') return _names @@ -444,8 +389,6 @@ class NorthAmericaEnergySystemCatalog(Catalog): return self._content.systems if category.lower() == 'generation_equipments': return self._content.generation_equipments - if category.lower() == 'storage_equipments': - return self._content.storage_equipments raise ValueError(f'Unknown category [{category}]') def get_entry(self, name): @@ -462,7 +405,4 @@ class NorthAmericaEnergySystemCatalog(Catalog): for entry in self._content.generation_equipments: if entry.name.lower() == name.lower(): return entry - for entry in self._content.storage_equipments: - if entry.name.lower() == name.lower(): - return entry raise IndexError(f"{name} doesn't exists in the catalog") diff --git a/hub/data/energy_systems/north_america_systems.xml b/hub/data/energy_systems/north_america_systems.xml index 36cee745..2a7c89c8 100644 --- a/hub/data/energy_systems/north_america_systems.xml +++ b/hub/data/energy_systems/north_america_systems.xml @@ -41,12 +41,27 @@ - - - - - - + + 6 + + + 6 + + + 6 + + + 6 + + + 6 + + + + + + + @@ -99,9 +114,8 @@ domestic_hot_water - 16 + 21 18 - 6 @@ -111,9 +125,8 @@ domestic_hot_water - 17 + 22 18 - 6 @@ -123,9 +136,8 @@ domestic_hot_water - 16 + 21 19 - 6 @@ -135,9 +147,8 @@ domestic_hot_water - 17 + 22 19 - 6 @@ -147,9 +158,8 @@ domestic_hot_water - 16 + 21 20 - 6 @@ -159,9 +169,8 @@ domestic_hot_water - 17 + 22 20 - 6 @@ -170,7 +179,7 @@ electricity - 21 + 26 diff --git a/tests/test_systems_catalog.py b/tests/test_systems_catalog.py index 01da9114..87634a73 100644 --- a/tests/test_systems_catalog.py +++ b/tests/test_systems_catalog.py @@ -36,4 +36,22 @@ class TestSystemsCatalog(TestCase): def test_north_america_systems_catalog(self): catalog = EnergySystemsCatalogFactory('north_america').catalog - print(catalog.entries()) + + catalog_categories = catalog.names() + archetypes = catalog.names('archetypes') + self.assertEqual(6, len(archetypes['archetypes'])) + systems = catalog.names('systems') + self.assertEqual(7, len(systems['systems'])) + generation_equipments = catalog.names('generation_equipments') + self.assertEqual(26, len(generation_equipments['generation_equipments'])) + with self.assertRaises(ValueError): + catalog.names('unknown') + + # retrieving all the entries should not raise any exceptions + for category in catalog_categories: + for value in catalog_categories[category]: + catalog.get_entry(value) + + with self.assertRaises(IndexError): + catalog.get_entry('unknown') +