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

start, end = wdm.get_dates(f, precip_dsn)

evap = wdm.get_data(f, evap_dsn, start = start, end = end)
Exemple #2
0
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. the attributes that identify the data are "IDCONS"
# (constituent ID) and "STAID " (station ID). these were assigned by the
# build_wdminfile and build_uci routines automatically; they can be modified
# as needed. the attributes always have six characters so make sure to add 
# trailing spaces.

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]

# uncomment this line to see what's here in the output file

# print(dsns, idconss, staids)

# one HSPF parameter we saved is ROVOL (PyHSPF has a Postprocessor that can 
# be used to simplify this, but WDMUtil can also be used more directly). 
# The following statement finds the dataset number for the ROVOL timeseries
# for the reach for subbasin 101.

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

# get the data for the reach volume flux dataset
Exemple #3
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)
        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)
tstypes = [wdm.get_attribute(f1, n, 'TSTYPE') for n in dsns]
Exemple #5
0
        # 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
# 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)

start, end = wdm.get_dates(f, precip_dsn)

evap = wdm.get_data(f, evap_dsn, start=start, end=end)
        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)
tstypes = [wdm.get_attribute(f1, n, 'TSTYPE') for n in dsns]
Exemple #8
0
import pandas as pd
import csv, os, datetime, numpy
from matplotlib import pyplot as plt
from pyhspf import HSPFModel, WDMUtil, Postprocessor

messagepath = 'hspfmsg.wdm'

wdm = WDMUtil(verbose=True, messagepath=messagepath)

# EXTRACT MODELED FLOWS FROM WDM OUTPUT FILE AND COMPARE TO
wdmFile = 'siletz_river_out.wdm'

wdm.open(wdmFile, 'r')

dsns = wdm.get_datasets(wdmFile)
idcons = [wdm.get_attribute(wdmFile, n, 'IDCONS') for n in dsns]
staids = [wdm.get_attribute(wdmFile, n, 'STAID ') for n in dsns]

pars = [dsns, idcons, staids]

dsnBas1 = [
    dsns for dsns, idcons, staid in zip(dsns, idconss, staids) if staid == '1'
]  # These are the dsns for all Basin 1 outputs

indBas1 = [dsn - 1
           for dsn in dsnBas1]  # These are element indeces for Basin 1 dsns

start = datetime.datetime(2012, 1, 1)
end = datetime.datetime(2013, 1, 1)

dttm = [