First time here? Check our help page!
4

OpenStudio python bindings

Hello,

I am very new to OpenStudio and I want to integrate the software in a statistical analysis on python. I do not know how to compile and use the python bindings. Can anyone give me a tutorial for it?

Michel's avatar
65
Michel
asked 2021-07-20 15:34:39 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

2 Answers

6

You can install the openstudio python bindings using pip install openstudio.

Then you can test they work:

import openstudio
m = openstudio.model.Model()
print(m)

That results in:

OS:Version,
  {b1c739b0-8af6-4d47-b6a2-96df1d55f3cb}, !- Handle
  3.2.1;                                  !- Version Identifier

You can find more information at https://pypi.org/project/openstudio/

shorowit's avatar
11.8k
shorowit
answered 2021-07-20 22:11:21 -0500, updated 2021-07-20 22:12:59 -0500
edit flag offensive 0 remove flag delete link

Comments

Thank you, it worked

Michel's avatar Michel (2021-07-21 01:58:19 -0500) edit
1

Where is the documentation for all the package functions? I want to use some OpenStudio modifications in my python scripts?

mechyai's avatar mechyai (2021-07-21 11:14:49 -0500) edit

Are you referring to the OpenStudio SDK documentation?

shorowit's avatar shorowit (2021-07-21 11:25:57 -0500) edit
1

Is there a python-specific version of the above SDK documentation that shows us the syntax of how to call the methods? Thanks

wassimj's avatar wassimj (2021-07-26 02:26:50 -0500) edit

The SDK documentation is for all languages (Ruby, C#, Python); I don't know what python-specific documentation would look like.

shorowit's avatar shorowit (2021-07-26 08:30:48 -0500) edit
add a comment see more comments
3

To expand on Scott's point, I've been learning how to use the Python bindings for the last couple of weeks. I've put together a Python Jupyter notebook as I've figured out a few of the things I wanted to do. The notation is a little different from Ruby for a few things, but with some practice, you should start to catch the patterns to the differences. Maybe this will help you in your own work.

Github-load_model_add_ruleset_notebook.ipynb

GFlechas's avatar
247
GFlechas
answered 2022-03-15 14:43:39 -0500
edit flag offensive 0 remove flag delete link

Comments

1

Hi. Are you using the Ruby Documentation and getting this done? I have a Ruby Script that I'm looking to convert to Python. Specifically this (https://github.com/LBNL-ETA/AlphaBuil...). Do you think it's possible to do this? Because openstudio-standards seems to be Ruby only.

asrjy's avatar asrjy (2022-03-17 09:40:16 -0500) edit
1

Yes, I am. It's not a 1 for 1 syntax match-up, but I'm using it as the starting place for object association.

As for openstudio-standards, I think you're correct. However, since they're all ruby scripts, you could still call them from Python's command-line interface as noted in the comment thread here. I think you can use the OS package in python to do those calls. See this link for ideas.

GFlechas's avatar GFlechas (2022-03-17 10:27:57 -0500) edit
1

So for that LBNL project, I think you could rewrite the main workflow script in python using the openstudio python bindings, and then call the openstudio-standards gem as needed as command line scripts. Might be a little slower but it certainly looks possible!

GFlechas's avatar GFlechas (2022-03-17 10:29:34 -0500) edit
1

Yea. I'll try doing that. Having no proper documentation is making the conversion really hard haha. I'll use your notebook as a reference. Thank you.

asrjy's avatar asrjy (2022-03-17 10:44:38 -0500) edit

Could you please elaborate on using openstudio-standards using command line scripts? In the repository, Openstudio Standards was called using Standards.Build which creates a prototype building model. If I were to write a ruby script to do that, how would I send the created prototype object back to python? I'm stuck there. I finished converting the other part of the script to Python.

asrjy's avatar asrjy (2022-03-22 04:43:14 -0500) edit
add a comment see more comments