Skip to content

Commit

Permalink
update of radiance and frads backend and depreciation changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristophGehbauer committed Jan 25, 2024
1 parent fca7863 commit 321a122
Show file tree
Hide file tree
Showing 822 changed files with 2,118 additions and 105,278 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# ipynb checkpoints #
#####################
*checkpoint.ipynb
*/.ipynb_checkpoints/*
.ipynb_checkpoints

# Other #
#########
Expand All @@ -23,3 +23,6 @@ cbc_*
*.zip
*_error.html
all_rins.csv
*.npz
Octrees
Temp
40 changes: 19 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ The following link permits users to clone the source directory containing the [A

Alternatively, AFC can be directly installed with `pip install git+https://github.com/LBNL-ETA/AFC`.

In addition the [Radiance](https://www.radiance-online.org/download-install/radiance-source-code/latest-release) tool needs to be installed. Binaries can be found [here](https://github.com/LBNL-ETA/Radiance/releases).

## Example
To test the installation and illustrate the functionality of AFC, the following command can be executed to run the [example_1.py](https://github.com/LBNL-ETA/AFC/blob/master/examples/example_1.py).

Expand All @@ -36,31 +34,31 @@ Running AFC Example1...
Configuration: three zone electrochromic window
Log-message:
Solver CBC 2.10.5
Duration [s] 3.28
Objective [$] 29.48 13.94 (Total Cost)
Cost [$] 16.15 (Energy) 13.21 (Demand)
Duration [s] 0.21
Objective [$] 20.49 7.63 (Total Cost)
Cost [$] 13.39 (Energy) 7.02 (Demand)
CO2 Emissions [kg] 0.0
Facade actuation during the day (when DNI > 0).
Facade 0 = bottom zone, Facade 1 = middle zone, Facade 2 = top zone
State 0.0 = fully tinted, State 1.0 and 2.0 = intermediate tint, state 3.0 = clear (double low-e)
Facade State 0 Facade State 1 Facade State 2
2022-07-01 05:00:00 3.0 3.0 3.0
2022-07-01 06:00:00 3.0 3.0 3.0
2022-07-01 07:00:00 3.0 2.0 3.0
2022-07-01 08:00:00 1.0 1.0 3.0
2022-07-01 09:00:00 0.0 0.0 3.0
2022-07-01 10:00:00 0.0 0.0 3.0
2022-07-01 11:00:00 0.0 0.0 3.0
2022-07-01 12:00:00 0.0 0.0 3.0
2022-07-01 13:00:00 0.0 0.0 3.0
2022-07-01 14:00:00 0.0 0.0 3.0
2022-07-01 15:00:00 0.0 0.0 3.0
2022-07-01 16:00:00 1.0 2.0 3.0
2022-07-01 17:00:00 1.0 3.0 3.0
2022-07-01 18:00:00 3.0 3.0 3.0
2022-07-01 19:00:00 3.0 3.0 3.0
2023-07-01 05:00:00 3.0 3.0 3.0
2023-07-01 06:00:00 3.0 3.0 3.0
2023-07-01 07:00:00 2.0 3.0 3.0
2023-07-01 08:00:00 3.0 2.0 3.0
2023-07-01 09:00:00 2.0 2.0 3.0
2023-07-01 10:00:00 2.0 2.0 3.0
2023-07-01 11:00:00 2.0 2.0 3.0
2023-07-01 12:00:00 2.0 2.0 3.0
2023-07-01 13:00:00 2.0 2.0 3.0
2023-07-01 14:00:00 2.0 2.0 3.0
2023-07-01 15:00:00 2.0 2.0 3.0
2023-07-01 16:00:00 3.0 2.0 3.0
2023-07-01 17:00:00 2.0 3.0 3.0
2023-07-01 18:00:00 3.0 3.0 3.0
2023-07-01 19:00:00 3.0 3.0 3.0
```

Additional examples with interactive Jupyter Notebooks can be found in the [examples](https://github.com/LBNL-ETA/AFC/blob/master/examples).
Expand Down
2 changes: 1 addition & 1 deletion afc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
from .ctrlWrapper import *
from .defaultConfig import *

__version__ = "0.0.1"
__version__ = "1.1.0"
35 changes: 19 additions & 16 deletions afc/ctrlWrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

warnings.simplefilter(action='ignore', category=pd.errors.PerformanceWarning)

map_weather = {'DNI':'weaHDirNor', 'DHI':'weaHDifHor'}
map_weather = {'dni':'weaHDirNor', 'dhi':'weaHDifHor'}

class Controller(eFMU):
"""Main controller wrapper class for the AFC."""
Expand Down Expand Up @@ -185,11 +185,11 @@ def compute(self):
temp = pd.DataFrame()
for d in sorted(np.unique(wf_all.index.date)):
if temp.empty:
tt = wf_all[['DNI','DHI']][wf_all.index.date == d]
tt = wf_all[['dni','dhi']][wf_all.index.date == d]
temp = self.forecaster.compute2(tt)
else:
temp = pd.concat([temp, self.forecaster.compute2( \
wf_all[['DNI','DHI']][wf_all.index.date == d])])
wf_all[['dni','dhi']][wf_all.index.date == d])])
self.forecaster = temp

# Glare handler
Expand All @@ -199,14 +199,14 @@ def compute(self):
self.glare_handler_class(config=self.input['radiance']['location'],
view_config=view_config)
if self.input['parameter']['wrapper']['precompute_radiance']:
wf = wf_all[['DNI','DHI']].copy(deep=True).rename(columns=map_weather)
wf = wf_all[['dni','dhi']].copy(deep=True).rename(columns=map_weather)
for ix in wf.index:
wf.loc[ix, ['alt', 'azi_shift', 'inci', 'azi']] = \
self.glare_handler.get_solar(ix, wf.loc[ix:ix])
gmodes = self.glare_handler.glare_mode_many( \
*wf.loc[ix, ['alt', 'azi_shift', 'inci']].values)
for i, g in enumerate(gmodes):
wf.loc[ix, f'zone{i}_gmode'] = g
wf.loc[ix, f'zone{i}_gmode'] = int(g)
self.glare_handler = wf

# Compute radiance
Expand All @@ -215,7 +215,7 @@ def compute(self):
if self.input['parameter']['wrapper']['precompute_radiance']:
data = self.forecaster.loc[inputs.index]
else:
data = self.forecaster.compute2(inputs[['DNI','DHI']])
data = self.forecaster.compute2(inputs[['dni','dhi']])
# cutoff
rad_cutoff = self.input['parameter']['facade']['rad_cutoff']
for k in rad_cutoff.keys():
Expand All @@ -230,14 +230,14 @@ def compute(self):
if self.input['parameter']['wrapper']['precompute_radiance']:
wf = self.glare_handler.loc[inputs.index]
else:
wf = inputs[['DNI','DHI']].copy(deep=True).rename(columns=map_weather)
wf = inputs[['dni','dhi']].copy(deep=True).rename(columns=map_weather)
for ix in wf.index:
wf.loc[ix, ['alt', 'azi_shift', 'inci', 'azi']] = \
self.glare_handler.get_solar(ix, wf.loc[ix:ix])
gmodes = self.glare_handler.glare_mode_many( \
*wf.loc[ix, ['alt', 'azi_shift', 'inci']].values)
for i, g in enumerate(gmodes):
wf.loc[ix, f'zone{i}_gmode'] = g
wf.loc[ix, f'zone{i}_gmode'] = int(g)

zones = self.input['parameter']['facade']['windows']
states = self.input['parameter']['facade']['states']
Expand All @@ -254,13 +254,13 @@ def compute(self):
wf_key = f'zone{t-1 if flip_z else nz-1}_gmode'
gmodes.append(wf.loc[wf.index[0], wf_key])
data[f'ev_{nz}_{t}'] = data[f'ev_{nz}_{t}'].mask( \
(wf[wf_key] is True) & (data[f'wpi_{nz}_{t}']>0), 2e4)
(wf[wf_key] > 0) & (data[f'wpi_{nz}_{t}']>0), 2e4)
self.output['glare_duration'] = time.time() - st1

# Compute other inputs
data = pd.concat([data, inputs], axis=1)
data['oat'] = inputs['DryBulb']
data['wind_speed'] = inputs['Wspd']
data['oat'] = inputs['temp_air']
data['wind_speed'] = inputs['wind_speed']
data['battery_0_avail'] = 0
data['battery_0_demand'] = 0
data['battery_reg'] = 0
Expand Down Expand Up @@ -349,7 +349,7 @@ def compute(self):
z in self.input['parameter']['facade']['windows']]].iloc[0].values
#uShade = df[['Tint Bottom [-]', 'Tint Middle [-]', 'Tint Top [-]']].iloc[0].values
self.output['uShade'] = [round(float(u),1) for u in uShade]
self.output['uTroom'] = float(df[['Temperature 0 [C]']].iloc[1].values)
self.output['uTroom'] = float(df['Temperature 0 [C]'].values[1])
df = pd.concat([df, data], axis=1)
df.index = (df.index.astype(np.int64) / 10 ** 6).astype(str)
df = df.fillna(-1)
Expand Down Expand Up @@ -423,11 +423,11 @@ def make_inputs(parameter, df):
# 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)
weather, info = read_tmy3(weather_path, coerce_year=2023)
weather = weather.resample('5T').interpolate()
st = dtm.datetime(dtm.datetime.now().year, 7, 1)
st = dtm.datetime(2023, 7, 1)
wf = weather.loc[st:st+pd.DateOffset(hours=24),]
wf = wf[['DryBulb','DNI','DHI','Wspd']+['GHI']].copy()
wf = wf[['temp_air','dni','dhi','wind_speed']+['ghi']].copy()
wf = wf[wf.index.date == wf.index[0].date()]

# Initialize controller
Expand All @@ -451,6 +451,9 @@ def make_inputs(parameter, df):
df.index = pd.to_datetime(pd.to_numeric(df.index), unit='ms')

try:
plot_standard1(pd.concat([wf, df], axis=1).ffill())
# Remove slab constraints for plotting
df['Temperature 1 Min [C]'] = None
df['Temperature 1 Max [C]'] = None
plot_standard1(pd.concat([wf, df], axis=1).ffill().iloc[:-1])
except:
pass
20 changes: 4 additions & 16 deletions afc/radiance/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,10 @@ def get_config(mode, wwr, abs_path=True, root=os.path.join(root, '..',
"""Function to generate configuration."""

filestruct = {}
if mode == 'shade':
config_path = os.path.join(root, f'room{wwr}WWR_shade.cfg')
filestruct['resources'] = os.path.join(root, 'BSDF_shade')
filestruct['matrices'] = os.path.join(root, 'matrices', mode, str(wwr))
elif mode == 'dshade':
mode = 'shade'
config_path = os.path.join(root, f'room{wwr}WWR_shade.cfg')
filestruct['resources'] = os.path.join(root, 'BSDF_dshade')
filestruct['matrices'] = os.path.join(root, 'matrices', mode, str(wwr))
elif mode == 'blinds':
config_path = os.path.join(root, f'room{wwr}WWR_blinds.cfg')
filestruct['resources'] = os.path.join(root, f'BSDF_blinds{wwr}')
filestruct['matrices'] = os.path.join(root, 'matrices', mode, str(wwr))
elif mode == 'ec':
config_path = os.path.join(root, f'room{wwr}WWR_ec.cfg')
filestruct['resources'] = os.path.join(root, 'BSDFs')
if mode in ['shade', 'dshade', 'blinds', 'ec']:
cfg_mode = mode.replace('dshade', 'shade')
config_path = os.path.join(root, f'room{wwr}WWR_{cfg_mode}.cfg')
filestruct['resources'] = os.path.join(root, 'bsdf', mode)
filestruct['matrices'] = os.path.join(root, 'matrices', mode, str(wwr))
else:
print(f'ERROR: Mode {mode} not supported.')
Expand Down
Loading

0 comments on commit 321a122

Please sign in to comment.