Initial setup of co2_emission repository
This commit is contained in:
parent
73dec8b54e
commit
6410a9d2e5
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
.idea
|
9
cerc_co2_emission.egg-info/PKG-INFO
Normal file
9
cerc_co2_emission.egg-info/PKG-INFO
Normal file
@ -0,0 +1,9 @@
|
||||
Metadata-Version: 2.1
|
||||
Name: cerc-costs
|
||||
Version: 0.1.0.0
|
||||
Summary: CERC costs contains the basic cost calculation per CERC-Hub building
|
||||
Classifier: License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)
|
||||
Classifier: Programming Language :: Python
|
||||
Classifier: Programming Language :: Python :: 3
|
||||
|
||||
CERC costs contains the basic cost calculation per CERC-Hub building
|
20
cerc_co2_emission.egg-info/SOURCES.txt
Normal file
20
cerc_co2_emission.egg-info/SOURCES.txt
Normal file
@ -0,0 +1,20 @@
|
||||
pyproject.toml
|
||||
requirements.txt
|
||||
setup.py
|
||||
cerc_costs.egg-info/PKG-INFO
|
||||
cerc_costs.egg-info/SOURCES.txt
|
||||
cerc_costs.egg-info/dependency_links.txt
|
||||
cerc_costs.egg-info/requires.txt
|
||||
cerc_costs.egg-info/top_level.txt
|
||||
costs/__init__.py
|
||||
costs/__main__.py
|
||||
costs/capital_costs.py
|
||||
costs/configuration.py
|
||||
costs/constants.py
|
||||
costs/cost.py
|
||||
costs/cost_base.py
|
||||
costs/end_of_life_costs.py
|
||||
costs/total_maintenance_costs.py
|
||||
costs/total_operational_costs.py
|
||||
costs/total_operational_incomes.py
|
||||
costs/version.py
|
1
cerc_co2_emission.egg-info/dependency_links.txt
Normal file
1
cerc_co2_emission.egg-info/dependency_links.txt
Normal file
@ -0,0 +1 @@
|
||||
|
4
cerc_co2_emission.egg-info/requires.txt
Normal file
4
cerc_co2_emission.egg-info/requires.txt
Normal file
@ -0,0 +1,4 @@
|
||||
numpy_financial
|
||||
cerc_hub
|
||||
pandas
|
||||
setuptools
|
1
cerc_co2_emission.egg-info/top_level.txt
Normal file
1
cerc_co2_emission.egg-info/top_level.txt
Normal file
@ -0,0 +1 @@
|
||||
costs
|
12
co2_emission/__init__.py
Normal file
12
co2_emission/__init__.py
Normal file
@ -0,0 +1,12 @@
|
||||
"""
|
||||
Cost workflow initialization
|
||||
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
||||
Copyright © 2023 Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
|
||||
Code contributor Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
||||
Code contributor Oriol Gavalda Torrellas oriol.gavalda@concordia.ca
|
||||
"""
|
||||
from .capital_costs import CapitalCosts
|
||||
from .end_of_life_costs import EndOfLifeCosts
|
||||
from .total_maintenance_costs import TotalMaintenanceCosts
|
||||
from .total_operational_costs import TotalOperationalCosts
|
||||
from .total_operational_incomes import TotalOperationalIncomes
|
80
co2_emission/co2_emission.py
Normal file
80
co2_emission/co2_emission.py
Normal file
@ -0,0 +1,80 @@
|
||||
"""
|
||||
CO2 emission module
|
||||
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
||||
Copyright © 2023 Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
||||
"""
|
||||
|
||||
from hub.city_model_structure.building import Building
|
||||
import hub.helpers.constants as cte
|
||||
|
||||
|
||||
class Co2Emission:
|
||||
"""
|
||||
Cost class
|
||||
"""
|
||||
|
||||
def __init__(self, building: Building, emissions_factor=None):
|
||||
if emissions_factor is None:
|
||||
emissions_factor = {cte.GAS: 1,
|
||||
cte.ELECTRICITY: 1,
|
||||
cte.WOOD: 1,
|
||||
cte.DIESEL: 1,
|
||||
cte.RENEWABLE: 0}
|
||||
self._emissions_factor = emissions_factor
|
||||
self._building = building
|
||||
|
||||
@property
|
||||
def building(self) -> Building:
|
||||
"""
|
||||
Get current building.
|
||||
"""
|
||||
return self._building
|
||||
|
||||
@property
|
||||
def operational_co2(self) -> dict:
|
||||
"""
|
||||
Get operational_co2
|
||||
:return: dict
|
||||
"""
|
||||
results = {}
|
||||
for energy_system in self._building.energy_systems:
|
||||
fuel_type = energy_system.generation_system.generic_generation_system.fuel_type
|
||||
for demand_type in energy_system.demand_types:
|
||||
results_by_time_period = {}
|
||||
if str(demand_type).lower() == str(cte.HEATING).lower():
|
||||
for time_period in self._building.heating_consumption:
|
||||
values = []
|
||||
for value in self._building.heating_consumption[time_period]:
|
||||
values.append(value * self._emissions_factor[fuel_type])
|
||||
results_by_time_period[time_period] = values
|
||||
if demand_type == cte.COOLING:
|
||||
for time_period in self._building.cooling_consumption:
|
||||
values = []
|
||||
for value in self._building.cooling_consumption[time_period]:
|
||||
values.append(value * self._emissions_factor[fuel_type])
|
||||
results_by_time_period[time_period] = values
|
||||
if demand_type == cte.DOMESTIC_HOT_WATER:
|
||||
for time_period in self._building.domestic_hot_water_consumption:
|
||||
values = []
|
||||
for value in self._building.domestic_hot_water_consumption[time_period]:
|
||||
values.append(value * self._emissions_factor[fuel_type])
|
||||
results_by_time_period[time_period] = values
|
||||
results[demand_type] = results_by_time_period
|
||||
|
||||
results_by_time_period = {}
|
||||
for time_period in self._building.lighting_electrical_demand:
|
||||
values = []
|
||||
for value in self._building.lighting_electrical_demand[time_period]:
|
||||
values.append(value * self._emissions_factor[cte.ELECTRICITY])
|
||||
results_by_time_period[time_period] = values
|
||||
results[cte.LIGHTING] = results_by_time_period
|
||||
|
||||
results_by_time_period = {}
|
||||
for time_period in self._building.appliances_electrical_demand:
|
||||
values = []
|
||||
for value in self._building.appliances_electrical_demand[time_period]:
|
||||
values.append(value * self._emissions_factor[cte.ELECTRICITY])
|
||||
results_by_time_period[time_period] = values
|
||||
results[cte.APPLIANCES] = results_by_time_period
|
||||
|
||||
return results
|
121
input_files/selected_building_2864.geojson
Normal file
121
input_files/selected_building_2864.geojson
Normal file
@ -0,0 +1,121 @@
|
||||
{
|
||||
"type": "FeatureCollection",
|
||||
"features": [
|
||||
{
|
||||
"type": "Feature",
|
||||
"id": 2864,
|
||||
"geometry": {
|
||||
"type": "Polygon",
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
-73.55628837310991,
|
||||
45.60732526295055
|
||||
],
|
||||
[
|
||||
-73.55628287285629,
|
||||
45.607324262904456
|
||||
],
|
||||
[
|
||||
-73.55609247288925,
|
||||
45.607288563416546
|
||||
],
|
||||
[
|
||||
-73.55607107262188,
|
||||
45.60734486277528
|
||||
],
|
||||
[
|
||||
-73.55612487276466,
|
||||
45.60735496306114
|
||||
],
|
||||
[
|
||||
-73.55609867281544,
|
||||
45.60742366317157
|
||||
],
|
||||
[
|
||||
-73.55624087271804,
|
||||
45.60745026331904
|
||||
],
|
||||
[
|
||||
-73.55628837310991,
|
||||
45.60732526295055
|
||||
]
|
||||
]
|
||||
]
|
||||
},
|
||||
"properties": {
|
||||
"OBJECTID_12_13": 2864,
|
||||
"ID_UEV": "02033771",
|
||||
"CIVIQUE_DE": " 8212",
|
||||
"CIVIQUE_FI": " 8212",
|
||||
"NOM_RUE": "avenue Peterborough (ANJ)",
|
||||
"SUITE_DEBU": " ",
|
||||
"MUNICIPALI": "50",
|
||||
"ETAGE_HORS": 1,
|
||||
"NOMBRE_LOG": 1,
|
||||
"ANNEE_CONS": 1960,
|
||||
"CODE_UTILI": "1000",
|
||||
"LETTRE_DEB": " ",
|
||||
"LETTRE_FIN": " ",
|
||||
"LIBELLE_UT": "Logement",
|
||||
"CATEGORIE_": "R\u00c3\u00a9gulier",
|
||||
"MATRICULE8": "0051-49-2041-2-000-0000",
|
||||
"SUPERFICIE": 450,
|
||||
"SUPERFIC_1": 176,
|
||||
"NO_ARROND_": "REM09",
|
||||
"Shape_Leng": 0.000666191644361,
|
||||
"OBJECTID": 2864,
|
||||
"Join_Count": 1,
|
||||
"TARGET_FID": 2864,
|
||||
"feature_id": "bdd1f0fe-89de-46d2-80dc-87d3636df60a",
|
||||
"md_id": " ",
|
||||
"acqtech": 1360,
|
||||
"acqtech_en": "Lidar",
|
||||
"acqtech_fr": "Lidar",
|
||||
"provider": 461,
|
||||
"provideren": "Municipal",
|
||||
"providerfr": "Municipal",
|
||||
"datemin": "20151124",
|
||||
"datemax": "20151208",
|
||||
"haccmin": 2,
|
||||
"haccmax": 2,
|
||||
"vaccmin": 1,
|
||||
"vaccmax": 1,
|
||||
"heightmin": 1.17,
|
||||
"heightmax": 7.5,
|
||||
"elevmin": 45.48,
|
||||
"elevmax": 45.96,
|
||||
"bldgarea": 193.18,
|
||||
"comment": " ",
|
||||
"OBJECTID_1": 2864,
|
||||
"Shape_Le_1": 0.000666191644361,
|
||||
"Shape_Ar_1": 2.22753099997e-08,
|
||||
"OBJECTID_12": 2864,
|
||||
"Join_Count_1": 1,
|
||||
"TARGET_FID_1": 2863,
|
||||
"g_objectid": "897744",
|
||||
"g_co_mrc": "66023",
|
||||
"g_code_mun": "66023",
|
||||
"g_arrond": "REM09",
|
||||
"g_anrole": "2019",
|
||||
"g_usag_pre": "R\u00c3\u00a9sidentiel",
|
||||
"g_no_lot": "1113400",
|
||||
"g_nb_poly_": "1",
|
||||
"g_utilisat": "1000",
|
||||
"g_nb_logem": "1",
|
||||
"g_nb_locau": " ",
|
||||
"g_descript": "Unit\u00c3\u00a9 d'\u00c3\u00a9valuation",
|
||||
"g_id_provi": "66023005149204120000000",
|
||||
"g_sup_tota": "450.1",
|
||||
"g_geometry": "0.000958907",
|
||||
"g_geomet_1": "5.20226e-008",
|
||||
"g_dat_acqu": "2020-02-12 00:00:00.0000000",
|
||||
"g_dat_char": "2020-02-17 00:00:00.0000000",
|
||||
"Shape_Leng_1": 0.000666191644361,
|
||||
"Shape_Area_1": 2.22753099997e-08,
|
||||
"Shape_Length": 0.0006661919640545334,
|
||||
"Shape_Area": 2.22753099997e-08
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
8
pyproject.toml
Normal file
8
pyproject.toml
Normal file
@ -0,0 +1,8 @@
|
||||
# pyproject.toml
|
||||
|
||||
[build-system]
|
||||
requires = ["setuptools>=61.0.0", "wheel"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
||||
[options.packages.find_namespace]
|
||||
where = "costs"
|
3
requirements.txt
Normal file
3
requirements.txt
Normal file
@ -0,0 +1,3 @@
|
||||
numpy_financial
|
||||
cerc_hub
|
||||
pandas
|
36
setup.py
Normal file
36
setup.py
Normal file
@ -0,0 +1,36 @@
|
||||
import glob
|
||||
import pathlib
|
||||
from distutils.util import convert_path
|
||||
from setuptools import setup
|
||||
|
||||
with pathlib.Path('requirements.txt').open() as r:
|
||||
install_requires = [
|
||||
str(requirement).replace('\n', '')
|
||||
for requirement
|
||||
in r.readlines()
|
||||
]
|
||||
install_requires.append('setuptools')
|
||||
|
||||
main_ns = {}
|
||||
version = convert_path('costs/version.py')
|
||||
with open(version) as f:
|
||||
exec(f.read(), main_ns)
|
||||
|
||||
setup(
|
||||
name='cerc-costs',
|
||||
version=main_ns['__version__'],
|
||||
description="CERC costs contains the basic cost calculation per CERC-Hub building",
|
||||
long_description="CERC costs contains the basic cost calculation per CERC-Hub building",
|
||||
classifiers=[
|
||||
"License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)",
|
||||
"Programming Language :: Python",
|
||||
"Programming Language :: Python :: 3",
|
||||
],
|
||||
include_package_data=True,
|
||||
packages=['costs'],
|
||||
setup_requires=install_requires,
|
||||
install_requires=install_requires,
|
||||
data_files=[
|
||||
('costs', glob.glob('requirements.txt'))
|
||||
]
|
||||
)
|
1
tests/data/test.geojson
Normal file
1
tests/data/test.geojson
Normal file
File diff suppressed because one or more lines are too long
2
tests/output/.gitignore
vendored
Normal file
2
tests/output/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
93
tests/unit_tests.py
Normal file
93
tests/unit_tests.py
Normal file
@ -0,0 +1,93 @@
|
||||
import datetime
|
||||
import glob
|
||||
import os
|
||||
import subprocess
|
||||
import unittest
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from hub.exports.energy_building_exports_factory import EnergyBuildingsExportsFactory
|
||||
from hub.exports.exports_factory import ExportsFactory
|
||||
from hub.imports.construction_factory import ConstructionFactory
|
||||
from hub.imports.energy_systems_factory import EnergySystemsFactory
|
||||
from hub.imports.geometry_factory import GeometryFactory
|
||||
from hub.imports.results_factory import ResultFactory
|
||||
from hub.imports.usage_factory import UsageFactory
|
||||
from hub.helpers.dictionaries import Dictionaries
|
||||
|
||||
from costs.cost import Cost
|
||||
from costs.constants import SKIN_RETROFIT, SKIN_RETROFIT_AND_SYSTEM_RETROFIT_AND_PV, SYSTEM_RETROFIT_AND_PV
|
||||
from costs.co2_emission import Co2Emission
|
||||
|
||||
|
||||
class Initialize:
|
||||
def __init__(self):
|
||||
self._city = None
|
||||
|
||||
@property
|
||||
def city(self):
|
||||
if self._city is None:
|
||||
start = datetime.datetime.now()
|
||||
print('init tests')
|
||||
city_file = (Path(__file__).parent / 'data/test.geojson').resolve()
|
||||
output_path = (Path(__file__).parent / 'output').resolve()
|
||||
city = GeometryFactory('geojson',
|
||||
city_file,
|
||||
height_field='citygml_me',
|
||||
year_of_construction_field='ANNEE_CONS',
|
||||
function_field='CODE_UTILI',
|
||||
function_to_hub=Dictionaries().montreal_function_to_hub_function).city
|
||||
ConstructionFactory('nrcan', city).enrich()
|
||||
UsageFactory('nrcan', city).enrich()
|
||||
ExportsFactory('sra', city, output_path).export()
|
||||
sra_file = str((output_path / f'{city.name}_sra.xml').resolve())
|
||||
subprocess.run(['sra', sra_file], stdout=subprocess.DEVNULL)
|
||||
ResultFactory('sra', city, output_path).enrich()
|
||||
|
||||
for building in city.buildings:
|
||||
building.energy_systems_archetype_name = 'system 1 gas pv'
|
||||
EnergySystemsFactory('montreal_custom', city).enrich()
|
||||
EnergyBuildingsExportsFactory('insel_monthly_energy_balance', city, output_path).export()
|
||||
_insel_files = glob.glob(f'{output_path}/*.insel')
|
||||
for insel_file in _insel_files:
|
||||
subprocess.run(['insel', str(insel_file)], stdout=subprocess.DEVNULL)
|
||||
ResultFactory('insel_monthly_energy_balance', city, output_path).enrich()
|
||||
self._city = city
|
||||
print(f'init completed {datetime.datetime.now() - start}')
|
||||
return self._city
|
||||
|
||||
|
||||
class UnitTests(unittest.TestCase):
|
||||
init = Initialize()
|
||||
|
||||
def test_current_status(self):
|
||||
for building in self.init.city.buildings:
|
||||
result = Cost(building).life_cycle
|
||||
self.assertIsNotNone(result)
|
||||
self.assertEqual(0, result.values[0])
|
||||
|
||||
def test_scenario_1(self):
|
||||
for building in self.init.city.buildings:
|
||||
result = Cost(building, retrofit_scenario=SKIN_RETROFIT).life_cycle
|
||||
self.assertIsNotNone(result)
|
||||
|
||||
def test_scenario_2(self):
|
||||
for building in self.init.city.buildings:
|
||||
result = Cost(building, retrofit_scenario=SYSTEM_RETROFIT_AND_PV).life_cycle
|
||||
self.assertIsNotNone(result)
|
||||
self.assertEqual(0, result.values[0])
|
||||
|
||||
def test_scenario_3(self):
|
||||
for building in self.init.city.buildings:
|
||||
result = Cost(building, retrofit_scenario=SKIN_RETROFIT_AND_SYSTEM_RETROFIT_AND_PV).life_cycle
|
||||
self.assertIsNotNone(result)
|
||||
|
||||
def test_co2_emission(self):
|
||||
for building in self.init.city.buildings:
|
||||
result = Co2Emission(building).operational_co2
|
||||
self.assertIsNotNone(result)
|
||||
|
||||
def tearDown(self):
|
||||
files = glob.glob('output/[!.]*')
|
||||
for file in files:
|
||||
os.unlink(file)
|
Loading…
Reference in New Issue
Block a user