watershed.add_mass_linkage(updown) watershed.add_outlet('101') # names of the files used in the simulation (the HSPF input and output files # are generated automatically); can also specify a directory to use elsewhere filename = 'example06' wdmoutfile = filename + '_out.wdm' # create an instance of the HSPFModel class hspfmodel = HSPFModel() # and build the model from the watershed hspfmodel.build_from_watershed(watershed, filename, tstep=tstep) # add a special action, thawed ground on the agricultural land # in the first subbasin on April 1 at 12 noon. thawdate = datetime.datetime(2001, 4, 1, 12) hspfmodel.add_special_action('thaw', '100', 'Agriculture', thawdate) # add another special action, frozen ground on the agricultural land # in the first subbasin on December 1 at midnight. freezedate = datetime.datetime(2001, 12, 1) hspfmodel.add_special_action('frozen', '100', 'Agriculture', freezedate)
# 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))] # build the model (file will all be called example02) hspfmodel.build_from_watershed(watershed, 'example02', ifraction = ifraction, tstep = tstep) # now add the time series to the model hspfmodel.add_timeseries('precipitation', 'hunting_prec', start, precip, tstep = tstep) hspfmodel.add_timeseries('evaporation', 'hunting_evap', start, evap, tstep = tstep) # and assign the time series to all the operations in the watershed hspfmodel.assign_watershed_timeseries('precipitation', 'hunting_prec') hspfmodel.assign_watershed_timeseries('evaporation', 'hunting_evap') # this simulation used the hydrology modules (and no others); need to create the # operations for the model and the default values for the hydrology parameters
# model filename + '_in.wdm' for the input WDM file and '_out.wdm' for the # output file (we'll need this later to retrieve results from the files) wdmoutfile = filename + '_out.wdm' # let's also generate an optional output file created by HSPF directly outfile = filename + '.out' # create an instance of the HSPFModel class hspfmodel = HSPFModel() # and build the model from the watershed hspfmodel.build_from_watershed(watershed, filename, print_file = outfile, tstep = tstep) # to run a simulation it is necessary to assign precipitation, potential # evapotranspiration, and any other time series to the subbasins. # there are many different ways to estimate the potential evapotranspiration # including correlation to observed pan evaporation, Penman-Monteith, etc. # here the potential evapotranspiration is assumed to start at zero then # increase to 12 mm in a day 7/01, then decreases to zero 1/01; thus max 4-hr # potential evapotranspiration is 2 mm. the following statement will generate # a time series with these assumptions. maxET = 2 nsteps = (end-start).days * 1440 // tstep evaporation = [maxET * (d - datetime.datetime(d.year, 1, 1)).days / (datetime.datetime(d.year, 7, 1) - datetime.datetime(d.year, 1, 1)).days
watershedSiletz.add_outlet(str(basin + 1)) # Assumes basin numbers x = 1 # Don't need this but the loop wants to include 'hspfmodel...' # Build the model hspfmodel = HSPFModel(units='Metric') filename = 'siletz_river' outfile = filename + '.out' wdmoutfile = filename + '_out.wdm' hspfmodel.build_from_watershed(watershedSiletz, 'siletz_river', ifraction=ifraction, tstep=tstep, print_file=outfile) watershedSiletz.plot_mass_flow(output='siletz_basin_network') # ADD TIME SERIES DATA: PRECIP, PET, and FLOW TO THE WDM FILE pcpData = pd.read_csv( os.path.abspath(os.path.curdir) + '\\siletz_HSPF_precip.csv') petData = pd.read_csv( os.path.abspath(os.path.curdir) + '\\siletz_HSPF_pet.csv') flwData = pd.read_csv( os.path.abspath(os.path.curdir) + '\\siletz_HSPF_flw.csv')
watershed.add_mass_linkage(updown) watershed.add_outlet('101') # names of the files used in the simulation (the HSPF input and output files # are generated automatically); can also specify a directory to use elsewhere filename = 'example06' wdmoutfile = filename + '_out.wdm' # create an instance of the HSPFModel class hspfmodel = HSPFModel() # and build the model from the watershed hspfmodel.build_from_watershed(watershed, filename, tstep = tstep) # add a special action, thawed ground on the agricultural land # in the first subbasin on April 1 at 12 noon. thawdate = datetime.datetime(2001, 4, 1, 12) hspfmodel.add_special_action('thaw', '100', 'Agriculture', thawdate) # add another special action, frozen ground on the agricultural land # in the first subbasin on December 1 at midnight. freezedate = datetime.datetime(2001, 12, 1) hspfmodel.add_special_action('frozen', '100', 'Agriculture', freezedate)
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 times = [start + (end - start) / len(precip) * i for i in range(len(precip))] # make the HSPFModel instance hspfmodel = HSPFModel(units='English') # build the model (file will all be called example03) hspfmodel.build_from_watershed(watershed, 'example03', ifraction=ifraction, tstep=tstep) # now add the time series to the model hspfmodel.add_timeseries('precipitation', 'hunting_prec', start, precip, tstep=60) hspfmodel.add_timeseries('evaporation', 'hunting_evap', start, evap, tstep=60) hspfmodel.add_timeseries('flowgage', 'hunting_flow', start, oflow, tstep=60) # and assign the watershed time series to all the operations hspfmodel.assign_watershed_timeseries('precipitation', 'hunting_prec')
# output file (we'll need this later to retrieve results from the files) wdmoutfile = filename + '_out.wdm' # let's also generate an optional output file created by HSPF directly outfile = filename + '.out' # create an instance of the HSPFModel class hspfmodel = HSPFModel() # and build the model from the watershed hspfmodel.build_from_watershed(watershed, filename, print_file=outfile, tstep=tstep) # to run a simulation it is necessary to assign precipitation, potential # evapotranspiration, and any other time series to the subbasins. # there are many different ways to estimate the potential evapotranspiration # including correlation to observed pan evaporation, Penman-Monteith, etc. # here the potential evapotranspiration is assumed to start at zero then # increase to 12 mm in a day 7/01, then decreases to zero 1/01; thus max 4-hr # potential evapotranspiration is 2 mm. the following statement will generate # a time series with these assumptions. maxET = 2 nsteps = (end - start).days * 1440 // tstep evaporation = [ maxET * (d - datetime.datetime(d.year, 1, 1)).days /