1

Modifying OSM files in python

I am trying to write a python script to read an OSM file and modify its thermostat setpoints schedules during some peak perids. does anyone know how can I modify thermostat schedules in OpenStudio (OSM) file using python?

Ali-Khosravani's avatar
65
Ali-Khosravani
asked 2023-09-29 15:54:03 -0500
Aaron Boranian's avatar
14.1k
Aaron Boranian
updated 2023-09-29 16:06:00 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

2 Answers

2

pip install openstudio. Make sure you use python 3.7 to 3.10, see the OpenStudio SDK Python Binding Version Compatibility Matrix

Then it's a matter of using the SDK to modify the schedule. Depends which schedule type is used (eg: ScheduleRuleset).

A short example:

In [1]: import openstudio

In [2]: openstudio.openStudioLongVersion()
Out[2]: '3.6.1+bb9481519e'

In [3]: m = openstudio.model.exampleModel()

In [4]: sch_ruleset = m.getScheduleRulesets()[0]
   ...: print(sch_ruleset)
OS:Schedule:Ruleset,
  {759b60e6-ce95-4ff3-8400-2162e0d007be}, !- Handle
  Medium Office Cooling Setpoint Schedule, !- Name
  {1f748523-f5e7-4388-8c2d-3aed545795c2}, !- Schedule Type Limits Name
  {91357986-488a-469e-8dca-cd87a7647e4b}, !- Default Day Schedule Name
  {d651ceae-2f44-465b-9617-554befb57e9b}; !- Summer Design Day Schedule Name

In [5]: sch_day = sch_ruleset.defaultDaySchedule()
   ...: print(sch_day)
OS:Schedule:Day,
  {91357986-488a-469e-8dca-cd87a7647e4b}, !- Handle
  Medium Office Cooling Setpoint All Other Days Schedule, !- Name
  {1f748523-f5e7-4388-8c2d-3aed545795c2}, !- Schedule Type Limits Name
  ,                                       !- Interpolate to Timestep
  24,                                     !- Hour 1
  0,                                      !- Minute 1
  26.7;                                   !- Value Until Time 1

In [6]: sch_day.clearExtensibleGroups()
   ...: sch_day.addValue(openstudio.Time(0, 12, 0), 18)
   ...: sch_day.addValue(openstudio.Time(0, 16, 0), 20)
   ...: sch_day.addValue(openstudio.Time(0, 24, 0), 18)

In [7]: print(sch_day)
OS:Schedule:Day,
  {91357986-488a-469e-8dca-cd87a7647e4b}, !- Handle
  Medium Office Cooling Setpoint All Other Days Schedule, !- Name
  {1f748523-f5e7-4388-8c2d-3aed545795c2}, !- Schedule Type Limits Name
  ,                                       !- Interpolate to Timestep
  12,                                     !- Hour 1
  0,                                      !- Minute 1
  18,                                     !- Value Until Time 1
  16,                                     !- Hour 2
  0,                                      !- Minute 2
  20,                                     !- Value Until Time 2
  24,                                     !- Hour 3
  0,                                      !- Minute 3
  18;                                     !- Value Until Time 3
Julien Marrec's avatar
29.7k
Julien Marrec
answered 2023-10-02 14:44:09 -0500, updated 2023-10-02 14:44:41 -0500
edit flag offensive 0 remove flag delete link

Comments

add a comment see more comments
0

A long time ago i was trying to develop a OSM handler, may be you can try it and modify it to your goals https://github.com/AltamarMx/osm_handler

altamar's avatar
228
altamar
answered 2023-10-01 15:54:09 -0500
edit flag offensive 0 remove flag delete link

Comments

add a comment see more comments