# get the datasets wtemps = wdm.get_data('test.wdm', 134) evaps = wdm.get_data('test.wdm', 41) winds = wdm.get_data('test.wdm', 42) flow1 = wdm.get_data('test.wdm', 113) flow2 = wdm.get_data('test.wdm', 119) dewp1 = wdm.get_data('test.wdm', 124) dewp2 = wdm.get_data('test.wdm', 125) dewp3 = wdm.get_data('test.wdm', 126) sedm = wdm.get_data('test.wdm', 127) flow3 = wdm.get_data('test.wdm', 136) # start and end dates (these are all the same so I will only do this once) start, end = wdm.get_dates('test.wdm', 134) times = [start + i * (end - start) / len(wtemps) for i in range(len(wtemps))] # use matplotlib to make the chart from matplotlib import pyplot, dates fig, subs = pyplot.subplots(nrows=3, ncols=2, sharex=True, figsize=(12, 9)) fig.suptitle('1976 Iowa River Water Quality Data', size=14) subs[0, 0].plot_date(times, dewp1, 'r-') subs[0, 0].plot_date(times, dewp2, 'g-') subs[0, 0].plot_date(times, dewp3, 'b-') subs[0, 0].set_ylabel('Dew point\n(\u00B0F)', multialignment='center')
# find all the time series types # (this is how they are identified in the exp file) tstypes = [wdm.get_attribute(f, n, 'TSTYPE') for n in dsns] # find the precip and evap timeseries (we could also just look at the exp files # to figure this out, but this illustrates some of the flexibility of PyHSPF) precip_dsn = dsns[tstypes.index('HPCP')] evap_dsn = dsns[tstypes.index('EVAP')] # get the time series and start and end dates precip = wdm.get_data(f, precip_dsn) start, end = wdm.get_dates(f, precip_dsn) evap = wdm.get_data(f, evap_dsn, start = start, end = end) # the observed flow is dsn 281 oflow = wdm.get_data(f, 281, start = start, end = end) # close up the wdm file (forgetting this WILL cause trouble) wdm.close('hunting.wdm') # make a list of the times in the daily time series using datetime "timedelta" delta = datetime.timedelta(days = 1) times = [start + i * delta for i in range(len(precip))]
# start date for the BASINS data (after the warmup period) bstart = start + datetime.timedelta(days=warmup) # get the precipitation data i = tstypes.index('PREC') prec = wdm.get_data(f2, dsns[i], start=bstart, end=end) # get the potential evapotranspiration and other climate data dsns = wdm.get_datasets(f1) tstypes = [wdm.get_attribute(f1, n, 'TSTYPE') for n in dsns] dates = [wdm.get_dates(f1, n) for n in dsns] tssteps = [wdm.get_attribute(f1, n, 'TSSTEP') for n in dsns] tcodes = [wdm.get_attribute(f1, n, 'TCODE ') for n in dsns] print(('Time series available in WDM file {}:\n'.format(f1))) for n, t, d, tstep, tcode in zip(dsns, tstypes, dates, tssteps, tcodes): s, e = d print(('{:02d}'.format(n), t, s)) # get the PyHSPF evapotranspiration data i = tstypes.index('PEVT') evap = wdm.get_data(f1, dsns[i], start=bstart, end=end) # get the PyHSPF wind speed data
# get the datasets wtemps = wdm.get_data('test.wdm', 134) evaps = wdm.get_data('test.wdm', 41) winds = wdm.get_data('test.wdm', 42) flow1 = wdm.get_data('test.wdm', 113) flow2 = wdm.get_data('test.wdm', 119) dewp1 = wdm.get_data('test.wdm', 124) dewp2 = wdm.get_data('test.wdm', 125) dewp3 = wdm.get_data('test.wdm', 126) sedm = wdm.get_data('test.wdm', 127) flow3 = wdm.get_data('test.wdm', 136) # start and end dates (these are all the same so I will only do this once) start, end = wdm.get_dates('test.wdm', 134) times = [start + i * (end - start) / len(wtemps) for i in range(len(wtemps))] # use matplotlib to make the chart from matplotlib import pyplot, dates fig, subs = pyplot.subplots(nrows = 3, ncols = 2, sharex = True, figsize = (12,9)) fig.suptitle('1976 Iowa River Water Quality Data', size = 14) subs[0,0].plot_date(times, dewp1, 'r-') subs[0,0].plot_date(times, dewp2, 'g-') subs[0,0].plot_date(times, dewp3, 'b-')
dsns = wdm.get_datasets(wdmfile) # see the datasets in the WDM file #for n in dsns: print(n, wdm.get_attribute(wdmfile, n, 'TSTYPE')) # look at the UCI file to get more info on the datasets precip = wdm.get_data(wdmfile, 106) evap = wdm.get_data(wdmfile, 426) pet = wdm.get_data(wdmfile, 425) rovol = wdm.get_data(wdmfile, 420) # acre-ft oflow = wdm.get_data(wdmfile, 281) # cfs start, end = wdm.get_dates(wdmfile, 420) # calculate the watershed area from the SCHEMATIC block in the UCI file area = (32 + 6 + 1318 + 193 + 231 + 84 + 3078 + 449 + 540 + 35) #print('watershed area: {} acres'.format(area)) # convert ROVOL and observed flows to m3/s ft3m3 = 35.314 # conversion from uci ext targets c = 0.0020107
flwData = pd.read_csv( os.path.abspath(os.path.curdir) + '\\siletz_HSPF_flw.csv') ts_to_wdmFile(wdmFile=wdmFile, pcpData=pcpData, petData=petData, flwData=flwData) # See if you can read the data from the WDM file wdm = WDMUtil(verbose=True, messagepath=mssgpath) # ADD BASIN TIMESERIES FROM THE WDM TO HSPFMODEL # open the wdm for read access wdm.open(wdmFile, 'r') start, end = wdm.get_dates(wdmFile, 101) x = 1 # Add specific basin met data for basin in range(0, len(basinRecords)): # The DSNs are known from the exp file so just use those this time prcp = wdm.get_data(wdmFile, 100 + x) evap = wdm.get_data(wdmFile, 200 + x) # Add and assign timeseries data hspfmodel.add_timeseries('precipitation', ('prcp_' + str(x)), start, prcp,
wdm.import_exp(hunthour, f) # copy the data to the hspfmodel using WDMUtil # open the wdm for read access wdm.open(f, 'r') # the dsns are known from the exp file so just use those this time precip = wdm.get_data(f, 106) evap = wdm.get_data(f, 111) oflow = wdm.get_data(f, 281) start, end = wdm.get_dates(f, 106) # close up the wdm file (forgetting this WILL cause trouble) wdm.close('hunting.wdm') # the evaporation data is daily so it needs to be disaggregated to hourly for # an hourly simulation (see how easy this is with Python) # the time series in the WDM file starts at 1 am so had to add one extra # value to the beginning of the time series for consistency evap = [0] + [e / 24 for e in evap for i in range(24)] precip = [0] + [p for p in precip] oflow = [0] + [o for o in oflow] # list of times
dsns = wdm.get_datasets(wdmfile) # see the datasets in the WDM file #for n in dsns: print(n, wdm.get_attribute(wdmfile, n, 'TSTYPE')) # look at the UCI file to get more info on the datasets precip = wdm.get_data(wdmfile, 106) evap = wdm.get_data(wdmfile, 426) pet = wdm.get_data(wdmfile, 425) rovol = wdm.get_data(wdmfile, 420) # acre-ft oflow = wdm.get_data(wdmfile, 281) # cfs start, end = wdm.get_dates(wdmfile, 420) # calculate the watershed area from the SCHEMATIC block in the UCI file area = (32 + 6 + 1318 + 193 + 231 + 84 + 3078 + 449 + 540 + 35 )
# find all the time series types # (this is how they are identified in the exp file) tstypes = [wdm.get_attribute(f, n, 'TSTYPE') for n in dsns] # find the precip and evap timeseries (we could also just look at the exp files # to figure this out, but this illustrates some of the flexibility of PyHSPF) precip_dsn = dsns[tstypes.index('HPCP')] evap_dsn = dsns[tstypes.index('EVAP')] # get the time series and start and end dates precip = wdm.get_data(f, precip_dsn) start, end = wdm.get_dates(f, precip_dsn) evap = wdm.get_data(f, evap_dsn, start=start, end=end) # the observed flow is dsn 281 oflow = wdm.get_data(f, 281, start=start, end=end) # close up the wdm file (forgetting this WILL cause trouble) wdm.close('hunting.wdm') # make a list of the times in the daily time series using datetime "timedelta" delta = datetime.timedelta(days=1) times = [start + i * delta for i in range(len(precip))]
# start date for the BASINS data (after the warmup period) bstart = start + datetime.timedelta(days = warmup) # get the precipitation data i = tstypes.index('PREC') prec = wdm.get_data(f2, dsns[i], start = bstart, end = end) # get the potential evapotranspiration and other climate data dsns = wdm.get_datasets(f1) tstypes = [wdm.get_attribute(f1, n, 'TSTYPE') for n in dsns] dates = [wdm.get_dates(f1, n) for n in dsns] tssteps = [wdm.get_attribute(f1, n, 'TSSTEP') for n in dsns] tcodes = [wdm.get_attribute(f1, n, 'TCODE ') for n in dsns] print('Time series available in WDM file {}:\n'.format(f1)) for n, t, d, tstep, tcode in zip(dsns, tstypes, dates, tssteps, tcodes): s, e = d print('{:02d}'.format(n), t, s) # get the PyHSPF evapotranspiration data i = tstypes.index('PEVT') evap = wdm.get_data(f1, dsns[i], start = bstart, end = end) # get the PyHSPF wind speed data