# operations for the model and the default values for the hydrology parameters hspfmodel.add_hydrology() # build the input wdm file hspfmodel.build_wdminfile() # tell HSPF to keep track of the outflow volume from the reach, which # has a Fortran name "ROVOL" and a PyHSPF name "reach_outvolume" targets = ['reach_outvolume'] # create the UCI for the simulation period to provide the targets hspfmodel.build_uci(targets, start, end, hydrology = True) # run it hspfmodel.run(verbose = True) # pull up the results; this output wdmfile is created automatically # and has the same name as the "filename" plus "_out.wdm" wdmoutfile = 'example02_out.wdm' wdm.open(wdmoutfile, 'r') # get the dataset numbers dsns = wdm.get_datasets(wdmoutfile)
# tell HSPF to run hydrology and assign default parameters hspfmodel.add_hydrology() # build the wdm input file using the timeseries hspfmodel.build_wdminfile() # external targets targets = ['reach_outvolume', 'evaporation', 'reach_volume', 'runoff'] # build the input files and run hspfmodel.build_uci(targets, start, end, hydrology=True, verbose=False) hspfmodel.run(verbose=True) # retrieve results using WDMUtil wdm = WDMUtil() # open the file for read access wdm.open(wdmoutfile, 'r') # pull up the flow at the outlet and plot it along with the precipitation # and evapotranspiration dsns = wdm.get_datasets(wdmoutfile) idconss = [wdm.get_attribute(wdmoutfile, n, 'IDCONS') for n in dsns]
# the targets above each correspond to a particular Fortran variable; the idea # is to make them more descriptive and easier to add. the targets above # correspond to: # # reach_outvolume = ROVOL # evaporation = TAET for PERLNDs, and IMPEV for IMPLNDs # reach_volume = RO # runoff = SURO, IFWO, and AGWO for PERLNDs, SURO for IMPLNDs # now the "build_uci" function can be used to build the UCI input file. # it also builds the output WDM file since it works together with the UCI # file. this example just does hydrology but flags exist to add air temperature, # snow, sediment, etc to the simulation assuming the required information has # been provided. hspfmodel.build_uci(targets, start, end, hydrology = True, verbose = False) # now the input files are ready, so run it hspfmodel.run(verbose = True) # now "pickle" the hspfmodel for later. "pickling" means writing a python # object to a file so that it can be accessed later. the concept is to save # the PyHSPF HSPFModel instance, and forget about the UCI. The UCI file is # always there if you want to see it, but changing the parameters is much # easier in Python, and can even be scripted. The "with" statement just closes # the file where the HSPFModel is stored. import pickle with open('hspfmodel', 'wb') as f: pickle.dump(hspfmodel, f)
targets = [ 'water_state', 'reach_outvolume', 'evaporation', 'runoff', 'groundwater', 'snow_state', 'snowpack', 'snowfall', ] # build the UCI and output WDM files simplified.build_uci(targets, start, end, atemp=True, snow=True, hydrology=True) # run it simplified.run(verbose=True) # use the Postprocessor to analyze and save the results to the folder dates = start + datetime.timedelta(days=warmup), end postprocessor = Postprocessor(simplified, dates, comid=comid) postprocessor.get_hspexp_parameters(verbose=False) postprocessor.plot_hydrograph(tstep='monthly',
# operations for the model and the default values for the hydrology parameters hspfmodel.add_hydrology() # build the input wdm file hspfmodel.build_wdminfile() # tell HSPF to keep track of the outflow volume from the reach, which # has a Fortran name "ROVOL" and a PyHSPF name "reach_outvolume" targets = ['reach_outvolume'] # create the UCI for the simulation period to provide the targets hspfmodel.build_uci(targets, start, end, hydrology=True) # run it hspfmodel.run(verbose=True) # pull up the results; this output wdmfile is created automatically # and has the same name as the "filename" plus "_out.wdm" wdmoutfile = 'example02_out.wdm' wdm.open(wdmoutfile, 'r') # get the dataset numbers dsns = wdm.get_datasets(wdmoutfile)
# output variables targets = ['water_state', 'reach_outvolume', 'evaporation', 'runoff', 'groundwater', 'snow_state', 'snowpack', 'snowfall', ] # build the UCI and output WDM files simplified.build_uci(targets, start, end, atemp = True, snow = True, hydrology = True) # run it simplified.run(verbose = True) # use the Postprocessor to analyze and save the results to the folder dates = start + datetime.timedelta(days = warmup), end postprocessor = Postprocessor(simplified, dates, comid = comid) postprocessor.get_hspexp_parameters(verbose = False) postprocessor.plot_hydrograph(tstep = 'monthly', show = False, output = '{}/hydrography'.format(output)) postprocessor.plot_calibration(output = '{}/statistics'.format(output),