north_america_energy_system_catalog.py is completed

montreal_custom_catalog.py is fixed
This commit is contained in:
Saeed Ranjbar 2023-08-23 17:09:55 -04:00
parent 9b0bdf2b7e
commit 3deb63b14a
6 changed files with 190 additions and 63 deletions

View File

@ -34,7 +34,7 @@ class EnergyStorageSystem:
self._maximum_operating_temperature = maximum_operating_temperature
@property
def stroage_id(self):
def id(self):
"""
Get storage id
:return: string
@ -151,7 +151,7 @@ class EnergyStorageSystem:
for _layer in self.layers:
_layers.append(_layer.to_dictionary())
content = {'Storage component': {
'storage id': self.stroage_id,
'storage id': self.id,
'name': self.name,
'model name': self.model_name,
'manufacturer': self.manufacturer,

View File

@ -115,14 +115,14 @@ class System:
_storage_system = [_storage.to_dictionary() for _storage in
self.energy_storage_system] if self.energy_storage_system is not None else None
content = {'Layer': {'id': self.id,
'name': self.name,
'level of detail': self.lod,
'demand types': self.demand_types,
'Generation system(s)': _generation_systems,
'distribution system': _distribution_system,
'emission system': _emission_system,
'energy storage system': _storage_system,
}
content = {'system': {'id': self.id,
'name': self.name,
'level of detail': self.lod,
'demand types': self.demand_types,
'Generation system(s)': _generation_systems,
'distribution system': _distribution_system,
'emission system': _emission_system,
'energy storage system': _storage_system,
}
}
return content

View File

@ -40,7 +40,8 @@ class MontrealCustomCatalog(Catalog):
self._catalog_systems,
self._catalog_generation_equipments,
self._catalog_distribution_equipments,
self._catalog_emission_equipments)
self._catalog_emission_equipments,
storages=None)
def _load_generation_equipments(self):
_equipments = []
@ -62,14 +63,34 @@ class MontrealCustomCatalog(Catalog):
storage = literal_eval(equipment['storage'].capitalize())
generation_system = GenerationSystem(equipment_id,
name,
None,
None,
equipment_type,
fuel_type,
None,
None,
None,
None,
None,
heating_efficiency,
None,
None,
None,
cooling_efficiency,
electricity_efficiency,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
storage,
None)
@ -153,7 +174,8 @@ class MontrealCustomCatalog(Catalog):
demands,
_generation_equipment,
_distribution_equipment,
_emission_equipment))
_emission_equipment,
energy_storage_systems=None))
return _catalog_systems
def _load_archetypes(self):

View File

@ -6,21 +6,18 @@ Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
Code contributors: Saeed Ranjbar saeed.ranjbar@concordia.ca
"""
from ast import literal_eval
import xmltodict
from hub.catalog_factories.catalog import Catalog
from hub.catalog_factories.data_models.energy_systems.system import System
from hub.catalog_factories.data_models.energy_systems.content import Content
from hub.catalog_factories.data_models.energy_systems.generation_system import GenerationSystem
from hub.catalog_factories.data_models.energy_systems.pv_generation_system import PvGenerationSystem
from hub.catalog_factories.data_models.energy_systems.distribution_system import DistributionSystem
from hub.catalog_factories.data_models.energy_systems.emission_system import EmissionSystem
from hub.catalog_factories.data_models.energy_systems.energy_storage_system import EnergyStorageSystem
from hub.catalog_factories.data_models.energy_systems.performance_curves import PerformanceCurves
from hub.catalog_factories.data_models.energy_systems.archetype import Archetype
from hub.catalog_factories.data_models.construction.material import Material
from hub.catalog_factories.data_models.construction.layer import Layer
import hub.helpers.constants as cte
class NorthAmericaEnergySystemCatalog(Catalog):
@ -33,12 +30,16 @@ class NorthAmericaEnergySystemCatalog(Catalog):
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()
print(self._generation_components)
print(len(self._generation_components))
self._storage_components = self._load_storage_components()
print(self._storage_components)
# self._systems = self._load_systems()
# print(self._load_systems())
self._systems = self._load_systems()
self._system_archetypes = self._load_archetypes()
print(self._system_archetypes)
self._content = Content(self._system_archetypes,
self._systems,
self._generation_components,
None,
None,
self._storage_components)
def _load_generation_components(self):
generation_components = []
@ -299,7 +300,7 @@ class NorthAmericaEnergySystemCatalog(Catalog):
insulation_layer = Layer(None, 'insulation', insulation_material, thickness)
thickness = float(tes['@tankThickness']) / 100 # from cm to m
tank_layer = Layer(None, 'insulation', tank_material, thickness)
# the convention is from outside to inside
# the convention is from outside to inside
layers = [insulation_layer, tank_layer]
storage_component = EnergyStorageSystem(storage_id,
name,
@ -330,7 +331,7 @@ class NorthAmericaEnergySystemCatalog(Catalog):
insulation_layer = Layer(None, 'insulation', insulation_material, thickness)
thickness = float(template['@tankThickness']) / 100 # from cm to m
tank_layer = Layer(None, 'insulation', tank_material, thickness)
# the convention is from outside to inside
# the convention is from outside to inside
layers = [insulation_layer, tank_layer]
storage_component = EnergyStorageSystem(storage_id,
name,
@ -349,24 +350,44 @@ class NorthAmericaEnergySystemCatalog(Catalog):
storage_components.append(storage_component)
return storage_components
# def _load_systems(self):
# _catalog_systems = []
# systems = self._archetypes['EnergySystemCatalog']['systems']['system']
# for system in systems:
# system_id = system['@id']
# name = system['@name']
# generation_components =
#
# energy_system = System(None,
# system_id,
# None,
# None,
# None,
# None,
# None,
# None)
# _catalog_systems.append(energy_system)
# return _catalog_systems
def _load_systems(self):
_catalog_systems = []
systems = self._archetypes['EnergySystemCatalog']['systems']['system']
for system in systems:
system_id = system['@id']
name = system['name']
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)
_catalog_systems.append(energy_system)
return _catalog_systems
def _load_archetypes(self):
_system_archetypes = []
system_clusters = self._archetypes['EnergySystemCatalog']['system_archetypes']['system_archetype']
for system_cluster in system_clusters:
name = system_cluster['name']
systems = system_cluster['systems']['system_id']
_systems = []
for system in systems:
for system_archetype in self._systems:
if int(system_archetype.id) == int(system):
_systems.append(system_archetype)
_system_archetypes.append(Archetype(None, name, _systems))
return _system_archetypes
def _load_materials(self):
materials = []
@ -398,12 +419,93 @@ class NorthAmericaEnergySystemCatalog(Catalog):
if _material is None:
raise ValueError(f'Material not found in catalog [{material_name}]')
def _load_demands(self):
demands = []
_demands = self._archetypes['encomp:EnergySystemCatalog']['energydemand']
for _demand in _demands:
demand_type = _demand['@name']
demands.append(demand_type)
return demands
@staticmethod
def _search_generation_equipment(generation_systems, generation_id):
_generation_systems = []
for generation in generation_systems:
if generation.id in generation_id:
_generation_systems.append(generation)
if len(_generation_systems) == 0:
_generation_systems = None
raise ValueError(f'The system with the following id is not found in catalog [{generation_id}]')
return _generation_systems
# def _search_demands(self, config_name):
@staticmethod
def _search_storage_equipment(storage_systems, storage_id):
_storage_systems = []
for storage in storage_systems:
if storage.id in storage_id:
_storage_systems.append(storage)
if len(_storage_systems) == 0:
_storage_systems_systems = None
raise ValueError(f'The system with the following id is not found in catalog [{storage_id}]')
return _storage_systems
def names(self, category=None):
"""
Get the catalog elements names
:parm: optional category filter
"""
if category is None:
_names = {'archetypes': [], 'systems': [], 'generation_equipments': [], 'storage_equipments': []}
for archetype in self._content.archetypes:
_names['archetypes'].append(archetype.name)
for system in self._content.systems:
_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':
for archetype in self._content.archetypes:
_names[category].append(archetype.name)
elif category.lower() == 'systems':
for system in self._content.systems:
_names[category].append(system.name)
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
def entries(self, category=None):
"""
Get the catalog elements
:parm: optional category filter
"""
if category is None:
return self._content
if category.lower() == 'archetypes':
return self._content.archetypes
if category.lower() == 'systems':
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):
"""
Get one catalog element by names
:parm: entry name
"""
for entry in self._content.archetypes:
if entry.name.lower() == name.lower():
return entry
for entry in self._content.systems:
if entry.name.lower() == name.lower():
return entry
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")

View File

@ -71,8 +71,8 @@
<system id="1">
<name>Air Source Heat Pump with Natural Gas Boiler and thermal storage</name>
<demands>
<demand_id>1</demand_id>
<demand_id>2</demand_id>
<demand>heating</demand>
<demand>domestic_hot_water</demand>
</demands>
<components>
<generation_id>16</generation_id>
@ -83,8 +83,8 @@
<system id="2">
<name>Air Source Heat Pump with Electrical Boiler and thermal storage</name>
<demands>
<demand_id>1</demand_id>
<demand_id>2</demand_id>
<demand>heating</demand>
<demand>domestic_hot_water</demand>
</demands>
<components>
<generation_id>17</generation_id>
@ -95,8 +95,8 @@
<system id="3">
<name>Ground Source Heat Pump with Natural Gas Boiler and thermal storage</name>
<demands>
<demand_id>1</demand_id>
<demand_id>2</demand_id>
<demand>heating</demand>
<demand>domestic_hot_water</demand>
</demands>
<components>
<generation_id>16</generation_id>
@ -107,8 +107,8 @@
<system id="4">
<name>Ground Source Heat Pump with Electrical Boiler and thermal storage</name>
<demands>
<demand_id>1</demand_id>
<demand_id>2</demand_id>
<demand>heating</demand>
<demand>domestic_hot_water</demand>
</demands>
<components>
<generation_id>17</generation_id>
@ -119,8 +119,8 @@
<system id="5">
<name>Water Source Heat Pump with Natural Gas Boiler and thermal storage</name>
<demands>
<demand_id>1</demand_id>
<demand_id>2</demand_id>
<demand>heating</demand>
<demand>domestic_hot_water</demand>
</demands>
<components>
<generation_id>16</generation_id>
@ -131,8 +131,8 @@
<system id="6">
<name>Water Source Heat Pump with Electrical Boiler and thermal storage</name>
<demands>
<demand_id>1</demand_id>
<demand_id>2</demand_id>
<demand>heating</demand>
<demand>domestic_hot_water</demand>
</demands>
<components>
<generation_id>17</generation_id>
@ -143,7 +143,7 @@
<system id="7">
<name>Photovoltaic System</name>
<demands>
<demand_id>3</demand_id>
<demand>electricity</demand>
</demands>
<components>
<generation_id>21</generation_id>

View File

@ -37,3 +37,6 @@ class TestSystemsCatalog(TestCase):
def test_north_america_systems_catalog(self):
catalog = EnergySystemsCatalogFactory('north_america').catalog
def test_montreal_catalog(self):
catalog = EnergySystemsCatalogFactory('montreal_custom').catalog