Skip to content

Commit

Permalink
Merge branch 'master' into release-3.35.1
Browse files Browse the repository at this point in the history
  • Loading branch information
reyery committed Jan 17, 2024
2 parents 3bcf98d + 3ccd91c commit 12c7d7d
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 87 deletions.
15 changes: 9 additions & 6 deletions cea/datamanagement/surroundings_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,15 @@ def geometry_extractor_osm(locator, config):
print("Removing unwanted buildings")
surroundings = erase_no_surrounding_areas(all_surroundings, zone, area_with_buffer)

assert surroundings.shape[0] > 0, 'No buildings were found within range based on buffer parameter.'

# clean attributes of height, name and number of floors
result = clean_attributes(surroundings, buildings_height, buildings_floors, key="CEA")
result = result.to_crs(get_projected_coordinate_system(float(lat), float(lon)))
result = clean_geometries(result)
if not surroundings.shape[0] > 0:
print('No buildings were found within range based on buffer parameter.')
# Create an empty surroundings file
result = gdf(columns=["Name", "height_ag", "floors_ag"], geometry=[], crs=surroundings.crs)
else:
# clean attributes of height, name and number of floors
result = clean_attributes(surroundings, buildings_height, buildings_floors, key="CEA")
result = result.to_crs(get_projected_coordinate_system(float(lat), float(lon)))
result = clean_geometries(result)

# save to shapefile
result.to_file(shapefile_out_path)
Expand Down
4 changes: 0 additions & 4 deletions cea/default.config
Original file line number Diff line number Diff line change
Expand Up @@ -606,10 +606,6 @@ radiation = true
radiation.type = BooleanParameter
radiation.help = True if executing CEA building radiation analysis using Daysim. Ensure radiation analysis results are in place before executing demand-forecasting and solar-potential analysis.

radiation-simplified = false
radiation-simplified.type = BooleanParameter
radiation-simplified.help = True for faster radiation simulations yet reduced accuracy. Consider setting to True for scenarios with more than 1000 buildings.

demand-forecasting = true
demand-forecasting.type = BooleanParameter
demand-forecasting.help = True if executing CEA demand-forecasting. Change default parameters under the respective tool tabs (i.e. building schedules and building energy demand) and Save to Config.
Expand Down
3 changes: 1 addition & 2 deletions cea/interfaces/dashboard/dashboard.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import signal
import webbrowser

from flask import Flask
Expand Down Expand Up @@ -43,7 +42,7 @@ def main(config):
webbrowser.open(url)

print("Press Ctrl+C to stop server")
socketio.run(app, host=config.server.host, port=config.server.port, allow_unsafe_werkzeug=True)
socketio.run(app, host=config.server.host, port=config.server.port)

print("\nserver exited")

Expand Down
34 changes: 4 additions & 30 deletions cea/scripts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -305,54 +305,28 @@ Utilities:
description: dbf => csv (xlsx) => dbf
interfaces: [cli, dashboard]
module: cea.utilities.dbf
parameters: ['general:scenario', 'dbf-tools:input-file', 'dbf-tools:output-path','dbf-tools:output-file-name']
parameters: ['general:scenario', dbf-tools]

- name: shp-to-csv-to-shp
label: SHP to CSV to SHP
description: shp => csv (xlsx) => shp
interfaces: [ cli, dashboard ]
module: cea.utilities.shapefile
parameters: [ 'general:scenario', 'shapefile-tools:input-file', 'shapefile-tools:output-file-name',
'shapefile-tools:output-path', 'shapefile-tools:reference-shapefile', 'shapefile-tools:polygon']
parameters: [ 'general:scenario', shapefile-tools]

- name: sensitivity-analysis-sampler
label: Generate samples for SA
description: Generate samples for sensitivity analysis using Sobol Method
interfaces: [ cli, dashboard ]
module: cea.utilities.sensitivity_analysis_sampler
parameters: [ 'general:scenario',
'sensitivity-analysis-tools:create-scenario-directory',
'sensitivity-analysis-tools:n',
'sensitivity-analysis-tools:having-variable-1',
'sensitivity-analysis-tools:variable-1-lower-bound', 'sensitivity-analysis-tools:variable-1-upper-bound',
'sensitivity-analysis-tools:having-variable-2',
'sensitivity-analysis-tools:variable-2-lower-bound', 'sensitivity-analysis-tools:variable-2-upper-bound',
'sensitivity-analysis-tools:having-variable-3',
'sensitivity-analysis-tools:variable-3-lower-bound', 'sensitivity-analysis-tools:variable-3-upper-bound',
'sensitivity-analysis-tools:having-variable-4',
'sensitivity-analysis-tools:variable-4-lower-bound', 'sensitivity-analysis-tools:variable-4-upper-bound',
'sensitivity-analysis-tools:having-variable-5',
'sensitivity-analysis-tools:variable-5-lower-bound', 'sensitivity-analysis-tools:variable-5-upper-bound'
]
parameters: [ 'general:scenario', sensitivity-analysis-tools]

- name: batch-process-workflow
label: Batch process Workflow (beta)
description: "Batch process the current scenario or all scenarios under this project. Design the CEA workflow below. Change the default settings under the respective tool tabs and Save to Config."
interfaces: [ cli, dashboard ]
module: cea.utilities.batch_process_workflow
parameters: [ 'general:scenario' , 'batch-process-workflow:all-scenarios', 'batch-process-workflow:zone-csv-to-shp', 'batch-process-workflow:typology-csv-to-dbf',
'batch-process-workflow:data-initializer', 'batch-process-workflow:archetypes-mapper',
'batch-process-workflow:weather-helper', 'batch-process-workflow:surroundings-helper',
'batch-process-workflow:terrain-helper', 'batch-process-workflow:streets-helper',
'batch-process-workflow:streets-csv-to-shp',
'batch-process-workflow:radiation',
'batch-process-workflow:radiation-simplified',
'batch-process-workflow:demand-forecasting',
'batch-process-workflow:emissions', 'batch-process-workflow:system-costs',
'batch-process-workflow:solar-potential-pv', 'batch-process-workflow:solar-potential-other', 'batch-process-workflow:shallow-geothermal-potential',
'batch-process-workflow:water-body-potential', 'batch-process-workflow:sewage-heat-potential', 'batch-process-workflow:thermal-network-layout',
'batch-process-workflow:thermal-network-operation', 'batch-process-workflow:optimization'
]
parameters: ['general:scenario', batch-process-workflow]

- name: data-migrator
label: Data migrator
Expand Down
117 changes: 72 additions & 45 deletions cea/utilities/batch_process_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def exec_cea_commands(config, cea_scenario):
streets_helper = config.batch_process_workflow.streets_helper

radiation = config.batch_process_workflow.radiation
radiation_simplified = config.batch_process_workflow.radiation_simplified
demand_forecasting = config.batch_process_workflow.demand_forecasting

emissions = config.batch_process_workflow.emissions
Expand Down Expand Up @@ -72,86 +71,105 @@ def exec_cea_commands(config, cea_scenario):
zone_csv_path = os.path.join(cea_scenario, 'inputs/building-geometry/zone.xlsx')
zone_out_path = os.path.join(cea_scenario, 'inputs/building-geometry')

subprocess.run(['cea', 'shp-to-csv-to-shp', '--scenario', '{cea_scenario}'.format(cea_scenario=cea_scenario),
'--input-file', '{zone_csv_path}'.format(zone_csv_path=zone_csv_path),
subprocess.run(['cea', 'shp-to-csv-to-shp',
'--scenario', cea_scenario,
'--input-file', zone_csv_path,
'--output-file-name', 'zone.shp',
'--output-path', '{zone_out_path}'.format(zone_out_path=zone_out_path),
'--output-path', zone_out_path,
# '--reference-shapefile', '{reference_shapefile_path}'.format(reference_shapefile_path=reference_shapefile_path),
'--polygon', 'true',
], env=my_env)
], env=my_env, check=True, capture_output=True)

if typology_csv_to_dbf:
typology_csv_path = os.path.join(cea_scenario, 'inputs/building-properties/typology.csv')
if not os.path.exists(typology_csv_path):
typology_csv_path = os.path.join(cea_scenario, 'inputs/building-properties/typology.xlsx')
typology_out_path = os.path.join(cea_scenario, 'inputs/building-properties')
subprocess.run(['cea', 'dbf-to-csv-to-dbf', '--scenario', '{cea_scenario}'.format(cea_scenario=cea_scenario),
'--input-file', '{typology_csv_path}'.format(typology_csv_path=typology_csv_path),
subprocess.run(['cea', 'dbf-to-csv-to-dbf', '--scenario', cea_scenario,
'--input-file', typology_csv_path,
'--output-file-name', 'typology.dbf',
'--output-path', '{typology_out_path}'.format(typology_out_path=typology_out_path),
], env=my_env)
'--output-path', typology_out_path,
], env=my_env, check=True, capture_output=True)

if data_initializer:
subprocess.run(['cea', 'data-initializer', '--scenario', '{cea_scenario}'.format(cea_scenario=cea_scenario)], env=my_env)
subprocess.run(['cea', 'data-initializer', '--scenario', cea_scenario], env=my_env, check=True,
capture_output=True)
if archetypes_mapper:
subprocess.run(['cea', 'archetypes-mapper', '--scenario', '{cea_scenario}'.format(cea_scenario=cea_scenario)], env=my_env)
subprocess.run(['cea', 'archetypes-mapper', '--scenario', cea_scenario], env=my_env, check=True,
capture_output=True)
if weather_helper:
subprocess.run(['cea', 'weather-helper', '--scenario', '{cea_scenario}'.format(cea_scenario=cea_scenario)], env=my_env)
subprocess.run(['cea', 'weather-helper', '--scenario', cea_scenario], env=my_env, check=True,
capture_output=True)
if surroundings_helper:
subprocess.run(['cea', 'surroundings-helper', '--scenario', '{cea_scenario}'.format(cea_scenario=cea_scenario)], env=my_env)
subprocess.run(['cea', 'surroundings-helper', '--scenario', cea_scenario], env=my_env, check=True,
capture_output=True)
if terrain_helper:
subprocess.run(['cea', 'terrain-helper', '--scenario', '{cea_scenario}'.format(cea_scenario=cea_scenario)], env=my_env)
subprocess.run(['cea', 'terrain-helper', '--scenario', cea_scenario], env=my_env, check=True,
capture_output=True)
if streets_helper:
subprocess.run(['cea', 'streets-helper', '--scenario', '{cea_scenario}'.format(cea_scenario=cea_scenario)], env=my_env)
subprocess.run(['cea', 'streets-helper', '--scenario', cea_scenario], env=my_env, check=True,
capture_output=True)

if streets_csv_to_shp:
streets_csv_path = os.path.join(cea_scenario, 'inputs/networks/streets.csv')
if not os.path.exists(streets_csv_path):
streets_csv_path = os.path.join(cea_scenario, 'inputs/networks/streets.xlsx')
streets_out_path = os.path.join(cea_scenario, 'inputs/networks')
reference_shapefile_path = os.path.join(cea_scenario, 'inputs/building-geometry/zone.shp')
subprocess.run(['cea', 'shp-to-csv-to-shp', '--scenario', '{cea_scenario}'.format(cea_scenario=cea_scenario),
subprocess.run(['cea', 'shp-to-csv-to-shp', '--scenario', cea_scenario,
'--input-file', '{streets_csv_path}'.format(streets_csv_path=streets_csv_path),
'--output-file-name', 'streets.shp',
'--output-path', '{streets_out_path}'.format(streets_out_path=streets_out_path),
'--reference-shapefile', '{reference_shapefile_path}'.format(reference_shapefile_path=reference_shapefile_path),
'--reference-shapefile',
'{reference_shapefile_path}'.format(reference_shapefile_path=reference_shapefile_path),
'--polygon', 'false',
], env=my_env)
], env=my_env, check=True, capture_output=True)

if radiation and not radiation_simplified:
subprocess.run(['cea', 'radiation', '--scenario', '{cea_scenario}'.format(cea_scenario=cea_scenario)], env=my_env)
if radiation and radiation_simplified:
subprocess.run(['cea', 'radiation-simplified', '--scenario', '{cea_scenario}'.format(cea_scenario=cea_scenario)], env=my_env)
if radiation:
subprocess.run(['cea', 'radiation', '--scenario', cea_scenario], env=my_env, check=True, capture_output=True)
if demand_forecasting:
subprocess.run(['cea', 'schedule-maker', '--scenario', '{cea_scenario}'.format(cea_scenario=cea_scenario)], env=my_env)
subprocess.run(['cea', 'demand', '--scenario', '{cea_scenario}'.format(cea_scenario=cea_scenario)], env=my_env)
subprocess.run(['cea', 'schedule-maker', '--scenario', cea_scenario], env=my_env, check=True,
capture_output=True)
subprocess.run(['cea', 'demand', '--scenario', cea_scenario], env=my_env, check=True, capture_output=True)

if emissions:
subprocess.run(['cea', 'emissions', '--scenario', '{cea_scenario}'.format(cea_scenario=cea_scenario)], env=my_env)
subprocess.run(['cea', 'emissions', '--scenario', cea_scenario], env=my_env, check=True, capture_output=True)
if system_costs:
subprocess.run(['cea', 'system-costs', '--scenario', '{cea_scenario}'.format(cea_scenario=cea_scenario)], env=my_env)
subprocess.run(['cea', 'system-costs', '--scenario', cea_scenario], env=my_env, check=True, capture_output=True)

if solar_pv:
subprocess.run(['cea', 'photovoltaic', '--scenario', '{cea_scenario}'.format(cea_scenario=cea_scenario)], env=my_env)
subprocess.run(['cea', 'photovoltaic', '--scenario', cea_scenario], env=my_env, check=True, capture_output=True)
if solar_other:
subprocess.run(['cea', 'solar-collector', '--type-scpanel', 'FP', '--scenario', '{cea_scenario}'.format(cea_scenario=cea_scenario)], env=my_env)
subprocess.run(['cea', 'solar-collector', '--type-scpanel', 'ET', '--scenario', '{cea_scenario}'.format(cea_scenario=cea_scenario)], env=my_env)
subprocess.run(['cea', 'photovoltaic-thermal', '--type-scpanel', 'FP', '--scenario', '{cea_scenario}'.format(cea_scenario=cea_scenario)], env=my_env)
subprocess.run(['cea', 'photovoltaic-thermal', '--type-scpanel', 'ET', '--scenario', '{cea_scenario}'.format(cea_scenario=cea_scenario)], env=my_env)
subprocess.run(['cea', 'solar-collector', '--type-scpanel', 'FP', '--scenario', cea_scenario],
env=my_env, check=True, capture_output=True)
subprocess.run(['cea', 'solar-collector', '--type-scpanel', 'ET', '--scenario', cea_scenario],
env=my_env, check=True, capture_output=True)
subprocess.run(['cea', 'photovoltaic-thermal', '--type-scpanel', 'FP', '--scenario', cea_scenario],
env=my_env, check=True, capture_output=True)
subprocess.run(['cea', 'photovoltaic-thermal', '--type-scpanel', 'ET', '--scenario', cea_scenario],
env=my_env, check=True, capture_output=True)
if shallow_geothermal:
subprocess.run(['cea', 'shallow-geothermal-potential', '--scenario', '{cea_scenario}'.format(cea_scenario=cea_scenario)], env=my_env)
subprocess.run(['cea', 'shallow-geothermal-potential', '--scenario', cea_scenario], env=my_env, check=True,
capture_output=True)
if water_body:
subprocess.run(['cea', 'water-body-potential', '--scenario', '{cea_scenario}'.format(cea_scenario=cea_scenario)], env=my_env)
subprocess.run(['cea', 'water-body-potential', '--scenario', cea_scenario], env=my_env, check=True,
capture_output=True)
if sewage_heat:
subprocess.run(['cea', 'sewage-potential', '--scenario', '{cea_scenario}'.format(cea_scenario=cea_scenario)], env=my_env)
subprocess.run(['cea', 'sewage-potential', '--scenario', cea_scenario], env=my_env, check=True,
capture_output=True)

if thermal_network_layout:
subprocess.run(['cea', 'network-layout', '--scenario', '{cea_scenario}'.format(cea_scenario=cea_scenario)], env=my_env)
subprocess.run(['cea', 'network-layout', '--scenario', cea_scenario], env=my_env, check=True,
capture_output=True)
if thermal_network_operation:
subprocess.run(['cea', 'thermal-network', '--scenario', '{cea_scenario}'.format(cea_scenario=cea_scenario)], env=my_env)
subprocess.run(['cea', 'thermal-network', '--scenario', cea_scenario], env=my_env, check=True,
capture_output=True)

if optimization:
subprocess.run(['cea', 'decentralized', '--scenario', '{cea_scenario}'.format(cea_scenario=cea_scenario)], env=my_env)
subprocess.run(['cea', 'optimization-new', '--scenario', '{cea_scenario}'.format(cea_scenario=cea_scenario)], env=my_env)
subprocess.run(['cea', 'decentralized', '--scenario', cea_scenario], env=my_env, check=True,
capture_output=True)
subprocess.run(['cea', 'optimization-new', '--scenario', cea_scenario], env=my_env, check=True,
capture_output=True)


def main(config):
Expand All @@ -169,24 +187,33 @@ def main(config):
assert os.path.exists(config.general.project), 'input file not found: %s' % config.project

project_path = config.general.project
scenario_path = config.general.scenario
scenario_name = config.general.scenario_name
project_boolean = config.batch_process_workflow.all_scenarios

# deciding to run all scenarios or the current the scenario only
if project_boolean:
scenarios_list = os.listdir(project_path)
else:
scenarios_list = [scenario_path]
scenarios_list = [scenario_name]

# loop over one or all scenarios under the project
for scenario in scenarios_list:
# Ignore hidden directories
if scenario.startswith('.'):
if scenario.startswith('.') or os.path.isfile(os.path.join(project_path, scenario)):
continue
cea_scenario = os.path.join(project_path, '{scenario}'.format(scenario=scenario))
print('Executing CEA simulations on {cea_scenario}.'.format(cea_scenario=cea_scenario))
# executing CEA commands
exec_cea_commands(config, cea_scenario)

cea_scenario = os.path.join(project_path, scenario)
print(f'Executing CEA simulations on {cea_scenario}.')
try:
# executing CEA commands
exec_cea_commands(config, cea_scenario)
except subprocess.CalledProcessError as e:
print(f"CEA simulation for scenario `{scenario_name}` failed at script: {e.cmd[1]}")
print("Error Message:")
err_msg = e.stderr
if err_msg is not None:
print(err_msg.decode())
raise e

# Print the time used for the entire processing
time_elapsed = time.perf_counter() - t0
Expand Down

0 comments on commit 12c7d7d

Please sign in to comment.