nrcan_catalog_creator/opaque_surfaces.py

83 lines
3.0 KiB
Python
Raw Normal View History

2023-02-16 08:00:16 -05:00
import configuration as c
import xmltodict
import json
from urllib.request import urlopen
2023-02-21 15:46:22 -05:00
2023-02-22 05:35:30 -05:00
print('start opaque surfaces')
2023-02-16 08:00:16 -05:00
def process_formula(formula, hdd):
formula = formula.replace('( hdd < ', '').replace(') ', '').split(':')
for equation in formula:
values = equation.split('? ')
if len(values) == 2:
if float(values[0]) > hdd:
return float(values[1])
else:
return float(equation)
2023-02-21 15:46:22 -05:00
2023-02-17 06:52:56 -05:00
def create_virtual_no_mass_material(u_value, name, materials, construction):
r_value = 0
for key in construction:
if key != 'virtual_no_mass':
material_thickness = construction[key]
2023-02-21 15:46:22 -05:00
material_conductivity = 0
2023-02-17 06:52:56 -05:00
for material in materials:
if key in material.keys():
material_conductivity = material[key]['conductivity']
2023-02-21 15:46:22 -05:00
if material_conductivity != 0:
r_value += (material_thickness/material_conductivity)
else:
r_value += 0
2023-02-17 06:52:56 -05:00
r_value = 1/u_value - r_value
new_virtual_no_mass_material = {
name: {
"no_mass": True,
"thermal_resistance": r_value
}
}
materials.append(new_virtual_no_mass_material)
2023-02-16 08:00:16 -05:00
with open(c.nrcan_urls, 'r') as f:
urls = xmltodict.parse(f.read(), force_list=['standard'])
base_url_construction = urls['nrcan']['@base_url_construction']
dictionary = {"opaque_surfaces": []}
2023-02-17 06:52:56 -05:00
no_mass_index = 0
materials = c.materials['materials']
2023-02-16 08:00:16 -05:00
for standard in urls['nrcan']['standards_per_period']['standard']:
constructions_location = standard['constructions_location']
url = f'{base_url_construction}/{constructions_location}'
_json = json.loads(urlopen(url).read())
for climate_zone in c.hdd_canadian_climate_zones.keys():
for table in _json['tables']['surface_thermal_transmittance']['table']:
if table['surface'] in c.opaque_surfaces:
u_value = process_formula(table['formula'], c.hdd_canadian_climate_zones[climate_zone])
2023-02-17 06:52:56 -05:00
layers = {}
construction = c.surface_types[table['surface']][c.heavy_light[standard["@period_of_construction"]]]
for key in construction:
if key != 'virtual_no_mass':
layers[key] = construction[key]
else:
material_name = f'virtual_no_mass_{no_mass_index}'
layers[material_name] = 0
no_mass_index += 1
create_virtual_no_mass_material(u_value,material_name, materials, construction)
2023-02-16 08:00:16 -05:00
opaque_surface = {
2023-02-21 15:46:22 -05:00
f'{standard["@period_of_construction"]}_{climate_zone}': {
2023-02-16 08:00:16 -05:00
"period_of_construction": f'{standard["@period_of_construction"]}',
"climate_zone": f'{climate_zone}',
"type": f"{table['boundary_condition']}{table['surface']}",
"u_value": u_value,
2023-02-17 06:52:56 -05:00
"layers": layers
2023-02-16 08:00:16 -05:00
}
}
dictionary['opaque_surfaces'].append(
opaque_surface
)
2023-02-17 06:52:56 -05:00
output_dictionary = {"opaque_surfaces": dictionary['opaque_surfaces'], "materials": materials}
2023-02-16 08:00:16 -05:00
with open(f'{c.output_path}/opaque_surfaces.json', 'w') as f:
json.dump(output_dictionary, f, indent=2)