Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
CircularGreenSimCity
CircularGreenSimCity
Compare Revisions
ef7eb0dc977d127aeb3d54eeb2e55e4a5d9e170d...4a031c3e58ff114b11bea00c25339f2759364dbe
Commits (3)
Parse heat demand
· 54fc986f
Eric Duminil
authored
Apr 05, 2024
54fc986f
Trying to run with different window ratios
· f9bcbc05
Eric Duminil
authored
Apr 05, 2024
f9bcbc05
FIXME
· 4a031c3e
Eric Duminil
authored
Apr 05, 2024
4a031c3e
Show whitespace changes
Inline
Side-by-side
python_scripts/run_simstadt_from_python/variable_window_ratio.py
View file @
4a031c3e
from
pathlib
import
Path
import
shutil
from
run_simstadt_workflow
import
find_simstadt
,
check_paths
,
SCRIPT_DIR
,
prepare_workflow
,
run_workflow
from
xml.etree
import
ElementTree
as
et
import
logging
import
pandas
as
pd
import
re
from
run_simstadt_workflow
import
find_simstadt
,
SCRIPT_DIR
,
run_workflow
# logging.getLogger().setLevel(logging.WARN)
SIMSTADT2_GLOB
=
'Desktop/SimStadt2_0.*/'
REPO_PATH
=
Path
.
home
()
/
'git'
/
'simstadt2'
/
'TestRepository'
PROJECT_NAME
=
'Gruenbuehl'
CITYGMLS
=
[
'Gruenbuehl_LOD2_ALKIS_1010
_2buildings
.gml'
]
CITYGMLS
=
[
'Gruenbuehl_LOD2_ALKIS_1010.gml'
]
PROJECT_PATH
=
REPO_PATH
/
f
'
{
PROJECT_NAME
}
.proj'
PARAMS
=
'params.xml'
print
(
find_simstadt
(
SIMSTADT2_GLOB
))
BUILDING_PHYSICS_LIBRARY
=
'GermanBuildingTypologyLibrary_IWU.xml'
WINDOW_RATIOS
=
[
0
,
0.5
,
1
]
TEMPLATE_NAME
=
'99_HeatDemand'
TEMPLATE
=
SCRIPT_DIR
/
'Template'
/
f
'
{
TEMPLATE_NAME
}
.flow'
# Heat demand, with custom BuildingPhysics
template
=
SCRIPT_DIR
/
'Template'
/
f
'
{
TEMPLATE_NAME
}
.flow'
# Heat demand, with custom BuildingPhysics
workflow_path
=
PROJECT_PATH
/
f
'
{
TEMPLATE_NAME
}
.flow'
shutil
.
copytree
(
template
,
workflow_path
,
dirs_exist_ok
=
True
)
print
(
workflow_path
)
physics_processor_step
=
workflow_path
/
'01_Preprocessing.step/02_PhysicsPreprocessor.step'
############# Specify custom lib #########################
custom_library_path
=
physics_processor_step
/
BUILDING_PHYSICS_LIBRARY
physics_processor_params
=
physics_processor_step
/
PARAMS
tree
=
et
.
parse
(
physics_processor_params
)
root
=
tree
.
getroot
()
lib_node
=
root
.
find
(
".//object[@class='de.hft.stuttgart.simstadt2.assessment.PhysicsXmlLib']/void[@property='path']/string"
)
lib_node
.
text
=
str
(
custom_library_path
)
tree
.
write
(
physics_processor_params
)
##########################################################
with
open
(
custom_library_path
)
as
library_file
:
content
=
library_file
.
read
()
for
window_ratio
in
WINDOW_RATIOS
:
WORKFLOW_PATH
=
PROJECT_PATH
/
f
'
{
TEMPLATE_NAME
}
.flow'
#################### Update lib with custom values ############################
shutil
.
copytree
(
TEMPLATE
,
WORKFLOW_PATH
,
dirs_exist_ok
=
True
)
new_content
=
re
.
sub
(
r
"<name>[\w ]+</name>"
,
f
"<name>Custom Physics Library with Window Ratio :
{
window_ratio
}
</name>"
,
content
,
1
)
# FIXME: Use et.parse instead. Because groundSurfaces shouldn't have any WindowRatio
new_content
=
re
.
sub
(
r
"<windowRatio>[\d\.]+</windowRatio>"
,
f
"<windowRatio>
{
window_ratio
}
</windowRatio>"
,
new_content
)
with
open
(
custom_library_path
,
'w'
)
as
library_file
:
library_file
.
write
(
new_content
)
#################################################################################
output_files
=
run_workflow
(
find_simstadt
(
SIMSTADT2_GLOB
),
workflow_path
,
CITYGMLS
)
heat_demand_csv
=
next
(
file
for
file
in
output_files
if
'HEATING.csv'
in
file
.
name
)
################### Parse heat demand ########################
output_files
=
run_workflow
(
find_simstadt
(
SIMSTADT2_GLOB
),
WORKFLOW_PATH
,
CITYGMLS
)
df
=
pd
.
read_csv
(
heat_demand_csv
,
skiprows
=
list
(
range
(
19
))
+
[
20
],
sep
=
';'
,
decimal
=
','
)
print
(
next
(
file
for
file
in
output_files
if
'HEATING.csv'
in
file
.
name
))
heat_demand_MWh
=
df
[
'Yearly Heating demand'
].
sum
()
/
1000
print
(
f
"Window Ratio :
{
window_ratio
*
100
}
%"
)
print
(
f
"Total heat demand :
{
heat_demand_MWh
:.
0
f
}
MWh / a"
)