Merge pull request 'fixing_unittests' (#12) from fixing_unittests into main

Reviewed-on: https://nextgenerations-cities.encs.concordia.ca/gitea/CERC/hub/pulls/12
This commit is contained in:
Guille Gutierrez 2023-03-23 12:02:04 -04:00
commit 33c854acad
4 changed files with 97 additions and 75 deletions

View File

@ -54,35 +54,38 @@ class MontrealCustomCatalog(Catalog):
def _get_capital_costs(self, entry): def _get_capital_costs(self, entry):
general_chapters = [] general_chapters = []
chapters_titles = CostHelper().chapters_in_lod1 chapters_titles = CostHelper().chapters_in_lod1
shell = entry['B_shell']
items_list = [] items_list = []
item_type = 'B10_superstructure' item_type = 'B10_superstructure'
item_description = self._item_with_refurbishment_values(entry, item_type) item_description = self._item_with_refurbishment_values(shell, item_type)
items_list.append(item_description) items_list.append(item_description)
for item in entry['B20_envelope']: for item in shell['B20_envelope']:
item_type = item item_type = item
item_description = self._item_with_refurbishment_values(entry['B20_envelope'], item_type) item_description = self._item_with_refurbishment_values(shell['B20_envelope'], item_type)
items_list.append(item_description) items_list.append(item_description)
item_type = 'B30_roofing' item_type = 'B3010_opaque_roof'
item_description = self._item_with_refurbishment_values(entry, item_type) item_description = self._item_with_refurbishment_values(shell['B30_roofing'], item_type)
items_list.append(item_description) items_list.append(item_description)
general_chapters.append(Chapter('B_shell', items_list)) general_chapters.append(Chapter('B_shell', items_list))
items_list = [] items_list = []
item_type = 'D301010_photovoltaic_system' item_type = 'D301010_photovoltaic_system'
item_description = self._item_with_threesome(entry['D30_hvac']['D3010_energy_supply'], item_type) services = entry['D_services']
item_description = self._item_with_threesome(services['D30_hvac']['D3010_energy_supply'], item_type)
items_list.append(item_description) items_list.append(item_description)
item_type_list = ['D3020_heat_generating_systems', 'D3030_cooling_generation_systems', 'D3040_distribution_systems', item_type_list = ['D3020_heat_generating_systems', 'D3030_cooling_generation_systems', 'D3040_distribution_systems',
'D3080_other_hvac_ahu'] 'D3080_other_hvac_ahu']
for item_type in item_type_list: for item_type in item_type_list:
item_description = self._item_with_threesome(entry['D30_hvac'], item_type) item_description = self._item_with_threesome(services['D30_hvac'], item_type)
items_list.append(item_description) items_list.append(item_description)
item_type = 'D5020lighting_and_branch_wiring' item_type = 'D5020_lighting_and_branch_wiring'
item_description = self._item_with_threesome(entry['D50_electrical'], item_type) item_description = self._item_with_threesome(services['D50_electrical'], item_type)
items_list.append(item_description) items_list.append(item_description)
general_chapters.append(Chapter('D_services', items_list)) general_chapters.append(Chapter('D_services', items_list))
design_allowance = float(entry['Z_allowances_overhead_profit']['Z10_design_allowance']['#text']) / 100 allowances = entry['Z_allowances_overhead_profit']
overhead_and_profit = float(entry['Z_allowances_overhead_profit']['Z10_overhead_and_profit']['#text']) / 100 design_allowance = float(allowances['Z10_design_allowance']['#text']) / 100
overhead_and_profit = float(allowances['Z20_overhead_profit']['#text']) / 100
_capital_cost = CapitalCost(general_chapters, design_allowance, overhead_and_profit) _capital_cost = CapitalCost(general_chapters, design_allowance, overhead_and_profit)
return _capital_cost return _capital_cost
@ -90,17 +93,17 @@ class MontrealCustomCatalog(Catalog):
@staticmethod @staticmethod
def _get_operational_costs(entry): def _get_operational_costs(entry):
fuels = [] fuels = []
for item in entry['fuels']: for item in entry['fuels']['fuel']:
fuel_type = item['fuel']['@fuel_type'] fuel_type = item['@fuel_type']
fuel_variable = float(entry['fuel']['variable']['#text']) fuel_variable = float(item['variable']['#text'])
fuel_variable_units = float(entry['fuel']['variable']['@cost_unit']) fuel_variable_units = item['variable']['@cost_unit']
fuel_fixed_monthly = None fuel_fixed_monthly = None
fuel_fixed_peak = None fuel_fixed_peak = None
if fuel_type == 'electricity': if fuel_type == 'electricity':
fuel_fixed_monthly = float(entry['fuel']['fixed']['fixed_monthly']['#text']) fuel_fixed_monthly = float(item['fixed_monthly']['#text'])
fuel_fixed_peak = float(entry['fuel']['fixed']['fixed_power']['#text']) / 1000 fuel_fixed_peak = float(item['fixed_power']['#text']) / 1000
elif fuel_type == 'gas': elif fuel_type == 'gas':
fuel_fixed_monthly = float(entry['fuel']['fixed']['fixed_monthly']['#text']) fuel_fixed_monthly = float(item['fixed_monthly']['#text'])
fuel = Fuel(fuel_type, fuel = Fuel(fuel_type,
fixed_monthly=fuel_fixed_monthly, fixed_monthly=fuel_fixed_monthly,
fixed_power=fuel_fixed_peak, fixed_power=fuel_fixed_peak,
@ -110,7 +113,7 @@ class MontrealCustomCatalog(Catalog):
heating_equipment_maintenance = float(entry['maintenance']['heating_equipment']['#text']) / 1000 heating_equipment_maintenance = float(entry['maintenance']['heating_equipment']['#text']) / 1000
cooling_equipment_maintenance = float(entry['maintenance']['cooling_equipment']['#text']) / 1000 cooling_equipment_maintenance = float(entry['maintenance']['cooling_equipment']['#text']) / 1000
photovoltaic_system_maintenance = float(entry['maintenance']['photovoltaic_system']['#text']) photovoltaic_system_maintenance = float(entry['maintenance']['photovoltaic_system']['#text'])
co2_emissions = float(entry['CO2_cost']['#text']) co2_emissions = float(entry['co2_cost']['#text'])
_operational_cost = OperationalCost(fuels, _operational_cost = OperationalCost(fuels,
heating_equipment_maintenance, heating_equipment_maintenance,
cooling_equipment_maintenance, cooling_equipment_maintenance,
@ -127,14 +130,13 @@ class MontrealCustomCatalog(Catalog):
country = archetype['@country'] country = archetype['@country']
lod = float(archetype['@lod']) lod = float(archetype['@lod'])
currency = archetype['currency'] currency = archetype['currency']
print(currency)
capital_cost = self._get_capital_costs(archetype['capital_cost']) capital_cost = self._get_capital_costs(archetype['capital_cost'])
operational_cost = self._get_operational_costs(archetype['operational_cost']) operational_cost = self._get_operational_costs(archetype['operational_cost'])
end_of_life_cost = float(archetype['end_of_life_cost']['#text']) end_of_life_cost = float(archetype['end_of_life_cost']['#text'])
construction = float(archetype['incomes']['subsidies']['construction_subsidy']['#text']) construction = float(archetype['incomes']['subsidies']['construction']['#text'])
hvac = float(archetype['incomes']['subsidies']['hvac_subsidy']['#text']) hvac = float(archetype['incomes']['subsidies']['hvac']['#text'])
photovoltaic_system = float(archetype['incomes']['subsidies']['photovoltaic_subsidy']['#text']) photovoltaic_system = float(archetype['incomes']['subsidies']['photovoltaic']['#text'])
electricity_exports = float(archetype['incomes']['energy_exports']['electricity']['#text']) / 1000 / 3600 electricity_exports = float(archetype['incomes']['electricity_export']['#text']) / 1000 / 3600
reduction_tax = float(archetype['incomes']['tax_reduction']['#text']) / 100 reduction_tax = float(archetype['incomes']['tax_reduction']['#text']) / 100
income = Income(construction_subsidy=construction, income = Income(construction_subsidy=construction,
hvac_subsidy=hvac, hvac_subsidy=hvac,

View File

@ -4,7 +4,7 @@
<capital_cost> <capital_cost>
<B_shell> <B_shell>
<B10_superstructure> <B10_superstructure>
<refurbishment_cost_basement cost_unit="currency/m2"> 0 </refurbishment_cost_basement> <refurbishment_cost cost_unit="currency/m2"> 0 </refurbishment_cost>
</B10_superstructure> </B10_superstructure>
<B20_envelope> <B20_envelope>
<B2010_opaque_walls> <B2010_opaque_walls>
@ -24,7 +24,7 @@
<D30_hvac> <D30_hvac>
<D3010_energy_supply> <D3010_energy_supply>
<D301010_photovoltaic_system> <D301010_photovoltaic_system>
<initial_investment cost_unit="currency/m2"> 800 </initial_investment> <investment_cost cost_unit="currency/m2"> 800 </investment_cost>
<reposition cost_unit="currency/m2"> 800 </reposition> <reposition cost_unit="currency/m2"> 800 </reposition>
<lifetime_equipment lifetime="years"> 25 </lifetime_equipment> <lifetime_equipment lifetime="years"> 25 </lifetime_equipment>
</D301010_photovoltaic_system> </D301010_photovoltaic_system>
@ -51,16 +51,16 @@
</D3080_other_hvac_ahu> </D3080_other_hvac_ahu>
</D30_hvac> </D30_hvac>
<D50_electrical> <D50_electrical>
<D5020lighting_and_branch_wiring> <D5020_lighting_and_branch_wiring>
<refurbishment_cost cost_unit="currency/kW"> 139 </refurbishment_cost> <investment_cost cost_unit="currency/kW"> 139 </investment_cost>
<reposition cost_unit="currency/kW"> 139 </reposition> <reposition cost_unit="currency/kW"> 139 </reposition>
<lifetime_equipment lifetime="years"> 20 </lifetime_equipment> <lifetime_equipment lifetime="years"> 20 </lifetime_equipment>
</D5020lighting_and_branch_wiring> </D5020_lighting_and_branch_wiring>
</D50_electrical> </D50_electrical>
</D_services> </D_services>
<Z_allowances_overhead_profit> <Z_allowances_overhead_profit>
<Z10_design_allowance cost_unit="%"> 2.5 </Z10_design_allowance> <Z10_design_allowance cost_unit="%"> 2.5 </Z10_design_allowance>
<Z10_overhead_and_profit cost_unit="%"> 14 </Z10_overhead_and_profit> <Z20_overhead_profit cost_unit="%"> 14 </Z20_overhead_profit>
</Z_allowances_overhead_profit> </Z_allowances_overhead_profit>
</capital_cost> </capital_cost>
<operational_cost> <operational_cost>
@ -81,23 +81,21 @@
<variable cost_unit="currency/kg"> 0.09 </variable> <variable cost_unit="currency/kg"> 0.09 </variable>
</fuel> </fuel>
</fuels> </fuels>
<maintenances> <maintenance>
<maintenance type="heating_equipment" cost_unit="currency/kW">40</maintenance> <heating_equipment cost_unit="currency/kW">40</heating_equipment>
<maintenance type="cooling_equipment" cost_unit="currency/kW">40</maintenance> <cooling_equipment cost_unit="currency/kW">40</cooling_equipment>
<maintenance type="photovoltaic_system" cost_unit="currency/m2">1</maintenance> <photovoltaic_system cost_unit="currency/m2">1</photovoltaic_system>
</maintenances> </maintenance>
<co2_cost cost_unit="currency/kgCO2"> 30 </co2_cost> <co2_cost cost_unit="currency/kgCO2"> 30 </co2_cost>
</operational_cost> </operational_cost>
<end_of_life_cost cost_unit="currency/m2"> 6.3 </end_of_life_cost> <end_of_life_cost cost_unit="currency/m2"> 6.3 </end_of_life_cost>
<incomes> <incomes>
<subsidies> <subsidies>
<subsidy type="construction" cost_unit="%">2</subsidy> <construction cost_unit="%">2</construction>
<subsidy type="hvac" cost_unit="%">1.5</subsidy> <hvac cost_unit="%">1.5</hvac>
<subsidy type="photovoltaic" cost_unit="%">3.6</subsidy> <photovoltaic cost_unit="%">3.6</photovoltaic>
</subsidies> </subsidies>
<energy_exports> <electricity_export cost_unit="currency/kWh">0</electricity_export>
<energy_export type="electricity" cost_unit="currency/kWh">0</energy_export>
</energy_exports>
<tax_reduction cost_unit="%">2</tax_reduction> <tax_reduction cost_unit="%">2</tax_reduction>
</incomes> </incomes>
</archetype> </archetype>
@ -106,7 +104,7 @@
<capital_cost> <capital_cost>
<B_shell> <B_shell>
<B10_superstructure> <B10_superstructure>
<refurbishment_cost_basement cost_unit="currency/m2"> 0 </refurbishment_cost_basement> <refurbishment_cost cost_unit="currency/m2"> 0 </refurbishment_cost>
</B10_superstructure> </B10_superstructure>
<B20_envelope> <B20_envelope>
<B2010_opaque_walls> <B2010_opaque_walls>
@ -126,7 +124,7 @@
<D30_hvac> <D30_hvac>
<D3010_energy_supply> <D3010_energy_supply>
<D301010_photovoltaic_system> <D301010_photovoltaic_system>
<initial_investment cost_unit="currency/m2"> 800 </initial_investment> <investment_cost cost_unit="currency/m2"> 800 </investment_cost>
<reposition cost_unit="currency/m2"> 800 </reposition> <reposition cost_unit="currency/m2"> 800 </reposition>
<lifetime_equipment lifetime="years"> 25 </lifetime_equipment> <lifetime_equipment lifetime="years"> 25 </lifetime_equipment>
</D301010_photovoltaic_system> </D301010_photovoltaic_system>
@ -142,7 +140,7 @@
<lifetime_equipment lifetime="years"> 15 </lifetime_equipment> <lifetime_equipment lifetime="years"> 15 </lifetime_equipment>
</D3030_cooling_generation_systems> </D3030_cooling_generation_systems>
<D3040_distribution_systems> <D3040_distribution_systems>
<refurbishment_cost cost_unit="currency/m2"> 0 </refurbishment_cost> <investment_cost cost_unit="currency/m2"> 0 </investment_cost>
<reposition cost_unit="currency/kW"> 0 </reposition> <reposition cost_unit="currency/kW"> 0 </reposition>
<lifetime_equipment lifetime="years"> 15 </lifetime_equipment> <lifetime_equipment lifetime="years"> 15 </lifetime_equipment>
</D3040_distribution_systems> </D3040_distribution_systems>
@ -154,7 +152,7 @@
</D30_hvac> </D30_hvac>
<D50_electrical> <D50_electrical>
<D5020_lighting_and_branch_wiring> <D5020_lighting_and_branch_wiring>
<refurbishment_cost cost_unit="currency/kW"> 139 </refurbishment_cost> <investment_cost cost_unit="currency/kW"> 139 </investment_cost>
<reposition cost_unit="currency/kW"> 139 </reposition> <reposition cost_unit="currency/kW"> 139 </reposition>
<lifetime_equipment lifetime="years"> 20 </lifetime_equipment> <lifetime_equipment lifetime="years"> 20 </lifetime_equipment>
</D5020_lighting_and_branch_wiring> </D5020_lighting_and_branch_wiring>
@ -166,6 +164,7 @@
</Z_allowances_overhead_profit> </Z_allowances_overhead_profit>
</capital_cost> </capital_cost>
<operational_cost> <operational_cost>
<fuels>
<fuel fuel_type="electricity"> <fuel fuel_type="electricity">
<fixed_monthly cost_unit="currency/month"> 12.27 </fixed_monthly> <fixed_monthly cost_unit="currency/month"> 12.27 </fixed_monthly>
<fixed_power cost_unit="currency/(month*kW)"> 0 </fixed_power> <fixed_power cost_unit="currency/(month*kW)"> 0 </fixed_power>
@ -181,23 +180,22 @@
<fuel fuel_type="biomass"> <fuel fuel_type="biomass">
<variable cost_unit="currency/kg"> 0.09 </variable> <variable cost_unit="currency/kg"> 0.09 </variable>
</fuel> </fuel>
<maintenances> </fuels>
<maintenance type="heating_equipment" cost_unit="currency/kW">40</maintenance> <maintenance>
<maintenance type="cooling_equipment" cost_unit="currency/kW">40</maintenance> <heating_equipment cost_unit="currency/kW">40</heating_equipment>
<maintenance type="photovoltaic_system" cost_unit="currency/m2">1</maintenance> <cooling_equipment cost_unit="currency/kW">40</cooling_equipment>
</maintenances> <photovoltaic_system cost_unit="currency/m2">1</photovoltaic_system>
<CO2_cost cost_unit="currency/kgCO2"> 30 </CO2_cost> </maintenance>
<co2_cost cost_unit="currency/kgCO2"> 30 </co2_cost>
</operational_cost> </operational_cost>
<end_of_life_cost cost_unit="currency/m2"> 6.3 </end_of_life_cost> <end_of_life_cost cost_unit="currency/m2"> 6.3 </end_of_life_cost>
<incomes> <incomes>
<subsidies> <subsidies>
<subsidy type="construction" cost_unit="%">2</subsidy> <construction cost_unit="%">2</construction>
<subsidy type="hvac" cost_unit="%">1.5</subsidy> <hvac cost_unit="%">1.5</hvac>
<subsidy type="photovoltaic" cost_unit="%">3.6</subsidy> <photovoltaic cost_unit="%">3.6</photovoltaic>
</subsidies> </subsidies>
<energy_exports> <electricity_export cost_unit="currency/kWh">0</electricity_export>
<energy_export type="electricity" cost_unit="currency/kWh">0</energy_export>
</energy_exports>
<tax_reduction cost_unit="%">2</tax_reduction> <tax_reduction cost_unit="%">2</tax_reduction>
</incomes> </incomes>
</archetype> </archetype>

View File

@ -131,4 +131,26 @@ class EpwWeatherParameters:
if cte.YEAR not in building.cold_water_temperature: if cte.YEAR not in building.cold_water_temperature:
building.cold_water_temperature[cte.YEAR] = wh().get_yearly_mean_values( building.cold_water_temperature[cte.YEAR] = wh().get_yearly_mean_values(
building.cold_water_temperature[cte.HOUR][['epw']]) building.cold_water_temperature[cte.HOUR][['epw']])
# If the usage has already being imported, the domestic hot water missing values must be calculated here that
# the cold water temperature is finally known
cold_temperature = building.cold_water_temperature[cte.YEAR]['epw']
for internal_zone in building.internal_zones:
if internal_zone.usages is not None:
for usage in internal_zone.usages:
if usage.domestic_hot_water.peak_flow is None:
if usage.domestic_hot_water.density is None:
continue
peak_flow = 0
if (usage.domestic_hot_water.service_temperature - cold_temperature) > 0:
peak_flow = usage.domestic_hot_water.density / cte.WATER_DENSITY / cte.WATER_HEAT_CAPACITY \
/ (usage.domestic_hot_water.service_temperature - cold_temperature)
usage.domestic_hot_water.peak_flow = peak_flow
if usage.domestic_hot_water.density is None:
if usage.domestic_hot_water.peak_flow is None:
continue
density = usage.domestic_hot_water.peak_flow * cte.WATER_DENSITY * cte.WATER_HEAT_CAPACITY \
* (usage.domestic_hot_water.service_temperature - cold_temperature)
usage.domestic_hot_water.density = density
self._city.level_of_detail.weather = 2 self._city.level_of_detail.weather = 2

View File

@ -17,7 +17,7 @@ class TestCostsCatalog(TestCase):
catalog_categories = catalog.names() catalog_categories = catalog.names()
self.assertIsNotNone(catalog, 'catalog is none') self.assertIsNotNone(catalog, 'catalog is none')
content = catalog.entries() content = catalog.entries()
self.assertTrue(len(content.archetypes) == 1) self.assertTrue(len(content.archetypes) == 2)
# retrieving all the entries should not raise any exceptions # retrieving all the entries should not raise any exceptions
for category in catalog_categories: for category in catalog_categories: