Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(v3.6.2) - EPW processing: Replace opyplus module by epw #450

Merged
merged 8 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions docs/source/pages/environments.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,29 @@ to introduce **noise** to the weather data episode to episode. Then, the paramet
established is a Python dictionary with the EPW column name as key and tuple of three variables (*sigma*, *mu*, and *tau*) whose
as value, defining the nature of that noise. This allows to apply different noise in several aspects of the weather data.

.. note:: The weather data columns or variables names is generated with opyplus WeatherData class,
for more information about the available variables in an EPW file, visit
`Opyplus documentation <https://opyplus.readthedocs.io/en/2.0.7/quickstart/index.html#weather-data-epw-file>`__.
Since Sinergym v3.6.2, the weather data columns or variables names is generated with
`epw module Weather class <https://pypi.org/project/epw/>`__, the list of the
available variable names is the next:

- ``Year``, ``Month``, ``Day``, ``Hour``, ``Minute``,
``Data Source and Uncertainty Flags``, ``Dry Bulb Temperature``,
``Dew Point Temperature``, ``Relative Humidity``,
``Atmospheric Station Pressure``, ``Extraterrestrial Horizontal Radiation``,
``Extraterrestrial Direct Normal Radiation``,
``Horizontal Infrared Radiation Intensity``,
``Global Horizontal Radiation``, ``Direct Normal Radiation``,
``Diffuse Horizontal Radiation``, ``Global Horizontal Illuminance``,
``Direct Normal Illuminance``, ``Diffuse Horizontal Illuminance``,
``Zenith Luminance``, ``Wind Direction``, ``Wind Speed``, ``Total Sky Cover``,
``Opaque Sky Cover (used if Horizontal IR Intensity missing)``,
``Visibility``, ``Ceiling Height``, ``Present Weather Observation``,
``Present Weather Codes``, ``Precipitable Water``, ``Aerosol Optical Depth``,
``Snow Depth``, ``Days Since Last Snowfall``, ``Albedo``,
``Liquid Precipitation Depth``, ``Liquid Precipitation Quantity``

If you are using an older version of Sinergym, the weather data columns or variables names is generated with
*opyplus WeatherData class*, for more information about the available variable names with opyplus, visit
`Opyplus documentation <https://opyplus.readthedocs.io/en/2.0.7/quickstart/index.html#weather-data-epw-file>`__.

.. image:: /_static/ornstein_noise.png
:scale: 80 %
Expand Down
69 changes: 12 additions & 57 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package-mode = true
name = "sinergym"

version = "3.6.1"
version = "3.6.2"
description = "The goal of sinergym is to create an environment following OpenAI Gym interface for wrapping simulation engines for building control using deep reinforcement learning."
license = "MIT"

Expand Down Expand Up @@ -62,7 +62,7 @@ pandas = "^2.2.2"
eppy = "^0.5.63"
tqdm = "^4.66.5"
xlsxwriter = "^3.2.0"
opyplus = "^2.0.7"
epw = "^1.2.dev2"

# Extra dependencies (optional)
pytest = { version = "^8.3.3", optional = true }
Expand Down
23 changes: 9 additions & 14 deletions sinergym/config/modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import numpy as np
from eppy.modeleditor import IDF
from opyplus import WeatherData
from epw.weather import Weather

from sinergym.utils.common import eppy_element_to_dict, get_delta_seconds
from sinergym.utils.constants import (CWD, LOG_MODEL_LEVEL, PKG_DATA_PATH,
Expand All @@ -34,7 +34,7 @@ class ModelJSON(object):
:param config: Dict config with extra configuration which is required to modify building model (may be None).
:param building: Building model (Dictionary extracted from JSON).
:param ddy_model: eppy object with DDY model.
:param weather_data: opyplus WeatherData object with EPW data.
:param weather_data: epw module Weather class instance with EPW data.
:param zone_names: List of the zone names available in the building.
:param schedulers: Information in Dict format about all building schedulers.
:param runperiod: Information in Dict format about runperiod that determine an episode.
Expand Down Expand Up @@ -99,8 +99,9 @@ def __init__(
IDF.setiddname(self._idd)
self.ddy_model = IDF(self._ddy_path)

# Weather data (opyplus object)
self.weather_data = WeatherData.from_epw(self._weather_path)
# Weather data (epw.weather object)
self.weather_data = Weather()
self.weather_data.read(self._weather_path)

# ----------------------------- Other attributes ----------------------------- #

Expand Down Expand Up @@ -309,7 +310,7 @@ def update_weather_path(self) -> None:
self.pkg_data_path, 'weather', random.choice(self.weather_files))
self._ddy_path = self._weather_path.split('.epw')[0] + '.ddy'
self.ddy_model = IDF(self._ddy_path)
self.weather_data = WeatherData.from_epw(self._weather_path)
self.weather_data.read(self._weather_path)
self.logger.info(
'Weather file {} used.'.format(
self._weather_path.split('/')[-1]))
Expand All @@ -332,14 +333,11 @@ def apply_weather_variability(
# Apply variation to EPW if exists
if weather_variability is not None:

# Get dataframe with weather series
df = weather_data_mod.get_weather_series()

T = 1. # Total time.
# All the columns are going to have the same num of rows since they are
# in the same dataframe
# get first column of df
n = df.shape[0]
n = weather_data_mod.dataframe.shape[0]
dt = T / n
# t = np.linspace(0., T, n) # Vector of times.

Expand All @@ -359,10 +357,7 @@ def apply_weather_variability(
sigma_bis * sqrtdt * np.random.randn()

# Add noise
df[variable] += noise

# Save new weather data
weather_data_mod.set_weather_series(df)
weather_data_mod.dataframe[variable] += noise

self.logger.info(
'Weather noise applied in columns: {}'.format(
Expand All @@ -374,7 +369,7 @@ def apply_weather_variability(
filename += '_OU_Noise.epw'

episode_weather_path = self.episode_path + '/' + filename
weather_data_mod.to_epw(episode_weather_path)
weather_data_mod.write(episode_weather_path)

self.logger.debug(
'Saving episode weather path... [{}]'.format(episode_weather_path))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"config_params" : null,

"weather_variability":{
"drybulb": [1.0, 0.0, 0.001]
"Dry Bulb Temperature": [1.0, 0.0, 0.001]
},

"max_ep_data_store_num" : 10,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"config_params" : null,

"weather_variability":{
"drybulb": [1.0, 0.0, 0.001]
"Dry Bulb Temperature": [1.0, 0.0, 0.001]
},

"max_ep_data_store_num" : 10,
Expand Down
2 changes: 1 addition & 1 deletion sinergym/data/default_configuration/5ZoneAutoDXVAV.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"config_params" : null,

"weather_variability":{
"drybulb": [1.0, 0.0, 0.001]
"Dry Bulb Temperature": [1.0, 0.0, 0.001]
},

"max_ep_data_store_num" : 10,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"config_params" : null,

"weather_variability":{
"drybulb": [1.0, 0.0, 0.001]
"Dry Bulb Temperature": [1.0, 0.0, 0.001]
},

"max_ep_data_store_num" : 10,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"config_params" : null,

"weather_variability":{
"drybulb": [1.0, 0.0, 0.001]
"Dry Bulb Temperature": [1.0, 0.0, 0.001]
},

"max_ep_data_store_num" : 10,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"config_params" : null,

"weather_variability":{
"drybulb": [1.0, 0.0, 0.001]
"Dry Bulb Temperature": [1.0, 0.0, 0.001]
},

"max_ep_data_store_num" : 10,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"config_params" : null,

"weather_variability":{
"drybulb": [1.0, 0.0, 0.001]
"Dry Bulb Temperature": [1.0, 0.0, 0.001]
},

"max_ep_data_store_num" : 10,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"config_params" : null,

"weather_variability":{
"drybulb": [1.0, 0.0, 0.001]
"Dry Bulb Temperature": [1.0, 0.0, 0.001]
},

"max_ep_data_store_num" : 10,
Expand Down
15 changes: 0 additions & 15 deletions sinergym/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
from sinergym.utils.logger import TerminalLogger
from sinergym.utils.rewards import *

# from opyplus.epgm.record import Record

logger = TerminalLogger().getLogger(
name='COMMON',
level=LOG_COMMON_LEVEL)
Expand Down Expand Up @@ -413,16 +411,3 @@ def convert_conf_to_env_parameters(
# if np.max(data[column]) > result[column][1]:
# result[column][1] = np.max(data[column])
# return result


# def get_record_keys(record: Record) -> List[str]:
# """Given an opyplus Epm Record (one element from opyplus.epm object) this function returns list of keys (opyplus hasn't got this functionality explicitly)

# Args:
# record (opyplus.Epm.Record): Element from Epm object.

# Returns:
# List[str]: Key list from record.
# """
# return [field.ref for field in
# record._table._dev_descriptor._field_descriptors]
2 changes: 1 addition & 1 deletion sinergym/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.6.1
3.6.2
22 changes: 16 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import pkg_resources
import pytest
from opyplus import WeatherData
from epw.weather import Weather

import sinergym
from sinergym.config.modeling import ModelJSON
Expand Down Expand Up @@ -357,7 +357,11 @@ def env_5zone_stochastic(
variables=VARIABLES_5ZONE,
meters=METERS_5ZONE,
actuators=ACTUATORS_5ZONE,
weather_variability={'drybulb': (1.0, 0.0, 0.001)},
weather_variability={
'Dry Bulb Temperature': (
1.0,
0.0,
0.001)},
reward=LinearReward,
reward_kwargs={
'temperature_variables': ['air_temperature'],
Expand All @@ -370,9 +374,13 @@ def env_5zone_stochastic(
26.0)},
env_name='TESTGYM',
config_params={
'runperiod': (1, 1, 1991, 31, 3, 1991)
}
)
'runperiod': (
1,
1,
1991,
31,
3,
1991)})
return env


Expand Down Expand Up @@ -595,7 +603,9 @@ def building(json_path_5zone):

@ pytest.fixture(scope='function')
def weather_data(weather_path_pittsburgh):
return WeatherData.from_epw(weather_path_pittsburgh)
weather_data = Weather()
weather_data.read(weather_path_pittsburgh)
return weather_data

# ---------------------------------------------------------------------------- #
# Rewards #
Expand Down
2 changes: 1 addition & 1 deletion tests/mock/environment_configurations/5ZoneAutoDXVAV.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"config_params" : null,

"weather_variability":{
"drybulb": [1.0, 0.0, 0.001]
"Dry Bulb Temperature": [1.0, 0.0, 0.001]
},

"max_ep_data_store_num" : 10,
Expand Down
Loading