Several todos added

This commit is contained in:
Guille 2024-02-06 05:11:26 +01:00
parent 844a2241a6
commit fa18c0445a
2 changed files with 30 additions and 19 deletions

View File

@ -15,25 +15,18 @@ try:
energy_systems_format = 'montreal_custom' energy_systems_format = 'montreal_custom'
out_path = (Path(__file__).parent / 'output_files') out_path = (Path(__file__).parent / 'output_files')
tmp_folder = (Path(__file__).parent / 'tmp')
print('[simulation start]')
city = GeometryFactory('geojson', city = GeometryFactory('geojson',
path=file_path, path=file_path,
height_field='citygml_me', height_field='citygml_me',
year_of_construction_field='ANNEE_CONS', year_of_construction_field='ANNEE_CONS',
function_field='CODE_UTILI', function_field='CODE_UTILI',
function_to_hub=Dictionaries().montreal_function_to_hub_function).city function_to_hub=Dictionaries().montreal_function_to_hub_function).city
print(f'city created from {file_path}')
ConstructionFactory(construction_format, city).enrich() ConstructionFactory(construction_format, city).enrich()
print('enrich constructions... done')
UsageFactory(usage_format, city).enrich() UsageFactory(usage_format, city).enrich()
print('enrich usage... done')
MatSimEngine(city, 'output_files') MatSimEngine(city, 'output_files')
# visualizer = MatSimVisualizer('output/output_network.xml.gz', 'output/output_events.xml.gz') # visualizer = MatSimVisualizer('output_files/network.xml.gz', 'output_files/output_events.xml.gz')
# visualizer.visualize() # visualizer.visualize()
except Exception as ex: except Exception as ex:

View File

@ -1,3 +1,4 @@
import math
import subprocess import subprocess
import xmltodict import xmltodict
@ -7,6 +8,9 @@ from shapely.geometry import Point
from matsim_activity_to_matsim_schedule import MatsimActivityToMatsimSchedule from matsim_activity_to_matsim_schedule import MatsimActivityToMatsimSchedule
from hub_function_to_matsim_activity import HubFunctionToMatsimActivity from hub_function_to_matsim_activity import HubFunctionToMatsimActivity
# TODO: Please check this https://github.com/matsim-org/matsim-code-examples/issues/63 for the CRS in matsim should match the city
class MatSimEngine: class MatSimEngine:
def __init__(self, city, output_file_path): def __init__(self, city, output_file_path):
self._city = city self._city = city
@ -29,18 +33,15 @@ class MatSimEngine:
# 1- Facilities # 1- Facilities
# TODO: Add the ability for a building to have multiple activities # TODO: Add the ability for a building to have multiple activities
# TODO: this should come from the factories, please check idf generation
for building in city.buildings: for building in city.buildings:
activity = hub_function_to_matsim.dictionary[building.function].split(',') activity = hub_function_to_matsim.dictionary[building.function].split(',')
schedule = matsim_schedule.dictionary[activity[0]] schedule = matsim_schedule.dictionary[activity[0]]
start_time, end_time = schedule.split('-') start_time, end_time = schedule.split('-')
new_id = 0 for surface in building.grounds:
# TODO: building.grounds (TBD)
for surface in building.surfaces:
for coord in surface.solid_polygon.coordinates: for coord in surface.solid_polygon.coordinates:
new_id += 1 buildings_shape_data['id'].append(f"{building.name}")
buildings_shape_data['id'].append(f"{new_id}_building.name")
buildings_shape_data['geometry'].append(Point(coord[0], coord[1])) buildings_shape_data['geometry'].append(Point(coord[0], coord[1]))
facility = { facility = {
@ -49,11 +50,22 @@ class MatSimEngine:
'@y': str(building.centroid[1]), '@y': str(building.centroid[1]),
'activity': [] 'activity': []
} }
if len(building.thermal_zones_from_internal_zones) > 1:
raise NotImplementedError("multi-zone buildings aren't yet supported")
for thermal_zone in building.thermal_zones_from_internal_zones:
capacity = thermal_zone.occupancy.occupancy_density * building.floor_area * building.storeys_above_ground
for schedule in thermal_zone.occupancy.occupancy_schedules:
print(schedule.values) # TODO: use this schedules values to generate more accurate opentimes.
# TODO: check http://www.matsim.org/files/dtd/facilities_v1.dtd seems to be missing values here
for new_activity in activity: for new_activity in activity:
facility['activity'].append({ facility['activity'].append({
'@type': new_activity, '@type': new_activity,
'capacity': { 'capacity': {
'@value': '4.0' # TODO: Replace with a proper value taken from function '@value': math.ceil(capacity)
}, },
'opentime': { 'opentime': {
'@day': 'wkday', '@day': 'wkday',
@ -66,7 +78,7 @@ class MatSimEngine:
gdf = gpd.GeoDataFrame( gdf = gpd.GeoDataFrame(
buildings_shape_data, buildings_shape_data,
crs="EPSG:26911" crs=city.srs_name
) )
gdf.to_file("input_files/buildings_shapefile.shp") gdf.to_file("input_files/buildings_shapefile.shp")
@ -75,14 +87,20 @@ class MatSimEngine:
xml_content = xmltodict.unparse(facilities_dict, pretty=True) xml_content = xmltodict.unparse(facilities_dict, pretty=True)
# Write the XML to the file # Write the XML to the file
with open(f"{output_file_path}/montreal_facilities.xml", 'w') as file: with open(f"{output_file_path}/{city.name}_facilities.xml", 'w') as file:
file.write(xml_content) file.write(xml_content)
# 2- Network # 2- Network
# First get only the part of the network necessary for the simulation # First get only the part of the network necessary for the simulation
java_path = "java" java_path = "java"
jar_path = "matsim-network-from-osm.jar" jar_path = "matsim-network-from-osm.jar"
command = [java_path, "-jar", jar_path, "input_files/merged-network.osm.pbf", "input_files/buildings_shapefile.shp", f"{output_file_path}/network.xml.gz"] command = [
java_path,
"-jar", jar_path,
"input_files/merged-network.osm.pbf",
"input_files/buildings_shapefile.shp",
f"{output_file_path}/network.xml.gz"
]
subprocess.run(command) subprocess.run(command)
# 3- Population # 3- Population