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

API Python examples of Data Transfer in EnergyPlus

asked 2021-05-04 11:57:36 -0500

cardav gravatar image

Hi everyone. I have been working for a while trying to call Python scripts during a simulation to perform some calculations to then override some actuators. However, I am stuck with some issues. I’ll appreciate your advice and/or examples on these topics:

1) I know certain variables cannot be actuated; however, when I actuated over “Outdoor Relative Humidity” during “begin_zone_timestep_before_set_current_weather” (which theoretically can be actuated), I do not get different results in my simulations. How can I know which variable can be actuated and the specific calling point to perform these tasks?

2) I would like to know if there is a way to save the outputs of the API python functions as part of the output variable or output meter reports. Since the length of the arrays or data frames are unknown, I do not know how to collect the time step generated data while running a callback function.

3) Where can I find an example of how to return variables from a call-back function at a specific calling point to be used with another python function or callback function into a further calling point. In summary, I am having trouble returning values to other functions at different calling points.

Thank you for your advice in advance.

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
0

answered 2021-05-05 11:07:43 -0500

Matt Mitchell gravatar image

Hi, thanks for using these new features and the question.

Re 1): my guess is that you are attempting to set the relhum value via the relhum sensor, not the actuator. Take a look at the following which is starting from the 1ZoneUncontrolled.idf file.

self.outdoor_air_relhum_actuator_handle = self.api.exchange.get_actuator_handle(state,
                                                                   "Weather Data",
                                                                   "Outdoor Relative Humidity",
                                                                   "Environment")
self.api.exchange.set_actuator_value(state, self.outdoor_air_relhum_actuator_handle, new_relhum)

A full example is posted here: https://gist.github.com/mitchute/5a9f...

Re 2): the example posted at the link demonstrates this, but you will need to use a global variable, then set up a new output variable based on that.

Re 3): what's wrong with class member variables? In the examples shipped with EnergyPlus and linked above, you'll see that we use the "self" class member variables all over the place to persist these data and pass them between calling points. If you want to pass data between class instances, you might need to use global variables (gasp) or be clever with how you set up your classes and calling points.

edit flag offensive delete link more
0

answered 2021-05-05 08:57:36 -0500

bonnema gravatar image

1) I think your using the wrong calling point (you're setting a weather variable and then it is being reset from the weather file). Try begin_timestep_before_predictor.

2) This is probably best to show with an example:

In the IDF:

PythonPlugin:Variables,
  Python Variables,                       !- Name
  a01_t_supp_f;                           !- Variable Name 1

PythonPlugin:OutputVariable,
  a01_t_supp_f,                           !- Name
  a01_t_supp_f,                           !- Python Plugin Variable Name
  Averaged,                               !- Type of Data in Variable
  SystemTimestep,                         !- Update Frequency
  ;                                       !- Units

Output:Variable,
  a01_t_supp_f,                           !- Key Value
  PythonPlugin:OutputVariable,            !- Variable Name
  Timestep;                               !- Reporting Frequency

In the Python script:

self.a01_t_supp_f_hndl = self.api.exchange.get_global_handle(state, "a01_t_supp_f")
self.api.exchange.set_global_value(state, self.a01_t_supp_f_hndl, self.a01_t_supp_f)

Read the documentation for PythonPlugin:OutputVariable and Output:Variable for information on update and reporting frequency.

3) This is hard to answer without more detail. I would encourage you to read Section 6 of https://energyplus.net/sites/all/modu... for information on calling points. The E+ examples files (C:\EnergyPlusV9-5-0\ExampleFiles\PythonPlugin*.idf/.py on Windows) will most likely show an example of what you're looking for.

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

 

Question Tools

3 followers

Stats

Asked: 2021-05-04 11:57:36 -0500

Seen: 79 times

Last updated: 18 hours ago