Skip to content

Commit

Permalink
Added function example_weather_forecast
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanlassere committed Apr 29, 2024
1 parent de82c6b commit 4938d51
Show file tree
Hide file tree
Showing 8 changed files with 8,872 additions and 54 deletions.
14 changes: 4 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,13 @@ The parameters that are specific to AFC include the following entries:
- `zone`: Configuration of each control zone within the building.

#### 1.2 Define Data (Time-series) Inputs
The optimization also needs additional data (time series) inputs to indicate the values for time-variable model inputs (such as weather data, occupancy, internal loads, etc.). Depending on the specific application of AFC, these are typically either provided by forecast models or building operators. The AFC package provides example data to represent weather forecasts for San Francisco, CA.
The optimization also needs additional data (time series) inputs to indicate the values for time-variable model inputs (such as weather data, occupancy, internal loads, etc.). Depending on the specific application of AFC, these are typically either provided by forecast models or building operators. The AFC package provides example data to represent weather forecasts for San Francisco, CA, as well as a function to read it.

```python
from afc.utility.weather import read_tmy3
from afc.utility.weather import example_weather_forecast
# read the weather file
weather_path =
'dev/resources/weather/USA_CA_San.Francisco.Intl.AP.724940_TMY3.csv'
weather, info = read_tmy3(weather_path)
# define start time
start_time = dtm.datetime(2023, 7, 1)
# select weather forecast for 24 hours ahead
wf = weather.loc[start_time:start_time+pd.DateOffset(hours=24),].iloc[:-1]
# select weather data needed for AFC
wf = wf[['temp_air','dhi','dhi','wind_speed']].copy()
wf = example_weather_forecast(date='2023-07-01')
```

The time-series input must be in the form of a pandas dataframe, indexed by timestamp, and contain the following weather forecast columns for the given location:
Expand Down
10 changes: 2 additions & 8 deletions afc/ctrlWrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,19 +461,13 @@ def make_inputs(parameter, df, ext_df=pd.DataFrame(), return_json=True):
root = os.getcwd()

from afc.utility.weather import read_tmy3
from afc.utility.weather import example_weather_forecast
# from afc.radiance.configs import get_config
from afc.defaultConfig import default_parameter
from afc.utility.plotting import plot_standard1

# read weather (forecast) data
weather_path = os.path.join(os.path.dirname(root), 'dev', 'resources', 'weather',
'USA_CA_San.Francisco.Intl.AP.724940_TMY3.csv')
weather, info = read_tmy3(weather_path, coerce_year=2023)
weather = weather.resample('5min').interpolate()
st = dtm.datetime(2023, 7, 1)
wf = weather.loc[st:st+pd.DateOffset(hours=24),]
wf = wf[['temp_air','dni','dhi','wind_speed']+['ghi']].copy()
wf = wf[wf.index.date == wf.index[0].date()]
wf = example_weather_forecast(date='2023-07-01')

# Initialize controller
ctrl = Controller()
Expand Down
2 changes: 1 addition & 1 deletion afc/resources/config/example_config.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"system_id": "Test-AAA", "location_state": "CA", "location_city": "Berkeley", "location_orientation": 180, "room_width": 10, "room_height": 11, "room_depth": 15, "occupant_1_direction": 0, "occupant_brightness": 100, "occupant_glare": 100, "window_width": 4.5, "window_height": 8.5, "window_sill": 0.5, "window_count": 2, "system_type": "ec-71t", "system_light": "FLU", "system_cooling": "el", "system_cooling_eff": 3.5, "system_heating": "el", "system_heating_eff": 0.95, "location_latitude": 37.85, "location_longitude": -122.24, "occupant_number": 1, "debug": false, "tariff_name": "e19-2020", "building_age": "new_constr", "interface_status": "Updated Configuration."}
{"system_id": "Test-AAA", "location_state": "CA", "location_city": "Berkeley", "location_orientation": 0, "room_width": 10, "room_height": 11, "room_depth": 15, "occupant_1_direction": 0, "occupant_brightness": 100, "occupant_glare": 100, "window_width": 4.5, "window_height": 8.5, "window_sill": 0.5, "window_count": 2, "system_type": "ec-71t", "system_light": "LED", "system_cooling": "el", "system_cooling_eff": 3.5, "system_heating": "el", "system_heating_eff": 0.95, "location_latitude": 37.85, "location_longitude": -122.24, "occupant_number": 1, "debug": false, "tariff_name": "e19-2020", "building_age": "new_constr", "interface_status": "Updated Configuration."}
8,762 changes: 8,762 additions & 0 deletions afc/resources/weather/USA_CA_San.Francisco.Intl.AP.724940_TMY3.csv

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions afc/utility/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,23 @@ def get_forecast(st=dt.datetime.now(), tz=-8,
loc=loc0, model=model0)
print(f'Duration for forecast: {round(time.time()-st1,1)}s')
print(forecast[['ghi','dhi','dni']].round(0))



def example_weather_forecast(date=None, horizon=24):
if not date:
# select today's date
start_time = dt.datetime.now().date()
else:
start_time = pd.to_datetime(date)

# read weather (forecast) data
weather_path = os.path.join(os.path.dirname(root), 'resources', 'weather',
'USA_CA_San.Francisco.Intl.AP.724940_TMY3.csv')
weather, info = read_tmy3(weather_path, coerce_year=start_time.year)
weather = weather.resample('5min').interpolate()

# output data
wf = weather.loc[start_time:start_time+pd.DateOffset(hours=horizon),]
wf = wf[['temp_air','dni','dhi','wind_speed']+['ghi']].copy()
return wf
94 changes: 77 additions & 17 deletions dev/Development-ControllerWrapper.ipynb

Large diffs are not rendered by default.

12 changes: 3 additions & 9 deletions examples/example_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# Improts from the AFC package
from afc.ctrlWrapper import Controller, make_inputs
from afc.utility.weather import read_tmy3
from afc.utility.weather import example_weather_forecast
from afc.radiance.configs import get_config
from afc.defaultConfig import default_parameter
from afc.utility.plotting import plot_standard1
Expand All @@ -33,21 +34,14 @@ def example1():

# read weather (forecast) data
# this would normally come from a weather forecast module
weather_path = os.path.join(os.path.dirname(root), 'dev', 'resources', 'weather',
'USA_CA_San.Francisco.Intl.AP.724940_TMY3.csv')
weather, info = read_tmy3(weather_path, coerce_year=2023)
#weather = weather.resample('5min').interpolate()
st = dtm.datetime(2023, 7, 1)
wf = weather.loc[st:st+pd.DateOffset(hours=24),]
df = wf[['temp_air','dni','dhi','wind_speed']].copy()
df = df[df.index.date == df.index[0].date()]
wf = example_weather_forecast(date='2023-07-01')

# Initialize controller
ctrl = Controller()

# Make inputs
parameter = default_parameter()
inputs = make_inputs(parameter, df)
inputs = make_inputs(parameter, wf)

# Query controller
log = ctrl.do_step(inputs=inputs) # run controller
Expand Down
12 changes: 3 additions & 9 deletions test/test_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
warnings.simplefilter(action='ignore', category=pd.errors.PerformanceWarning)
from afc.ctrlWrapper import Controller, make_inputs
from afc.utility.weather import read_tmy3
from afc.utility.weather import example_weather_forecast
from afc.radiance.configs import get_config
from afc.defaultConfig import default_parameter
from afc.utility.plotting import plot_standard1
Expand All @@ -29,21 +30,14 @@ def test1():
"""

# read weather (forecast) data
weather_path = os.path.join(os.path.dirname(root), 'dev', 'resources', 'weather',
'USA_CA_San.Francisco.Intl.AP.724940_TMY3.csv')
weather, info = read_tmy3(weather_path, coerce_year=2023)
weather = weather.resample('5min').interpolate()
st = dtm.datetime(2023, 7, 1)
wf = weather.loc[st:st+pd.DateOffset(hours=24),]
df = wf[['temp_air','dni','dhi','wind_speed']].copy()
df = df[df.index.date == df.index[0].date()]
wf = example_weather_forecast(date='2023-07-01')

# Initialize controller
ctrl = Controller()

# Make inputs
parameter = default_parameter()
inputs = make_inputs(parameter, df)
inputs = make_inputs(parameter, wf)

# Query controller
ctrl.do_step(inputs=inputs)
Expand Down

0 comments on commit 4938d51

Please sign in to comment.