コード例 #1
0
ファイル: intro06.py プロジェクト: Python3pkg/PyHSPF
def get_NSE(values):

    its = values['LZSN'], values['INFILT']
    print(('running simulation LZSN: {:.1f}, INFILT: {:.4f}\n'.format(*its)))

    # open the baseline HSPF model

    with open(model, 'rb') as f:
        hspfmodel = pickle.load(f)

    # change the filename to prevent two simultaneous runs with the same name

    its = working, values['LZSN'], values['INFILT']
    hspfmodel.filename = '{}/LZSN{:.1f}INFILT{:.4f}'.format(*its)

    # change the pan coefficient

    hspfmodel.evap_multiplier = 0.76

    # change the parameter values in all the land segments

    for p in hspfmodel.perlnds:
        p.LZSN = values['LZSN']
        p.INFILT = values['INFILT']

    # build the input WDM file

    hspfmodel.build_wdminfile()

    # build the UCI file (only need to save the reach_outvolume, ROVOL)

    hspfmodel.build_uci(['reach_outvolume'], start, end, hydrology=True)

    # run the simulation

    hspfmodel.run(verbose=True)

    # make an instance of the postprocessor to get the efficiency

    p = Postprocessor(hspfmodel, (start, end), comid=gagecomid)

    # the regressions between the simulated and observed flows can be
    # computed using the "regression" function that returns:
    #
    # daily r2, log daily r2, daily NSE, log daily NSE
    # montly r2, log monthly r2, monthly NSE, log monthly NSE

    dr2, dlr2, dNS, dlNS, mr2, mlr2, mNS, mlNS = p.get_regression(gagecomid)

    # close the Postprocessor

    p.close()

    return dNS
コード例 #2
0
ファイル: make_figure1.py プロジェクト: uiseokj/PyHSPF
def get_NSE(values):

    its = values['LZSN'], values['INFILT']
    print('running simulation LZSN: {:.0f}, INFILT: {:.2f}\n'.format(*its))

    # open the baseline HSPF model

    with open(filename, 'rb') as f:
        hspfmodel = pickle.load(f)

    # change the filename to prevent two simultaneous runs with the same name

    i = len(hspfmodel.filename) - 1
    while hspfmodel.filename[i] != '/':
        i -= 1

    path = hspfmodel.filename[:i]

    its = path, values['LZSN'], values['INFILT']
    hspfmodel.filename = '{}/LZSN{:.0f}INFILT{:.2f}'.format(*its)

    # change the parameter values in all the land segments

    for p in hspfmodel.perlnds:

        p.LZSN = values['LZSN']
        p.INFILT = values['INFILT']

    # build the input WDM file

    hspfmodel.build_wdminfile()

    # build the UCI file (only need to save the reach_outvolume, ROVOL)

    hspfmodel.build_uci(['reach_outvolume'],
                        start,
                        end,
                        atemp=atemp,
                        snow=snow,
                        hydrology=hydrology)

    # run the simulation

    hspfmodel.run(verbose=True)

    # calibration period

    dates = start + datetime.timedelta(days=warmup), end

    # find the common identifier for the NWIS gage

    d = {v: k for k, v in hspfmodel.subbasin_timeseries['flowgage'].items()}
    comid = d[gageid]

    # make an instance of the postprocessor to get the efficiency

    p = Postprocessor(hspfmodel, dates, comid=comid)

    # the regressions between the simulated and observed flows can be
    # computed using the "regression" function that returns:
    #
    # daily r2, log daily r2, daily NSE, log daily NSE
    # montly r2, log monthly r2, monthly NSE, log monthly NSE

    dr2, dlr2, dNS, dlNS, mr2, mlr2, mNS, mlNS = p.get_regression(comid)

    # close the Postprocessor

    p.close()

    return dNS
コード例 #3
0
ファイル: example05.py プロジェクト: MachineAi/PyHSPF
# open the postprocessor to get the calibration info

p = Postprocessor(hspfmodel, (start, end), comid = gagecomid) 

# calculate and show the errors in the calibration parameters. the product 
# of the daily log-flow and daily flow Nash-Sutcliffe model efficiency are 
# one possible optimization parameter for a calibration. the log-flow 
# captures relative errors (low-flow conditions) while the flow captures 
# absolute error (high-flow conditions).

p.calculate_errors()

# close the open files

p.close()

# now let's change the value of some parameters, re-run the model, and see 
# the effect on the calibration statistics. we will change the default
# values by perturbing some calibration multiplier parameter by a "factor."
# since the initial run has low storm volumes, flow should be shifted from 
# interflow to surface runoff by decreasing INTFW

LZETP_multiplier  = 1.    # lower zone evapotranspiration parameter
LZSN_multiplier   = 1.    # lower soil zone storage capacity
UZSN_multiplier   = 1.    # upper soil zone storage capacity
INTFW_multiplier  = 0.8   # interflow inflow rate
INFILT_multiplier = 1.    # infiltration rate
IRC_multiplier    = 1.    # interflow recession rate
evap_multiplier   = 0.76  # pan evaporation relative to potential ET
AGWRC             = 0.95  # groundwater recession rate (site-wide)
コード例 #4
0
    postprocessor.get_hspexp_parameters(verbose = False)
    postprocessor.plot_hydrograph(tstep = 'monthly', show = False,
                                  output = '{}/hydrography'.format(preliminary))
    postprocessor.plot_calibration(output = '{}/statistics'.format(preliminary),
                                   show = False)
    output = '{}/calibration_report.csv'.format(preliminary)
    postprocessor.calibration_report(output = output)
    postprocessor.plot_snow(output = '{}/snow'.format(preliminary), 
                            show = False)
    postprocessor.plot_dayofyear(output = '{}/dayofyear'.format(preliminary),
                                 show = False)

    # have to close the WDM files to continue
    
    postprocessor.close()

    # calibration using the full period of record

    # file path to place the calibrated model and results

    calibration = '{}/{}/calibration'.format(destination, HUC8)

    # path where the calibrated model will be saved/located

    calibrated = '{}/{}'.format(calibration, gageid)

    # make the directory for the calibration simulations

    if not os.path.isdir(calibration): os.mkdir(calibration)
コード例 #5
0
        postprocessor.plot_calibration(output = '{}/stats'.format(calibration),
                                       show = False)
        postprocessor.plot_runoff(tstep = 'daily', show = False,
                                  output = '{}/runoff'.format(calibration))
        output = '{}/calibration_report.csv'.format(calibration)
        postprocessor.calibration_report(output = output)
        postprocessor.plot_snow(output = '{}/snow'.format(calibration), 
                                show = False)
        postprocessor.plot_dayofyear(output ='{}/dayofyear'.format(calibration),
                                     show = False)
        postprocessor.plot_storms(season = 'all', show = False, 
                                  output = '{}/storms'.format(calibration))
    
        # have to close the WDM files to continue
    
        postprocessor.close()

        # run a validation simulation
        
        with open(calibrated, 'rb') as f: hspfmodel = pickle.load(f)

        # output variables

        targets = ['water_state', 
                   'reach_outvolume', 
                   'evaporation', 
                   'runoff', 
                   'groundwater',
                   ]

        # build the input WDM file
コード例 #6
0
ファイル: intro05.py プロジェクト: djibi2/PyHSPF
# open the postprocessor to get the calibration info

p = Postprocessor(hspfmodel, (start, end), comid = gagecomid) 

# calculate and show the errors in the calibration parameters. the product 
# of the daily log-flow and daily flow Nash-Sutcliffe model efficiency are 
# one possible optimization parameter for a calibration. the log-flow 
# captures relative errors (low-flow conditions) while the flow captures 
# absolute error (high-flow conditions).

p.calculate_errors()

# close the open files

p.close()

# now let's change the value of some parameters, re-run the model, and see 
# the effect on the calibration statistics. we will change the default
# values by perturbing some calibration multiplier parameter by a "factor."
# since the initial run has low storm volumes, flow should be shifted from 
# interflow to surface runoff by decreasing INTFW

LZETP_multiplier  = 1.    # lower zone evapotranspiration parameter
LZSN_multiplier   = 1.    # lower soil zone storage capacity
UZSN_multiplier   = 1.    # upper soil zone storage capacity
INTFW_multiplier  = 0.8   # interflow inflow rate
INFILT_multiplier = 1.    # infiltration rate
IRC_multiplier    = 1.    # interflow recession rate
evap_multiplier   = 0.76  # pan evaporation relative to potential ET
AGWRC             = 0.95  # groundwater recession rate (site-wide)
コード例 #7
0
ファイル: make_figure1.py プロジェクト: djlampert/PyHSPF
def get_NSE(values):

    its = values['LZSN'], values['INFILT']
    print('running simulation LZSN: {:.0f}, INFILT: {:.2f}\n'.format(*its))
    
    # open the baseline HSPF model

    with open(filename, 'rb') as f: hspfmodel = pickle.load(f)

    # change the filename to prevent two simultaneous runs with the same name

    i = len(hspfmodel.filename) - 1
    while hspfmodel.filename[i] != '/': i -= 1

    path = hspfmodel.filename[:i]
    
    its = path, values['LZSN'], values['INFILT']
    hspfmodel.filename = '{}/LZSN{:.0f}INFILT{:.2f}'.format(*its)
                              
    # change the parameter values in all the land segments

    for p in hspfmodel.perlnds:

        p.LZSN   = values['LZSN']
        p.INFILT = values['INFILT']

    # build the input WDM file
        
    hspfmodel.build_wdminfile()

    # build the UCI file (only need to save the reach_outvolume, ROVOL)
        
    hspfmodel.build_uci(['reach_outvolume'], start, end, atemp = atemp,
                        snow = snow, hydrology = hydrology)

    # run the simulation

    hspfmodel.run(verbose = True)

    # calibration period

    dates = start + datetime.timedelta(days = warmup), end

    # find the common identifier for the NWIS gage

    d = {v:k for k, v in hspfmodel.subbasin_timeseries['flowgage'].items()}
    comid = d[gageid]

    # make an instance of the postprocessor to get the efficiency
        
    p = Postprocessor(hspfmodel, dates, comid = comid)

    # the regressions between the simulated and observed flows can be
    # computed using the "regression" function that returns:
    #
    # daily r2, log daily r2, daily NSE, log daily NSE
    # montly r2, log monthly r2, monthly NSE, log monthly NSE
        
    dr2, dlr2, dNS, dlNS, mr2, mlr2, mNS, mlNS = p.get_regression(comid)

    # close the Postprocessor

    p.close()

    return dNS