# 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 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']
# specify the time series type tstype = 'evaporation' # give the dataset a unique identifier identifier = 'example_evap' # finally need the start date, a list of the data, and the time step (min) hspfmodel.add_timeseries(tstype, identifier, start, evaporation, tstep=tstep) # assign the time series for this model hspfmodel.assign_watershed_timeseries(tstype, identifier) # add some random rainfall rainfall = [ random.randint(0, 20) if random.random() > 0.95 else 0. for i in range(nsteps) ] # assign the precipitation time series to the file tstype = 'precipitation' identifier = 'example_prec' hspfmodel.add_timeseries(tstype, identifier, start, rainfall, tstep=tstep)
# give the dataset a unique identifier identifier = 'example_evap' # finally need the start date, a list of the data, and the time step (min) hspfmodel.add_timeseries(tstype, identifier, start, evaporation, tstep = tstep) # now tell HSPF how to use the time series for this model. the unique # identifier for the time series and the unique subbasin numbers are used # to make this connection. we will assign this time series to the whole # watershed, although you can have a unique time series for each subbasin, # landuse category, or each operation if you want. hspfmodel.assign_watershed_timeseries(tstype, identifier) # now add some random rainfall. here it is assumed there is a 5% chance of rain # every 4-hour period and that the rainfall is an integer between 0 and 20. import random # make random numbers for each 4 hour timestep # if the number is greater than 0.95 (5% chance), let's say it's raining and # assign a value (this should give about a meter of rain per year) rainfall = [random.randint(0,20) if random.random() > 0.95 else 0. for i in range(nsteps)] # assign the precipitation time series to the file
d = { v: k for k, v in list(hspfmodel.subbasin_timeseries['flowgage'].items()) } comid = d[gageid] s, tstep, data = hspfmodel.flowgages[gageid] simplified.add_timeseries('flowgage', gageid, s, data, tstep=tstep) simplified.assign_subbasin_timeseries('flowgage', comid, gageid) # add and assign the snowfall and snowdepth from the old model s, tstep, data = hspfmodel.snowdepths[HUC8] simplified.add_timeseries('snowdepth', HUC8, s, data, tstep=tstep) simplified.assign_watershed_timeseries('snowdepth', HUC8) s, tstep, data = hspfmodel.snowfalls[HUC8] simplified.add_timeseries('snowfall', HUC8, s, data, tstep=tstep) simplified.assign_watershed_timeseries('snowfall', HUC8) # add other time series to the model and assign them to the whole watershed # note that the first year from the PyHSPF data is used for the warmup # since the BASINS station data are incomplete name = 'precipitation' data = [p for p in pavg[:cutoff]] + [p * 25.4 for p in prec] simplified.add_timeseries(name, 'simplified', start, data) simplified.assign_watershed_timeseries(name, 'simplified') name = 'evaporation'
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') hspfmodel.assign_watershed_timeseries('evaporation', 'hunting_evap') # assign the flowgage to the subbasin 30 (the outlet) hspfmodel.assign_subbasin_timeseries('flowgage', '30', 'hunting_flow') # this simulation used the hydrology modules (and no others); need to set the # operations for the watershed and default values for the hydrology parameters hspfmodel.add_hydrology() # this example will stop here by pickling the hspfmodel for later--since the # model will be run many times it just makes sense to save the work so far # before moving on.
# find the comid of the gage and add the flow data to the new model d = {v:k for k, v in hspfmodel.subbasin_timeseries['flowgage'].items()} comid = d[gageid] s, tstep, data = hspfmodel.flowgages[gageid] simplified.add_timeseries('flowgage', gageid, s, data, tstep = tstep) simplified.assign_subbasin_timeseries('flowgage', comid, gageid) # add and assign the snowfall and snowdepth from the old model s, tstep, data = hspfmodel.snowdepths[HUC8] simplified.add_timeseries('snowdepth', HUC8, s, data, tstep = tstep) simplified.assign_watershed_timeseries('snowdepth', HUC8) s, tstep, data = hspfmodel.snowfalls[HUC8] simplified.add_timeseries('snowfall', HUC8, s, data, tstep = tstep) simplified.assign_watershed_timeseries('snowfall', HUC8) # add other time series to the model and assign them to the whole watershed # note that the first year from the PyHSPF data is used for the warmup # since the BASINS station data are incomplete name = 'precipitation' data = [p for p in pavg[:cutoff]] + [p * 25.4 for p in prec] simplified.add_timeseries(name, 'simplified', start, data) simplified.assign_watershed_timeseries(name, 'simplified') name = 'evaporation'