From d3b524b6778012b1ba48db14a799e0124a7332b3 Mon Sep 17 00:00:00 2001 From: jgavalda Date: Wed, 7 Jun 2023 20:33:33 -0400 Subject: [PATCH] Incorporated co2 in costs workflow. Constants initialised in init, and calculations done in __main__emissions.py --- costs/__init__.py | 9 +++++ costs/__main__.py | 3 ++ costs/__main__emissions.py | 68 ++++++++++++++++++++++++++++++++++++++ costs/life_cycle_costs.py | 1 + 4 files changed, 81 insertions(+) create mode 100644 costs/__main__emissions.py diff --git a/costs/__init__.py b/costs/__init__.py index f92f26b..9425e48 100644 --- a/costs/__init__.py +++ b/costs/__init__.py @@ -36,6 +36,15 @@ RETROFITTING_SCENARIOS = [ SYSTEM_RETROFIT_AND_PV, SKIN_RETROFIT_AND_SYSTEM_RETROFIT_AND_PV ] + +EMISSION_FACTOR_GAS_QUEBEC = 0.25 +EMISSION_FACTOR_ELECTRICITY_QUEBEC = 0.0015 #https://www.cer-rec.gc.ca/en/data-analysis/energy-markets/provincial-territorial-energy-profiles/provincial-territorial-energy-profiles-quebec.html#:~:text=GHG%20Emissions,-Quebec's%20GHG%20emissions&text=The%20largest%20emitting%20sectors%20in,2.3%20MT%20CO2e. +EMISSION_FACTOR_GAS_QUEBEC = 0.183 #https://www.canada.ca/en/environment-climate-change/services/climate-change/pricing-pollution-how-it-will-work/output-based-pricing-system/federal-greenhouse-gas-offset-system/emission-factors-reference-values.html +EMISSION_FACTOR_BIOMASS_QUEBEC = 0.035 #Data from Spain. https://www.miteco.gob.es/es/cambio-climatico/temas/mitigacion-politicas-y-medidas/factoresemision_tcm30-479095.pdf +EMISSION_FACTOR_FUEL_OIL_QUEBEC = 0.274 +EMISSION_FACTOR_DIESEL_QUEBEC = 0.240 + + tmp_folder = Path('./tmp').resolve() out_path = Path('./outputs').resolve() files = glob.glob(f'{out_path}/*') diff --git a/costs/__main__.py b/costs/__main__.py index e76efab..2a78c41 100644 --- a/costs/__main__.py +++ b/costs/__main__.py @@ -29,6 +29,9 @@ from costs import CONSUMER_PRICE_INDEX, ELECTRICITY_PEAK_INDEX, ELECTRICITY_PRIC from costs import SKIN_RETROFIT, SYSTEM_RETROFIT_AND_PV, SKIN_RETROFIT_AND_SYSTEM_RETROFIT_AND_PV from costs import RETROFITTING_YEAR_CONSTRUCTION +from costs import EMISSION_FACTOR_GAS_QUEBEC, EMISSION_FACTOR_ELECTRICITY_QUEBEC, EMISSION_FACTOR_GAS_QUEBEC,\ + EMISSION_FACTOR_BIOMASS_QUEBEC, EMISSION_FACTOR_FUEL_OIL_QUEBEC, EMISSION_FACTOR_DIESEL_QUEBEC + # import paths from costs import file_path, tmp_folder, out_path diff --git a/costs/__main__emissions.py b/costs/__main__emissions.py new file mode 100644 index 0000000..6f1b507 --- /dev/null +++ b/costs/__main__emissions.py @@ -0,0 +1,68 @@ +""" +Costs Workflow +SPDX - License - Identifier: LGPL - 3.0 - or -later +Copyright © 2022 Project Author Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca +Code contributor Oriol Gavalda Torrellas oriol.gavalda@concordia.ca +""" + +from pathlib import Path + +import pandas as pd +from hub.helpers.dictionaries import Dictionaries +from hub.catalog_factories.costs_catalog_factory import CostCatalogFactory + +from costs import EMISSION_FACTOR_ELECTRICITY_QUEBEC, EMISSION_FACTOR_GAS_QUEBEC, EMISSION_FACTOR_BIOMASS_QUEBEC, \ + EMISSION_FACTOR_FUEL_OIL_QUEBEC, EMISSION_FACTOR_DIESEL_QUEBEC, NUMBER_OF_YEARS + +def _search_archetype(costs_catalog, building_function): + costs_archetypes = costs_catalog.entries('archetypes').archetypes + for building_archetype in costs_archetypes: + if str(building_function) == str(building_archetype.function): + return building_archetype + raise KeyError('archetype not found') + +catalog = CostCatalogFactory('montreal_custom').catalog + +for building in city.buildings: + building_heating_consumption = 1000 + building_domestic_water_consumption = 1000 + building_cooling_consumption = 1000 + distribution_systems_electrical_consumption = 1000 + lighting_electrical_demand = 1000 + appliances_electrical_demand = 1000 + rng = range(NUMBER_OF_YEARS) + + function = Dictionaries().hub_function_to_montreal_custom_costs_function[building.function] + archetype = _search_archetype(catalog, function) + + print('co2 for first building started') + if "gas" in building.energy_systems_archetype_name: + gas_consumption = building_heating_consumption + building_domestic_water_consumption + electricity_consumption = building_cooling_consumption + distribution_systems_electrical_consumption + \ + lighting_electrical_demand + appliances_electrical_demand + biomass_consumption = 0 + fuel_oil_consumption = 0 + diesel_consumption = 0 + else: + gas_consumption = 0 + electricity_consumption = building_heating_consumption + building_domestic_water_consumption + \ + building_cooling_consumption + distribution_systems_electrical_consumption + \ + lighting_electrical_demand + appliances_electrical_demand + biomass_consumption = 0 + fuel_oil_consumption = 0 + diesel_consumption = 0 + + CO2_emissions = pd.DataFrame(index=rng, columns=['CO2 emissions gas', 'CO2 emissions electricity', + 'CO2 Emissions biomass', 'CO2 emissions fueloil', + 'CO2 emissions diesel'], dtype='float') + + for year in range(1, NUMBER_OF_YEARS+1): + + CO2_emissions.at[year,'CO2 emissions gas'] = gas_consumption * EMISSION_FACTOR_GAS_QUEBEC + CO2_emissions.at[year, 'CO2 emissions electricity'] = electricity_consumption * EMISSION_FACTOR_ELECTRICITY_QUEBEC + CO2_emissions.at[year, 'CO2 emissions biomass'] = biomass_consumption * EMISSION_FACTOR_BIOMASS_QUEBEC + CO2_emissions.at[year, 'CO2 emissions fueloil'] = fuel_oil_consumption * EMISSION_FACTOR_FUEL_OIL_QUEBEC + CO2_emissions.at[year, 'CO2 emissions diesel'] = diesel_consumption * EMISSION_FACTOR_DIESEL_QUEBEC + + CO2_emissions_total = CO2_emissions.sum() + diff --git a/costs/life_cycle_costs.py b/costs/life_cycle_costs.py index 7fc3974..e2d845f 100644 --- a/costs/life_cycle_costs.py +++ b/costs/life_cycle_costs.py @@ -280,6 +280,7 @@ class LifeCycleCosts: electricity_heating + electricity_cooling + electricity_lighting + domestic_hot_water_electricity + electricity_plug_loads + electricity_distribution ) + print(f'electricity consumption {total_electricity_consumption}') # todo: change when peak electricity demand is coded. Careful with factor residential peak_electricity_demand = 100 # self._peak_electricity_demand