Exemplo n.º 1
0
def postprocess():
    """Postprocess the results and save."""

    print('saving the calibration results\n')

    # open the calibrated model

    with open(calibrated, 'rb') as f:
        hunting = pickle.load(f)

    # external targets for calibration

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

    # build the HSPF input files

    hunting.build_wdminfile()
    hunting.build_uci(targets, start, end, hydrology=True)

    # run it

    hunting.run(verbose=True)

    # create a postprocessor to analyze the results

    postprocessor = Postprocessor(hunting, (start, end))

    # make a report of the calibration

    report = '{}/calibration_report.csv'.format(hspf)
    postprocessor.get_hspexp_parameters(verbose=False)
    postprocessor.get_calibration()
    postprocessor.calculate_errors(output=report, verbose=False)

    # plot the daily hydrograph

    hydrograph = '{}/dailyhydrograph'.format(hspf)
    postprocessor.plot_hydrograph(tstep='daily', output=hydrograph, show=False)

    # plot the monthly hydrograph

    hydrograph = '{}/monthlyhydrograph'.format(hspf)
    postprocessor.plot_hydrograph(tstep='monthly',
                                  output=hydrograph,
                                  show=False)

    # plot the calibration

    calibration_graph = '{}/calibration'.format(hspf)
    postprocessor.plot_calibration(output=calibration_graph, show=False)
Exemplo n.º 2
0
def validate(directory, HUC8, NWISgage, start, end, temp = True,
             snow = True, hydrology = True, warmup = 1, upcomids = []):

    run_dates     = (datetime.datetime(start, 1, 1),
                     datetime.datetime(end, 1, 1))

    process_dates = (datetime.datetime(start + warmup, 1, 1),
                     datetime.datetime(end, 1, 1))

    f      = '{}/{}/calibrations/{}/hspfmodel'.format(directory, HUC8, NWISgage)
    folder = '{}/{}/validations/{}'.format(directory, HUC8, NWISgage)

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

    # figure out the external targets needed

    targets = ['reach_outvolume', 'groundwater', 'water_state', 
               'evaporation', 'runoff', 'snow_state', 'snowpack', 
               'snowfall']

    # build the input wdmfile

    hspfmodel.build_wdminfile()

    # create the UCI file and the output WDM file

    hspfmodel.build_uci(targets, run_dates[0], run_dates[1], temp = temp,
                        snow = snow, hydrology = hydrology)

    hspfmodel.messagepath = None

    # run it

    hspfmodel.run(verbose = True)

    # add the simulation parameters to the calibrator

    postprocessor = Postprocessor(hspfmodel, process_dates)

    # calculate the errors and make a calibration report

    postprocessor.get_hspexp_parameters(verbose = False)
    postprocessor.get_calibration(verbose = False, vverbose = False)

    # plot everything and save to file

    if not os.path.isdir('{}/{}/validations'.format(directory, HUC8)):
        os.mkdir('{}/{}/validations'.format(directory, HUC8))
    if not os.path.isdir(folder): os.mkdir(folder)

    output  = folder + '/calibration_report.csv'
    postprocessor.calculate_errors(verbose = False, output = output)

    output  = folder + '/snow'
    postprocessor.plot_snow(output = output, show = False)

    output  = folder + '/snowcalibration'
    postprocessor.plot_snowcalibration(output = output, show = False)

    output  = folder + '/monthlyhydrograph'
    postprocessor.plot_hydrograph(output = output, show = False)

    output  = folder + '/dayofyear'
    postprocessor.plot_dayofyear(output = output, show = False)

    output  = folder + '/averagewaterbudget'
    postprocessor.plot_waterbudget(output = output, show = False)

    output  = folder + '/waterbudgets'
    postprocessor.plot_allwaterbudgets(output = output, show = False)

    output  = folder + '/runoff'
    postprocessor.plot_runoff(output = output, show = False)

    output  = folder + '/storms'
    postprocessor.plot_storms(output = output, show = False)

    output  = folder + '/calibration'
    postprocessor.plot_calibration(output = output, show = False)

    postprocessor.close()
Exemplo n.º 3
0
def postprocess():

    # open the calibrated model

    with open(calibrated, 'rb') as f: hunting = pickle.load(f)

    # external targets for calibration

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

    # build the HSPF input files

    hunting.build_wdminfile()
    hunting.build_uci(targets, start, end, hydrology = True)

    # run it

    hunting.run(verbose = True)

    # create a postprocessor to analyze the results

    postprocessor = Postprocessor(hunting, (start, end))

    # make a report of the calibration

    report = '{}/calibration_report.csv'.format(hspf)
    postprocessor.get_hspexp_parameters(verbose = False)
    postprocessor.get_calibration()
    postprocessor.calculate_errors(output = report, verbose = False)

    # plot the daily hydrograph

    hydrograph = '{}/dailyhydrograph'.format(hspf)
    postprocessor.plot_hydrograph(tstep = 'daily', output = hydrograph, 
                                  show = False)

    # plot the monthly hydrograph

    hydrograph = '{}/monthlyhydrograph'.format(hspf)
    postprocessor.plot_hydrograph(tstep = 'monthly', output = hydrograph, 
                                  show = False)

    # plot the calibration

    calibration_graph = '{}/calibration'.format(hspf)
    postprocessor.plot_calibration(output = calibration_graph, show = False)

    # storm events from HSPExp file (for plotting)

    storms = [[datetime.datetime(1989, 2, 20), datetime.datetime(1989, 2, 26)],
              [datetime.datetime(1989, 5,  1), datetime.datetime(1989, 5,  5)],
              [datetime.datetime(1989, 6,  6), datetime.datetime(1989, 6, 11)],
              [datetime.datetime(1989, 9, 25), datetime.datetime(1989, 9, 29)],
              [datetime.datetime(1989,10,  1), datetime.datetime(1989,10,  5)],
              [datetime.datetime(1989,12, 31), datetime.datetime(1990, 1,  5)],
              [datetime.datetime(1990, 1, 25), datetime.datetime(1990, 1, 30)],
              [datetime.datetime(1990, 5,  4), datetime.datetime(1990, 5,  8)],
              [datetime.datetime(1990, 5, 28), datetime.datetime(1990, 6,  1)],
              [datetime.datetime(1990, 6, 15), datetime.datetime(1990, 6, 18)],
              ]

    # plot the storm events

    storm_plots = '{}/storms'.format(hspf)
    postprocessor.plot_storms(stormdates = storms, output = storm_plots, 
                              tstep = 'hourly', show = False)
Exemplo n.º 4
0
def validate(directory, HUC8, NWISgage, start, end, temp=True, snow=True, hydrology=True, warmup=1, upcomids=[]):

    run_dates = (datetime.datetime(start, 1, 1), datetime.datetime(end, 1, 1))

    process_dates = (datetime.datetime(start + warmup, 1, 1), datetime.datetime(end, 1, 1))

    f = "{}/{}/calibrations/{}/hspfmodel".format(directory, HUC8, NWISgage)
    folder = "{}/{}/validations/{}".format(directory, HUC8, NWISgage)

    with open(f, "rb") as m:
        hspfmodel = pickle.load(m)

    # figure out the external targets needed

    targets = [
        "reach_outvolume",
        "groundwater",
        "water_state",
        "evaporation",
        "runoff",
        "snow_state",
        "snowpack",
        "snowfall",
    ]

    # build the input wdmfile

    hspfmodel.build_wdminfile()

    # create the UCI file and the output WDM file

    hspfmodel.build_uci(targets, run_dates[0], run_dates[1], temp=temp, snow=snow, hydrology=hydrology)

    hspfmodel.messagepath = None

    # run it

    hspfmodel.run(verbose=True)

    # add the simulation parameters to the calibrator

    postprocessor = Postprocessor(hspfmodel, process_dates)

    # calculate the errors and make a calibration report

    postprocessor.get_hspexp_parameters(verbose=False)
    postprocessor.get_calibration(verbose=False, vverbose=False)

    # plot everything and save to file

    if not os.path.isdir("{}/{}/validations".format(directory, HUC8)):
        os.mkdir("{}/{}/validations".format(directory, HUC8))
    if not os.path.isdir(folder):
        os.mkdir(folder)

    output = folder + "/calibration_report.csv"
    postprocessor.calculate_errors(verbose=False, output=output)

    output = folder + "/snow"
    postprocessor.plot_snow(output=output, show=False)

    output = folder + "/snowcalibration"
    postprocessor.plot_snowcalibration(output=output, show=False)

    output = folder + "/monthlyhydrograph"
    postprocessor.plot_hydrograph(output=output, show=False)

    output = folder + "/dayofyear"
    postprocessor.plot_dayofyear(output=output, show=False)

    output = folder + "/averagewaterbudget"
    postprocessor.plot_waterbudget(output=output, show=False)

    output = folder + "/waterbudgets"
    postprocessor.plot_allwaterbudgets(output=output, show=False)

    output = folder + "/runoff"
    postprocessor.plot_runoff(output=output, show=False)

    output = folder + "/storms"
    postprocessor.plot_storms(output=output, show=False)

    output = folder + "/calibration"
    postprocessor.plot_calibration(output=output, show=False)

    postprocessor.close()
Exemplo n.º 5
0
def postprocess():

    # open the calibrated model

    with open(calibrated, "rb") as f:
        hunting = pickle.load(f)

    # external targets for calibration

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

    # build the HSPF input files

    hunting.build_wdminfile()
    hunting.build_uci(targets, start, end, hydrology=True)

    # run it

    hunting.run(verbose=True)

    # create a postprocessor to analyze the results

    postprocessor = Postprocessor(hunting, (start, end))

    # make a report of the calibration

    report = "{}/calibration_report.csv".format(hspf)
    postprocessor.get_hspexp_parameters(verbose=False)
    postprocessor.get_calibration()
    postprocessor.calculate_errors(output=report, verbose=False)

    # plot the daily hydrograph

    hydrograph = "{}/dailyhydrograph".format(hspf)
    postprocessor.plot_hydrograph(tstep="daily", output=hydrograph, show=False)

    # plot the monthly hydrograph

    hydrograph = "{}/monthlyhydrograph".format(hspf)
    postprocessor.plot_hydrograph(tstep="monthly", output=hydrograph, show=False)

    # plot the calibration

    calibration_graph = "{}/calibration".format(hspf)
    postprocessor.plot_calibration(output=calibration_graph, show=False)

    # storm events from HSPExp file (for plotting)

    storms = [
        [datetime.datetime(1989, 2, 20), datetime.datetime(1989, 2, 26)],
        [datetime.datetime(1989, 5, 1), datetime.datetime(1989, 5, 5)],
        [datetime.datetime(1989, 6, 6), datetime.datetime(1989, 6, 11)],
        [datetime.datetime(1989, 9, 25), datetime.datetime(1989, 9, 29)],
        [datetime.datetime(1989, 10, 1), datetime.datetime(1989, 10, 5)],
        [datetime.datetime(1989, 12, 31), datetime.datetime(1990, 1, 5)],
        [datetime.datetime(1990, 1, 25), datetime.datetime(1990, 1, 30)],
        [datetime.datetime(1990, 5, 4), datetime.datetime(1990, 5, 8)],
        [datetime.datetime(1990, 5, 28), datetime.datetime(1990, 6, 1)],
        [datetime.datetime(1990, 6, 15), datetime.datetime(1990, 6, 18)],
    ]

    # plot the storm events

    storm_plots = "{}/storms".format(hspf)
    postprocessor.plot_storms(stormdates=storms, output=storm_plots, tstep="hourly", show=False)