Exemple #1
0
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]
staids = [wdm.get_attribute(wdmoutfile, n, 'STAID ') for n in dsns]

# find the dsn

n = [
    dsn for dsn, idcons, staid in zip(dsns, idconss, staids)
    if idcons == 'ROVOL' and staid == '101'
][0]

rovol = wdm.get_data(wdmoutfile, n)

# close up the fortran files.

wdm.close(wdmoutfile)
Exemple #2
0
# copy the data to the hspfmodel using WDMUtil. in general climate 
# data would need to come from some other place  (not a wdm file); 
# e.g., an NCDC file. the preprocessing modules can automate this
# for the hspexp example, only one timeseries for precip and evap 
# are provided. the file also contains the observed flow at the outlet. 
# this is set up to find the dsns, time steps etc, though if they were 
# known they could be provided directly.

# open the wdm for read access

wdm.open(f, 'r')

# find all the dsns

dsns = wdm.get_datasets(f)

# 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)
        print(('error: required data in {} do not exist!\n'.format(d)))
        raise

# use WDMUtil to read the BASINS data

wdm = WDMUtil(verbose=verbose)

# open the precipitation file and the other climate data file

wdm.open(f1, 'r')
wdm.open(f2, 'r')

# make a list of the datasets and numbers

dsns = wdm.get_datasets(f2)
tstypes = [wdm.get_attribute(f2, n, 'TSTYPE') for n in dsns]

# 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)
Exemple #4
0
        raise

    # find the path to the HSPF message file

    pyhspfdirectory = os.path.dirname(hspf.__file__)
    messagepath = '{}/pyhspf/core/hspfmsg.wdm'.format(pyhspfdirectory)

    # run the simulation

    hspf.hsppy(ucifile, messagepath)

    wdm = WDMUtil()

    wdm.open(wdmfile, 'r')

    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)
Exemple #5
0
        with open(p, 'rb') as f: hspfmodel = pickle.load(f)

        # calculate the runoff components in each land segment and store
        # the results in a structure as [subbasin][landuse][runoff/area]

        results = {}

        # use WDMUtil to read the data

        output = hspfmodel.filename + '_out.wdm'
        wdmutil = WDMUtil()
        wdmutil.open(output, 'r')

        # read the metadata for each timeseries in the WDM file

        dsns = wdmutil.get_datasets(output)    
        idconss = [wdmutil.get_attribute(output, n, 'IDCONS') for n in dsns]
        descrps = [wdmutil.get_attribute(output, n, 'DESCRP') for n in dsns]
        staids  = [wdmutil.get_attribute(output, n, 'STAID ') for n in dsns]

        # go through the impervious land segments to get the surface runoff

        for o in hspfmodel.implnds:

            c = o.subbasin
        
            # make a data dictionary for each subbasin
        
            results[c] = {}

            # make a data dictionary for the land use and add the area
Exemple #6
0
        raise

    # find the path to the HSPF message file

    pyhspfdirectory = os.path.dirname(hspf.__file__)
    messagepath = '{}/pyhspf/core/hspfmsg.wdm'.format(pyhspfdirectory)

    # run the simulation

    hspf.hsppy(ucifile, messagepath)

    wdm = WDMUtil()

    wdm.open(wdmfile, 'r')

    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)
        print('error: required data in {} do not exist!\n'.format(d))
        raise

# use WDMUtil to read the BASINS data

wdm = WDMUtil(verbose = verbose)

# open the precipitation file and the other climate data file

wdm.open(f1, 'r')
wdm.open(f2, 'r')

# make a list of the datasets and numbers

dsns    = wdm.get_datasets(f2)
tstypes = [wdm.get_attribute(f2, n, 'TSTYPE') for n in dsns]

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