Esempio n. 1
0
    (datetime.datetime(d.year + 1, 1, 1) -
     datetime.datetime(d.year, 7, 1)).days for d in
    [start + datetime.timedelta(minutes=tstep) * i for i in range(nsteps)]
]

# 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'
Esempio n. 2
0
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

hspfmodel.add_hydrology()

# build the input wdm file
Esempio n. 3
0
    # actions, and reach network from the old file but contains no time series
    # or time series assignments

    simplified.build_from_existing(hspfmodel, newmodel)

    # find the comid of the gage and add the flow data to the new model

    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
Esempio n. 4
0
                datetime.datetime(d.year, 7, 1)).days
               for d in [start + datetime.timedelta(minutes = tstep) * i
                         for i in range(nsteps)]
               ]

# 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)

# 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
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,
                             tstep=tstep)

    hspfmodel.add_timeseries('evaporation', ('evap_' + str(x)),
                             start,
                             evap,
                             tstep=tstep)

    # Assign to specific basin
    hspfmodel.assign_subbasin_timeseries('precipitation', str(basin + 1),
                                         ('prcp_' + str(x)))

    hspfmodel.assign_subbasin_timeseries('evaporation', str(basin + 1),
                                         ('evap_' + str(x)))

    x += 1
Esempio n. 6
0
# 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')
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
Esempio n. 7
0
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
Esempio n. 8
0
    # build new model parameters from the base model; the build_from_existing
    # method can be used to copy the perlnds, implnds, rchreses, special 
    # actions, and reach network from the old file but contains no time series
    # or time series assignments

    simplified.build_from_existing(hspfmodel, newmodel)

    # 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
Esempio n. 9
0
# 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')
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