Question-and-Answer Resource for the Building Energy Modeling Community
Get started with the Help page
Ask Your Question
1

Applying measures in Python workflow and simulating

asked 2023-11-15 19:39:44 -0500

clima337's avatar

updated 2024-02-14 07:57:25 -0500

Hello, I've been able to build out a workflow entirely in Python that loads an .osm file, takes in a measure, finds the right measure (using the NREL Comstock ones https://github.com/NREL/ComStock/tree... ), copy the requisite files over and create a workflow.osw that incorporates the measure steps. This file structure includes building_name/files , building_name/measures and building_name/workflow.osw . That's all working fine. However when I convert the .osm to an .idf and run an E+ simulation, it doesn't incorporate the measures. I realize that the .idf conversion is not capturing what the measures are doing.

I have tried to change that by creating a workflowJson object and setting it to the new .osw file, but it seems to have no effect. Does anyone know if the workflow I'm trying to do is possible?

My pseudo code:

# make a new workflow.osw - there's some magic in this function, but output is a workflow.osw path
outfile = create_workflow_full(bpath, upgrades, weather_path="weather.epw")
# load model
b0 = osm.model.Model.load(bpath).get()
# try to load the workflow
workflow = b0.workflowJSON().load(outfile).get()
# maybe setting it might do something?
b0.setWorkflowJSON(workflow)
v = translator.translateModel(b0)
# convert to IDF, ideally with the measures applied 
v.save(idf_path')
edit retag flag offensive close merge delete

Comments

... not enough space in comment, see sort-of-answer below ...

mattkoch's avatar mattkoch  ( 2024-03-29 17:01:47 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
2

answered 2024-03-29 21:59:28 -0500

updated 2024-04-01 12:56:00 -0500

There is no simple method to run an OpenStudio workflow using the SDK. Rather, you save the workflow to an OSW file:

workflow.setOswPath("foo.osw")
workflow.save()

And then you run it via the CLI:

import subprocess
subprocess.run(["openstudio", "run", "-w", "foo.osw"])

Running the CLI will do everything for you -- apply any model measures, translate the model to IDF, apply any EnergyPlus measures, run the EnergyPlus simulation, and finally apply any reporting measures.

edit flag offensive delete link more
1

answered 2024-03-29 17:00:56 -0500

mattkoch's avatar

FWIW, I have had good success with the following, after "import openstudio" and creating or loading a model.

# Make sure measure path is what it needs to be
  model.workflowJSON().addMeasurePath(absolute_measure_path)

# Check on existing measure steps
  measure_types = ["ModelMeasure","EnergyPlusMeasure","UtilityMeasure","ReportingMeasure"]
  for measure_type in measure_types:
    measure_type = openstudio.MeasureType(measure_type)
    measure_steps = model.workflowJSON().getMeasureSteps(measure_type)
    print(measure_type,measure_steps)

# Define a measure step
  measure_type = openstudio.MeasureType(measure_types[1])
  measure_step = openstudio.MeasureStep(measure_folder) # measure_folder is a sub_folder under absolute_measure_path, containing measure.rb and measure.xml and resources
  measure_step.setDescription("Description")
  measure_step.setModelerDescription("ModelerDescription")

  arguments = {key1:value1,key2:value2,key3:value3} # Whatever the measure arguments need to be
  measure_step.clearArguments()
  for key,value in arguments.items():
    measure_step.setArgument(key,value)

# Add measure step to the workflow and save
  model.workflowJSON().setMeasureSteps(measure_type,[measure_step]) # note that this requires a Python list!
  model.workflowJSON().save()

When you check the workflow.osw file, you should see the new measure step. The measures sub-folder will likely not have any measures under it yet, but when you start OpenStudioApp, under the Measures tab, the new measure step should appear properly.

I realize this does not get you to an .IDF, but it may be a start, plus, you might be able to run the OpenStudio CLI instead?

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Training Workshops

Careers

Question Tools

1 follower

Stats

Asked: 2023-11-15 19:39:44 -0500

Seen: 655 times

Last updated: Apr 01