Skip to content

Commit

Permalink
Merge commit '3c04cc03f17ff545a0a566bb4fcbb69dac4cd4fc' into gh-pages…
Browse files Browse the repository at this point in the history
…-custom

* commit '3c04cc03f17ff545a0a566bb4fcbb69dac4cd4fc':
  Add release notes and contributor entry
  Pin Dockerfile image to `linux/x86_64`
  Update design text and image
  Updated forecasts documentation
  Clean docs
  Reduce size of reference result files
  Updated release notes
  Added unit tests for simulation and forecast across the year
  Extend data_manager get_data reading beyond one year
  • Loading branch information
javiarrobas committed Jan 26, 2024
2 parents 0ce51d5 + 3c04cc0 commit a0682a0
Show file tree
Hide file tree
Showing 15 changed files with 587 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:20.04
FROM --platform=linux/x86_64 ubuntu:20.04

# Install required packages
RUN apt-get update && \
Expand Down
1 change: 1 addition & 0 deletions contributors.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Thank you to all who have provided guidance on the development of this software.
- Robert Lutes, Pacific Northwest National Laboratory
- Kefei Mo, Pacific Northwest National Laboratory
- Erik Paulson, Independent
- Matt Robinson, University of Colorado - Boulder
- Jermy Thomas, National Renewable Energy Laboratory
- Christian Veje, University of Southern Denmark
- Draguna Vrabie, Pacific Northwest National Laboratory
Expand Down
67 changes: 55 additions & 12 deletions data/data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,20 +333,36 @@ def get_data(self, horizon=24*3600, interval=None, index=None,
# the closest possible point under stop will be the end
# point in order to keep interval unchanged among index.
index = np.arange(start,stop+0.1,interval).astype(int)
else:
if not isinstance(index, np.ndarray):
index = np.asarray(index)

# Reindex to the desired index
data_slice_reindexed = data_slice.reindex(index)

for key in data_slice_reindexed.keys():
# Use linear interpolation for continuous variables
if key in self.categories['weather']:
f = interpolate.interp1d(self.case.data.index,
self.case.data[key], kind='linear')
# Use forward fill for discrete variables
else:
f = interpolate.interp1d(self.case.data.index,
self.case.data[key], kind='zero')
data_slice_reindexed.loc[:,key] = f(index)
start = index[0]
# 1 year in (s)
year = 31536000
# Starting year
year_start = int(np.floor(start/year))*year
# Normalizing index with respect to starting year
index_norm = index - year_start
stop_norm = index_norm[-1]
# If stop happens across the year divide df and interpolate separately
if stop_norm > data_slice.index[-1]:
idx_year = (np.abs(index_norm - year)).argmin() + 1
# Take previous index value if index at idx_year > year
if index_norm[idx_year - 1] - year > np.finfo(float).eps:
idx_year = idx_year -1
df_slice1 = data_slice.reindex(index_norm[:idx_year])
df_slice1 = self.interpolate_data(df_slice1,index_norm[:idx_year])
df_slice2 = data_slice.reindex(index_norm[idx_year:] - year)
df_slice2 = self.interpolate_data(df_slice2,index_norm[idx_year:] - year)
df_slice2.index = df_slice2.index + year
data_slice_reindexed = pd.concat([df_slice1,df_slice2])
else:
data_slice_reindexed = data_slice.reindex(index_norm)
data_slice_reindexed = self.interpolate_data(data_slice_reindexed,index_norm)
# Add starting year back to index desired by user
data_slice_reindexed.index = data_slice_reindexed.index + year_start

if plot:
if category is None:
Expand Down Expand Up @@ -504,6 +520,33 @@ def get_data_metadata(self):

return data_metadata

def interpolate_data(self,df,index):
'''Interpolate testcase data.
Parameters
----------
df: pandas.DataFrame
Dataframe that needs to be interpolated
index: np.array()
Index to use to get interpolated data
Returns
-------
df: pandas.DataFrame
Interpolated dataframe
'''
for key in df.keys():
# Use linear interpolation for continuous variables
if key in self.categories['weather']:
f = interpolate.interp1d(self.case.data.index,
self.case.data[key], kind='linear')
# Use forward fill for discrete variables
else:
f = interpolate.interp1d(self.case.data.index,
self.case.data[key], kind='zero')
df.loc[:,key] = f(index)
return df

if __name__ == "__main__":
import sys
Expand Down
34 changes: 32 additions & 2 deletions docs/design/source/forecasts.rst
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
Forecast Generation
===================

Forecaster Module
-----------------

A forecaster module is developed to retrieve forecast from a BOPTEST
testcase, which is needed for predictive controllers. This module uses the
data_manager object of a test case to read the deterministic forecast from
the testcase wrapped.fmu. In future developments it will be possible to
:code:`data_manager` object of a test case to read the deterministic forecast from
the testcase :code:`wrapped.fmu`. In future developments it will be possible to
request stochastic forecast with a predefined distribution over the
deterministic forecast for research purposes. This distribution will be
added on the top of the deterministic forecast mentioned before.
Expand All @@ -15,3 +18,30 @@ The controller developer can choose the prediction horizon and interval of
the forecast from the actual simulation time. The controller developer may
also filter the forecast for a specific data category or request all data
variables and filter it afterwards.

Getting Weather Forecasts Across Year-End
-----------------------------------------

The data in TMY weather files used in BOPTEST test cases are discontinuous
at the end of the year relative to the start of the year.
Therefore, so is the weather data in the .csv files supplied for weather
forecast generation. As an example, see the relative humidity in the
figure below (orange line). If weather forecasts are asked for that cross
year-end, the :code:`data_manager` object used by the forcaster module splits the
data at year-end into one portion that is inclusive of the last data point
at the end of the year (midnight), and one portion after the end of the
year that is not inclusive of the first data point at the start of the
year (midnight). The implementation is done this way so that the forecast
is more consistent for any interval through the full first year if a user
only intends to simulate one year. The relative humidity plot below shows
the interpolation behavior of the implementation graphically for forecast
intervals of 1800s and 123s (intervals used in the unit tests), compared
to the reference weather boundary condition data at 1800s intervals
in the .csv file.

.. figure:: images/relative_humidity_over_year_sim.png
:scale: 50 %

Forecast retrieved across one year for intervals of 1800s (blue) and
123s (yellow) compared to the reference data in the boundary condition
.csv file (orange), shown for relative humidity.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions releasenotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Released on xx/xx/xxxx.
- Add materials for RLEM23 workshop at ``docs/workshops/RlemWorkshop_20231112``. This is for [#585](https://github.com/ibpsa/project1-boptest/issues/585).
- Change JModelica docker container address in ``testing/Dockerfile``. This is for [#590](https://github.com/ibpsa/project1-boptest/issues/590).
- Specify the Python version (3.7) used for building the wrapper to execute the example JavaScript controllers in the unit test. This is for [#594](https://github.com/ibpsa/project1-boptest/issues/594).
- Allow simulations and forecast to work across the end of the year to the next year. This is for [#239](https://github.com/ibpsa/project1-boptest/issues/239).
- Pin base Docker image to ``linux/x86_64`` platform. This is for [#608](https://github.com/ibpsa/project1-boptest/issues/608).

## BOPTEST v0.5.0

Expand Down
Loading

0 comments on commit a0682a0

Please sign in to comment.