Skip to content

Draft: Runoff duration hydrograph plotter

Draft: Runoff Duration Hydrograph Plotting

This was also fairly straightforward (which is good) due to leveraging of the previous functionality for regular streamflow duration hydrographs.

Same story as !27 (closed) with some refactoring to provide convenience functions plot_duration_hydrograph and plot_runoff_duration_hydrograph that provide relevant default axes labels and wrap a core function _base_duration_plotter.

Functional demo workflow

Need to figure out how to work up nicer examples and documentation. The below code works using the test "demo_weights.json" data.

# load weights matrix
weights = pd.read_json("demo_weights.json")

# get list of sites in MN geometry with non-zero weights
site_list = hyswap.runoff.identify_sites_from_weights("MN", weights)

# loop to construct df_list by fetching NWIS data and calculating runoff values
df_list = []
for site in site_list:
    # get site info
    info_df, _ = dataretrieval.nwis.get_info(sites=site)
    # convert drainage area from sq mi to sq km
    da = info_df['drain_area_va'][0] * 2.58998811
    # get streamflow data
    dv_df, _ = dataretrieval.nwis.get_dv(
        sites=site, parameterCd='00060',
        startDT='2000-01-01', endDT='2010-02-01'
    # calculate runoff
    ro_df = hyswap.runoff.streamflow_to_runoff(
        dv_df, '00060_Mean', da, frequency='daily')
    # append to df_list

# calculate the area-weighted runoff
runoff = hyswap.runoff.calculate_geometric_runoff(
    "MN", df_list, weights)

# convert to data frame
runoff_df = runoff.to_frame(name='runoff')

# calculate daily percentile thresholds
pdf = hyswap.percentiles.calculate_variable_percentile_thresholds_by_day(
    runoff_df, data_column_name='runoff')

# identify runoff values from the target year (to be plotted)
runoff_year = runoff_df[runoff_df.index.year == 2009]

# make the plot
fig, ax = plt.subplots(figsize=(10, 6))
ax = hyswap.plots.plot_duration_hydrograph(
    pdf, runoff_year, 'runoff', 'index_doy',
    ax=ax, data_label='2009'


This builds off of !27 (closed)

Edited by Hariharan, Jayaram Athreya

Merge request reports