Skip to content

Commit

Permalink
utilities.py and io.py -- small improvements to get into the next rel…
Browse files Browse the repository at this point in the history
…ease, for GENER operations and outputting mean values
  • Loading branch information
PaulDudaRESPEC committed May 1, 2024
1 parent 9e8abaa commit 63b8e86
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 2 additions & 7 deletions HSP2/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,10 +462,6 @@ def get_gener_timeseries(ts: Dict, gener_instances: Dict, ddlinks: List, ddmassl
mldata = ddmasslinks[link.MLNO]
for dat in mldata:
mfactor = dat.MFACTOR
sgrpn = dat.SGRPN
smemn = dat.SMEMN
smemsb1 = dat.SMEMSB1
smemsb2 = dat.SMEMSB2
tmemn = dat.TMEMN
tmemsb1 = dat.TMEMSB1
tmemsb2 = dat.TMEMSB2
Expand All @@ -474,9 +470,8 @@ def get_gener_timeseries(ts: Dict, gener_instances: Dict, ddlinks: List, ddmassl
factor = afactr * mfactor

# may need to do something in here for special cases like in get_flows

smemn, tmemn = expand_timeseries_names(sgrpn, smemn, smemsb1, smemsb2, tmemn, tmemsb1,
tmemsb2)
if tmemn != 'ONE' and tmemn != 'TWO':
tmemn = clean_name(tmemn, tmemsb1 + tmemsb2)

t = series * factor

Expand Down
6 changes: 6 additions & 0 deletions HSP2IO/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,23 @@ def write_ts(self,
# change time step of output to daily
sumdf1 = data_frame.resample('D',kind='timestamp',origin='start').sum()
lastdf2 = data_frame.resample('D', kind='timestamp', origin='start').last()
meandf3 = data_frame.resample('D', kind='timestamp', origin='start').mean()
data_frame= pd.merge(lastdf2.add_suffix('_last'), sumdf1.add_suffix('_sum'), left_index=True, right_index=True)
data_frame = pd.merge(data_frame, meandf3.add_suffix('_aver'), left_index=True,right_index=True)
elif outstep == 4:
# change to monthly
sumdf1 = data_frame.resample('M',kind='timestamp',origin='start').sum()
lastdf2 = data_frame.resample('M', kind='timestamp', origin='start').last()
meandf3 = data_frame.resample('M', kind='timestamp', origin='start').mean()
data_frame = pd.merge(lastdf2.add_suffix('_last'), sumdf1.add_suffix('_sum'), left_index=True, right_index=True)
data_frame = pd.merge(data_frame, meandf3.add_suffix('_aver'), left_index=True, right_index=True)
elif outstep == 5:
# change to annual
sumdf1 = data_frame.resample('Y',kind='timestamp',origin='start').sum()
lastdf2 = data_frame.resample('Y', kind='timestamp', origin='start').last()
meandf3 = data_frame.resample('Y', kind='timestamp', origin='start').mean()
data_frame = pd.merge(lastdf2.add_suffix('_last'), sumdf1.add_suffix('_sum'), left_index=True, right_index=True)
data_frame = pd.merge(data_frame, meandf3.add_suffix('_aver'), left_index=True, right_index=True)
self._output.write_ts(data_frame, category, operation, segment, activity)

def read_ts(self,
Expand Down

0 comments on commit 63b8e86

Please sign in to comment.