Skip to content

Draft: Cumulative runoff plotter

Hariharan, Jayaram Athreya requested to merge cumulative-runoff-plotter into main

Draft: Cumulative Runoff Hydrograph Plotting

This ended up being fairly straightforward when leveraging the previous functionality for making cumulative hydrographs.

I am doing some refactoring of the plotting functions to split out the core functionality from plot_cumulative_hydrograph into a function _base_cumulative_plotter that is wrapped and called by both plot_cumulative_hydrograph and the new plot_cumulative_runoff_hydrograph that are essentially convenience functions with appropriate default axes labels.


Functional demo workflow

Need to work up some sort of examples and documentation for the cumulative runoff hydrograph, the below code works using the test "demo_weights.json" data. The involved portion is the fetching of data and calculation of runoff to create the list of dataframes, and this is probably where having a multitude of examples covering difference cases, averaging schemes, and runoff calculations will be useful.

# 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
    df_list.append(ro_df)

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

# calculate the cumulative yearly values (same as what we do for streamflow)
cdf = hyswap.cumulative.calculate_daily_cumulative_values(
    runoff_df, "runoff")

# make the plot
fig, ax = plt.subplots(figsize=(12, 6))
ax = hyswap.plots.plot_cumulative_runoff_hydrograph(cdf, 2009, ax=ax,
                                                    min_pct=True,
                                                    max_pct=True)

image


This builds off of !26 (merged)

Edited by Hariharan, Jayaram Athreya

Merge request reports

Loading