|
11 | 11 | from collections import defaultdict |
12 | 12 | from datetime import datetime as dt |
13 | 13 | import os |
14 | | -from HSP2.utilities import transform, versions, get_timeseries |
| 14 | +from HSP2.utilities import transform, versions, get_timeseries, expand_timeseries_names |
15 | 15 | from HSP2.configuration import activities, noop, expand_masslinks |
16 | 16 |
|
17 | 17 | from typing import List |
@@ -257,53 +257,6 @@ def get_uci(store): |
257 | 257 | for i in range(int(start), int(stop)): ddgener[module][f'G{i:03d}'] = row[2] |
258 | 258 | return opseq, ddlinks, ddmasslinks, ddext_sources, ddgener, uci, siminfo |
259 | 259 |
|
260 | | - |
261 | | -def get_timeseries(store, ext_sourcesdd, siminfo): |
262 | | - ''' makes timeseries for the current timestep and trucated to the sim interval''' |
263 | | - # explicit creation of Numba dictionary with signatures |
264 | | - ts = Dict.empty(key_type=types.unicode_type, value_type=types.float64[:]) |
265 | | - for row in ext_sourcesdd: |
266 | | - if row.SVOL == '*': |
267 | | - path = f'TIMESERIES/{row.SVOLNO}' |
268 | | - if path in store: |
269 | | - temp1 = store[path] |
270 | | - else: |
271 | | - print('Get Timeseries ERROR for', path) |
272 | | - continue |
273 | | - else: |
274 | | - temp1 = read_hdf(row.SVOL, path) |
275 | | - |
276 | | - if row.MFACTOR != 1.0: |
277 | | - temp1 *= row.MFACTOR |
278 | | - t = transform(temp1, row.TMEMN, row.TRAN, siminfo) |
279 | | - |
280 | | - # in some cases the subscript is irrelevant, like '1' or '1 1', and we can leave it off. |
281 | | - # there are other cases where it is needed to distinguish, such as ISED and '1' or '1 1'. |
282 | | - tname = f'{row.TMEMN}{row.TMEMSB}' |
283 | | - if row.TMEMN in {'GATMP', 'PREC', 'DTMPG', 'WINMOV', 'DSOLAR', 'SOLRAD', 'CLOUD', 'PETINP', 'IRRINP', 'POTEV', 'DEWTMP', 'WIND', |
284 | | - 'IVOL', 'IHEAT'}: |
285 | | - tname = f'{row.TMEMN}' |
286 | | - elif row.TMEMN == 'ISED': |
287 | | - if row.TMEMSB == '1 1' or row.TMEMSB == '1' or row.TMEMSB == '': |
288 | | - tname = 'ISED1' |
289 | | - else: |
290 | | - tname = 'ISED' + row.TMEMSB[0] |
291 | | - elif row.TMEMN in {'ICON', 'IDQAL', 'ISQAL'}: |
292 | | - tmemsb1 = '1' |
293 | | - tmemsb2 = '1' |
294 | | - if len(row.TMEMSB) > 0: |
295 | | - tmemsb1 = row.TMEMSB[0] |
296 | | - if len(row.TMEMSB) > 2: |
297 | | - tmemsb2 = row.TMEMSB[-1] |
298 | | - sname, tname = expand_timeseries_names('', '', '', row.TMEMN, tmemsb1, tmemsb2) |
299 | | - |
300 | | - if tname in ts: |
301 | | - ts[tname] += t |
302 | | - else: |
303 | | - ts[tname] = t |
304 | | - return ts |
305 | | - |
306 | | - |
307 | 260 | def save_timeseries(store, ts, savedict, siminfo, saveall, operation, segment, activity, jupyterlab=True): |
308 | 261 | # save computed timeseries (at computation DELT) |
309 | 262 | save = {k for k,v in savedict.items() if v or saveall} |
@@ -457,91 +410,6 @@ def get_flows(store, ts, flags, uci, segment, ddlinks, ddmasslinks, steps, msg): |
457 | 410 | print('ERROR in FLOWS for', path) |
458 | 411 | return |
459 | 412 |
|
460 | | -def expand_timeseries_names(smemn, smemsb1, smemsb2, tmemn, tmemsb1, tmemsb2): |
461 | | - #special cases to expand timeseries names to resolve with output names in hdf5 file |
462 | | - if tmemn == 'ICON': |
463 | | - if tmemsb1 == '': |
464 | | - tmemn = 'CONS1_ICON' |
465 | | - else: |
466 | | - tmemn = 'CONS' + tmemsb1 + '_ICON' |
467 | | - if smemn == 'OCON': |
468 | | - if smemsb2 == '': |
469 | | - smemn = 'CONS1_OCON' + smemsb1 |
470 | | - else: |
471 | | - smemn = 'CONS' + smemsb2 + '_OCON' + smemsb1 |
472 | | - if smemn == 'ROCON': |
473 | | - if smemsb1 == '': |
474 | | - smemn = 'CONS1_ROCON' |
475 | | - else: |
476 | | - smemn = 'CONS' + smemsb1 + '_ROCON' |
477 | | - |
478 | | - # GQUAL: |
479 | | - if tmemn == 'IDQAL': |
480 | | - if tmemsb1 == '': |
481 | | - tmemn = 'GQUAL1_IDQAL' |
482 | | - else: |
483 | | - tmemn = 'GQUAL' + tmemsb1 + '_IDQAL' |
484 | | - if tmemn == 'ISQAL1' or tmemn == 'ISQAL2' or tmemn == 'ISQAL3': |
485 | | - if tmemsb2 == '': |
486 | | - tmemn = 'GQUAL1_' + tmemn |
487 | | - else: |
488 | | - tmemn = 'GQUAL' + tmemsb2 + '_' + tmemn |
489 | | - if tmemn == 'ISQAL': |
490 | | - if tmemsb2 == '': |
491 | | - tmemn = 'GQUAL1_' + 'ISQAL' + tmemsb1 |
492 | | - else: |
493 | | - tmemn = 'GQUAL' + tmemsb2 + '_' + 'ISQAL' + tmemsb1 |
494 | | - if smemn == 'ODQAL': |
495 | | - smemn = 'GQUAL' + smemsb1 + '_ODQAL' + smemsb2 # smemsb2 is exit number |
496 | | - if smemn == 'OSQAL': |
497 | | - smemn = 'GQUAL' + smemsb1 + '_OSQAL' + smemsb2 # smemsb2 is ssc plus exit number |
498 | | - if smemn == 'RODQAL': |
499 | | - smemn = 'GQUAL' + smemsb1 + '_RODQAL' |
500 | | - if smemn == 'ROSQAL': |
501 | | - smemn = 'GQUAL' + smemsb2 + '_ROSQAL' + smemsb1 # smemsb1 is ssc |
502 | | - |
503 | | - # OXRX: |
504 | | - if smemn == 'OXCF1': |
505 | | - smemn = 'OXCF1' + smemsb1 |
506 | | - |
507 | | - if smemn == 'OXCF2': |
508 | | - smemn = 'OXCF2' + smemsb1 + ' ' + smemsb2 # smemsb1 is exit # |
509 | | - |
510 | | - if tmemn == 'OXIF': |
511 | | - tmemn = 'OXIF' + tmemsb1 |
512 | | - |
513 | | - # NUTRX - dissolved species: |
514 | | - if smemn == 'NUCF1': # total outflow |
515 | | - smemn = 'NUCF1' + smemsb1 |
516 | | - |
517 | | - if smemn == 'NUCF9': # exit-specific outflow |
518 | | - smemn = 'NUCF9' + smemsb1 + ' ' + smemsb2 # smemsb1 is exit # |
519 | | - |
520 | | - if tmemn == 'NUIF1': |
521 | | - tmemn = 'NUIF1' + tmemsb1 |
522 | | - |
523 | | - # NUTRX - particulate species: |
524 | | - if smemn == 'NUCF2': # total outflow |
525 | | - smemn = 'NUCF2' + smemsb1 + ' ' + smemsb2 # smemsb1 is sediment class |
526 | | - |
527 | | - if smemn == 'OSNH4' or smemn == 'OSPO4': # exit-specific outflow |
528 | | - smemn = smemn + smemsb1 + ' ' + smemsb2 # smemsb1 is exit #, smemsb2 is sed class |
529 | | - |
530 | | - if tmemn == 'NUIF2': |
531 | | - tmemn = 'NUIF2' + tmemsb1 + ' ' + tmemsb2 |
532 | | - |
533 | | - # PLANK: |
534 | | - if smemn == 'PKCF1': # total outflow |
535 | | - smemn = 'PKCF1' + smemsb1 # smemsb1 is species index |
536 | | - |
537 | | - if smemn == 'PKCF2': # exit-specific outflow |
538 | | - smemn = 'PKCF2' + smemsb1 + ' ' + smemsb2 # smemsb1 is exit #, smemsb2 is species index |
539 | | - |
540 | | - if tmemn == 'PKIF': |
541 | | - tmemn = 'PKIF' + tmemsb1 # smemsb1 is species index |
542 | | - |
543 | | - return smemn, tmemn |
544 | | - |
545 | 413 | def get_gener_timeseries(ts: Dict, gener_instances: Dict, ddlinks: List) -> Dict: |
546 | 414 | """ |
547 | 415 | Uses links tables to load necessary TimeSeries from Gener class instances to TS dictionary |
|
0 commit comments