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

Revision history [back]

Creating workflow.osw file in Python

 Anyone have any tips for creating workflow.osw files programmatically in Python?

I have tried the following, but running into various issues:

  1. I used this [Notebook](https://github.com/NREL/docker-openstudio-jupyter/blob/945b6f00b97ebd2a7f11b9f125b6c03f03159a0f/osw_project/BaselineModel.ipynb#L4) for inspiration, but am running into an issue with the following script, with the resulting .osw file being blank. I believe the issue is caused by using **.append()**, but am not 100% sure:
measure_steps=[]
os_results = openstudio.MeasureStep("measures/AddMonthlyJSONUtilityData")
os_results.setArgument("json", "../../../data/electric.json")
os_results.setArgument("variable_name", "Electricity Bill")
os_results.setArgument("set_runperiod", True)
measure_steps.append(os_results)
'# Set the measure steps in the OSW object
measureType = openstudio.MeasureType('ModelMeasure')
osw.setMeasureSteps(measureType,measure_steps)
print(osw)
{
  "created_at" : "20240416T135449Z",
  "steps" : []
}
  1. I then used some of the script from this open issue in [Github](https://github.com/NREL/OpenStudio/issues/2795#issuecomment-332346032) which somewhat works. The osw file results in the arguments, but I had to adjust the setWorkflowSteps() to only include the measure steps because the function only takes one argument. This makes me concerned that I am not defining the MeasureType there may be another issue further down the line.
wf = openstudio.WorkflowJSON()
measure = openstudio.MeasureStep('Measure1')
measure.setArgument('r_value', '45')
stepVector = openstudio.WorkflowStepVector([measure])
measureType=openstudio.MeasureType("ModelMeasure")
wf.setWorkflowSteps(stepVector)
print(wf)
{
  "created_at" : "20240416T155242Z",
  "steps" : 
  [
     {
        "arguments" : 
        {
           "r_value" : "45"
        },
        "measure_dir_name" : "Measure1"
     }
  ],
  "updated_at" : "20240416T155242Z"
}

Creating workflow.osw file in Python

 Anyone have any tips for creating workflow.osw files programmatically in Python?

I have tried the following, but running into various issues:

  1. I used this [Notebook](https://github.com/NREL/docker-openstudio-jupyter/blob/945b6f00b97ebd2a7f11b9f125b6c03f03159a0f/osw_project/BaselineModel.ipynb#L4) for inspiration, but am running into an issue with the following script, with the resulting .osw file being blank. I believe the issue is caused by using **.append()**, but am not 100% sure:
measure_steps=[]
os_results = openstudio.MeasureStep("measures/AddMonthlyJSONUtilityData")
os_results.setArgument("json", "../../../data/electric.json")
os_results.setArgument("variable_name", "Electricity Bill")
os_results.setArgument("set_runperiod", True)
measure_steps.append(os_results)
'# Set the measure steps in the OSW object
measureType = openstudio.MeasureType('ModelMeasure')
osw.setMeasureSteps(measureType,measure_steps)
print(osw)
{
  "created_at" : "20240416T135449Z",
  "steps" : []
}
  1. I then used some of the script from this open issue in [Github](https://github.com/NREL/OpenStudio/issues/2795#issuecomment-332346032) which somewhat works. The osw file results in the arguments, but I had to adjust the setWorkflowSteps() to only include the measure steps because the function only takes one argument. This makes me concerned that I am not defining the MeasureType there may be another issue further down the line.
wf = openstudio.WorkflowJSON()
measure = openstudio.MeasureStep('Measure1')
measure.setArgument('r_value', '45')
stepVector = openstudio.WorkflowStepVector([measure])
measureType=openstudio.MeasureType("ModelMeasure")
wf.setWorkflowSteps(stepVector)
print(wf)
{
  "created_at" : "20240416T155242Z",
  "steps" : 
  [
     {
        "arguments" : 
        {
           "r_value" : "45"
        },
        "measure_dir_name" : "Measure1"
     }
  ],
  "updated_at" : "20240416T155242Z"
}

Creating workflow.osw file in Python

 Anyone Anyone have any tips for creating workflow.osw files programmatically in Python?

Python? I have tried the following, but running into various issues:

  1. I used this [Notebook](https://github.com/NREL/docker-openstudio-jupyter/blob/945b6f00b97ebd2a7f11b9f125b6c03f03159a0f/osw_project/BaselineModel.ipynb#L4) Notebook for inspiration, but am running into an issue with the following script, with the resulting .osw file being blank. I believe the issue is caused by using **.append()**, .append(), but am not 100% sure:
measure_steps=[]
os_results = openstudio.MeasureStep("measures/AddMonthlyJSONUtilityData")
os_results.setArgument("json", "../../../data/electric.json")
os_results.setArgument("variable_name", "Electricity Bill")
os_results.setArgument("set_runperiod", True)
measure_steps.append(os_results)
'# Set the measure steps in the OSW object
measureType = openstudio.MeasureType('ModelMeasure')
osw.setMeasureSteps(measureType,measure_steps)
print(osw)
{
  "created_at" : "20240416T135449Z",
  "steps" : []
}
  1. I then used some of the script from this open issue in [Github](https://github.com/NREL/OpenStudio/issues/2795#issuecomment-332346032) Github which somewhat works. The osw file results in the arguments, but I had to adjust the setWorkflowSteps() to only include the measure steps because the function only takes one argument. This makes me concerned that I am not defining the MeasureType there may be another issue further down the line.line.
wf = openstudio.WorkflowJSON()
measure = openstudio.MeasureStep('Measure1')
measure.setArgument('r_value', '45')
stepVector = openstudio.WorkflowStepVector([measure])
measureType=openstudio.MeasureType("ModelMeasure")
wf.setWorkflowSteps(stepVector)
print(wf)
{
  "created_at" : "20240416T155242Z",
  "steps" : 
  [
     {
        "arguments" : 
        {
           "r_value" : "45"
        },
        "measure_dir_name" : "Measure1"
     }
  ],
  "updated_at" : "20240416T155242Z"
}

Creating workflow.osw file in Python

Anyone have any tips for creating workflow.osw files programmatically in Python? I have tried the following, but running into various issues:

  1. 1) I used this Notebook for inspiration, but am running into an issue with the following script, with the resulting .osw file being blank. I believe the issue is caused by using .append(), but am not 100% sure:

measure_steps=[]
os_results = openstudio.MeasureStep("measures/AddMonthlyJSONUtilityData")
os_results.setArgument("json", "../../../data/electric.json")
os_results.setArgument("variable_name", "Electricity Bill")
os_results.setArgument("set_runperiod", True)
measure_steps.append(os_results)
'# Set the measure steps in the OSW object
measureType = openstudio.MeasureType('ModelMeasure')
osw.setMeasureSteps(measureType,measure_steps)
print(osw)
{
  "created_at" : "20240416T135449Z",
  "steps" : []
}
  1. 2) I then used some of the script from this open issue in Github which somewhat works. The osw file results in the arguments, but I had to adjust the setWorkflowSteps() to only include the measure steps because the function only takes one argument. This makes me concerned that I am not defining the MeasureType there may be another issue further down the line.

wf = openstudio.WorkflowJSON()
measure = openstudio.MeasureStep('Measure1')
measure.setArgument('r_value', '45')
stepVector = openstudio.WorkflowStepVector([measure])
measureType=openstudio.MeasureType("ModelMeasure")
wf.setWorkflowSteps(stepVector)
print(wf)
{
  "created_at" : "20240416T155242Z",
  "steps" : 
  [
     {
        "arguments" : 
        {
           "r_value" : "45"
        },
        "measure_dir_name" : "Measure1"
     }
  ],
  "updated_at" : "20240416T155242Z"
}