@@ -214,46 +214,47 @@ def transform(ts, name, how, siminfo):
214214 """
215215
216216 tsfreq = ts .index .freq
217- freq = Minute (siminfo ["delt" ])
217+ fmins = Minute (siminfo ["delt" ])
218+ freq = fmins .nanos
218219 stop = siminfo ["stop" ]
219220
220221 # append duplicate of last point to force processing last full interval
221222 if ts .index [- 1 ] < stop :
222223 ts [stop ] = ts .iloc [- 1 ]
223224
224- if freq == tsfreq :
225+ if freq == tsfreq . nanos :
225226 pass
226227 elif tsfreq is None : # Sparse time base, frequency not defined
227228 ts = ts .reindex (siminfo ["tbase" ]).ffill ().bfill ()
228229 elif how == "SAME" :
229- ts = ts .resample (freq ).ffill () # tsfreq >= freq assumed, or bad user choice
230+ ts = ts .resample (fmins ).ffill () # tsfreq.nanos >= freq assumed, or bad user choice
230231 elif not how :
231232 if name in flowtype :
232- if "Y" in str (tsfreq ) or "M" in str (tsfreq ) or tsfreq > freq :
233+ if "Y" in str (tsfreq ) or "M" in str (tsfreq ) or tsfreq . nanos > freq :
233234 if "M" in str (tsfreq ):
234235 ratio = 1.0 / 730.5
235236 elif "Y" in str (tsfreq ):
236237 ratio = 1.0 / 8766.0
237238 else :
238- ratio = freq / tsfreq
239- ts = (ratio * ts ).resample (freq ).ffill () # HSP2 how = div
239+ ratio = freq / tsfreq . nanos
240+ ts = (ratio * ts ).resample (fmins ).ffill () # HSP2 how = div
240241 else :
241- ts = ts .resample (freq ).sum ()
242+ ts = ts .resample (fmins ).sum ()
242243 else :
243- if "Y" in str (tsfreq ) or "M" in str (tsfreq ) or tsfreq > freq :
244- ts = ts .resample (freq ).ffill ()
244+ if "Y" in str (tsfreq ) or "M" in str (tsfreq ) or tsfreq . nanos > freq :
245+ ts = ts .resample (fmins ).ffill ()
245246 else :
246- ts = ts .resample (freq ).mean ()
247+ ts = ts .resample (fmins ).mean ()
247248 elif how == "MEAN" :
248- ts = ts .resample (freq ).mean ()
249+ ts = ts .resample (fmins ).mean ()
249250 elif how == "SUM" :
250- ts = ts .resample (freq ).sum ()
251+ ts = ts .resample (fmins ).sum ()
251252 elif how == "MAX" :
252- ts = ts .resample (freq ).max ()
253+ ts = ts .resample (fmins ).max ()
253254 elif how == "MIN" :
254- ts = ts .resample (freq ).min ()
255+ ts = ts .resample (fmins ).min ()
255256 elif how == "LAST" :
256- ts = ts .resample (freq ).ffill ()
257+ ts = ts .resample (fmins ).ffill ()
257258 elif how == "DIV" :
258259 if "Y" in str (tsfreq ) or "M" in str (tsfreq ):
259260 mult = 1
@@ -267,14 +268,14 @@ def transform(ts, name, how, siminfo):
267268 elif "Y" in str (tsfreq ):
268269 ratio = 1.0 / (8766.0 * mult )
269270 else :
270- ratio = freq / tsfreq
271- ts = (ratio * ts ).resample (freq ).ffill () # HSP2 how = div
271+ ratio = freq / tsfreq . nanos
272+ ts = (ratio * ts ).resample (fmins ).ffill () # HSP2 how = div
272273 else :
273- ts = (ts * (freq / ts . index . freq )).resample (freq ).ffill ()
274+ ts = (ts * (freq / tsfreq . nanos )).resample (fmins ).ffill ()
274275 elif how == "ZEROFILL" :
275- ts = ts .resample (freq ).fillna (0.0 )
276+ ts = ts .resample (fmins ).fillna (0.0 )
276277 elif how == "INTERPOLATE" :
277- ts = ts .resample (freq ).interpolate ()
278+ ts = ts .resample (fmins ).interpolate ()
278279 else :
279280 print (f"UNKNOWN method in TRANS, { how } " )
280281 return zeros (1 )
@@ -287,7 +288,8 @@ def hoursval(siminfo, hours24, dofirst=False, lapselike=False):
287288 """create hours flags, flag on the hour or lapse table over full simulation"""
288289 start = siminfo ["start" ]
289290 stop = siminfo ["stop" ]
290- freq = Minute (siminfo ["delt" ])
291+ fmins = Minute (siminfo ["delt" ])
292+ freq = fmins .nanos
291293
292294 dr = date_range (
293295 start = f"{ start .year } -01-01" , end = f"{ stop .year } -12-31" , freq = Minute (60 )
@@ -297,16 +299,17 @@ def hoursval(siminfo, hours24, dofirst=False, lapselike=False):
297299 hours [0 ] = 1
298300
299301 ts = Series (hours [0 : len (dr )], dr )
302+ tsfreq = ts .index .freq
300303 if lapselike :
301- if ts . index . freq > freq : # upsample
302- ts = ts .resample (freq ).asfreq ().ffill ()
303- elif ts . index . freq < freq : # downsample
304- ts = ts .resample (freq ).mean ()
304+ if tsfreq . nanos > freq : # upsample
305+ ts = ts .resample (fmins ).asfreq ().ffill ()
306+ elif tsfreq . nanos < freq : # downsample
307+ ts = ts .resample (fmins ).mean ()
305308 else :
306- if ts . index . freq > freq : # upsample
307- ts = ts .resample (freq ).asfreq ().fillna (0.0 )
308- elif ts . index . freq < freq : # downsample
309- ts = ts .resample (freq ).max ()
309+ if tsfreq . nanos > freq : # upsample
310+ ts = ts .resample (fmins ).asfreq ().fillna (0.0 )
311+ elif tsfreq . nanos < freq : # downsample
312+ ts = ts .resample (fmins ).max ()
310313 return ts .truncate (start , stop ).to_numpy ()
311314
312315
@@ -321,16 +324,18 @@ def monthval(siminfo, monthly):
321324 """returns value at start of month for all times within the month"""
322325 start = siminfo ["start" ]
323326 stop = siminfo ["stop" ]
324- freq = Minute (siminfo ["delt" ])
327+ fmins = Minute (siminfo ["delt" ])
328+ freq = fmins .nanos
325329
326330 months = tile (monthly , stop .year - start .year + 1 ).astype (float )
327331 dr = date_range (start = f"{ start .year } -01-01" , end = f"{ stop .year } -12-31" , freq = "MS" )
328332 ts = Series (months , index = dr ).resample ("D" ).ffill ()
333+ tsfreq = ts .index .freq
329334
330- if ts . index . freq > freq : # upsample
331- ts = ts .resample (freq ).asfreq ().ffill ()
332- elif ts . index . freq < freq : # downsample
333- ts = ts .resample (freq ).mean ()
335+ if tsfreq . nanos > freq : # upsample
336+ ts = ts .resample (fmins ).asfreq ().ffill ()
337+ elif tsfreq . nanos < freq : # downsample
338+ ts = ts .resample (fmins ).mean ()
334339 return ts .truncate (start , stop ).to_numpy ()
335340
336341
@@ -339,16 +344,19 @@ def dayval(siminfo, monthly):
339344 interpolation to day, but constant within day"""
340345 start = siminfo ["start" ]
341346 stop = siminfo ["stop" ]
342- freq = Minute (siminfo ["delt" ])
347+ fmins = Minute (siminfo ["delt" ])
348+ freq = fmins .nanos
343349
344350 months = tile (monthly , stop .year - start .year + 1 ).astype (float )
345351 dr = date_range (start = f"{ start .year } -01-01" , end = f"{ stop .year } -12-31" , freq = "MS" )
346352 ts = Series (months , index = dr ).resample ("D" ).interpolate ("time" )
353+ tsfreq = ts .index .freq
354+
347355
348- if ts . index . freq > freq : # upsample
349- ts = ts .resample (freq ).ffill ()
350- elif ts . index . freq < freq : # downsample
351- ts = ts .resample (freq ).mean ()
356+ if tsfreq . nanos > freq : # upsample
357+ ts = ts .resample (fmins ).ffill ()
358+ elif tsfreq . nanos < freq : # downsample
359+ ts = ts .resample (fmins ).mean ()
352360 return ts .truncate (start , stop ).to_numpy ()
353361
354362
0 commit comments