Skip to content

Commit

Permalink
Update 8 files
Browse files Browse the repository at this point in the history
- /site_conditions_examples.ipynb
- /regional_runoff_calculations.ipynb
- /single_gage_n_day_flows_analysis.ipynb
- /single_gage_analysis.ipynb
- /example_notebooks/site_conditions_examples.ipynb
- /example_notebooks/regional_runoff_calculations.ipynb
- /example_notebooks/single_gage_n_day_flows_analysis.ipynb
- /example_notebooks/single_gage_analysis.ipynb
  • Loading branch information
jzemmels committed Jun 29, 2024
1 parent 1e9f88f commit b96b09e
Show file tree
Hide file tree
Showing 8 changed files with 387 additions and 2,337 deletions.
204 changes: 115 additions & 89 deletions example_notebooks/regional_runoff_calculations.ipynb

Large diffs are not rendered by default.

126 changes: 69 additions & 57 deletions example_notebooks/single_gage_analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"## Download streamflow data from USGS NWIS for an example site \n",
"For demonstration purposes, retrieving data for gage 04288000 - MAD RIVER AT MORETOWN, VT.\n",
"\n",
"Users can identify streamflow gage locations and site ID numbers through the [USGS National Water Dashboard](https://dashboard.waterdata.usgs.gov/app/nwd/en/)"
"Users can identify streamflow gage locations and site ID numbers through the [USGS National Water Dashboard](https://dashboard.waterdata.usgs.gov/app/nwd/en/)."
]
},
{
Expand All @@ -51,8 +51,11 @@
"outputs": [],
"source": [
"StaID = '04288000'\n",
"flow_data = nwis.get_record(sites=StaID, parameterCd='00060', start='1900-01-01', service='dv')\n",
"station_name = nwis.get_record(sites=StaID, service='site').loc[0, 'station_nm']"
"flow_data = nwis.get_record(sites = StaID, \n",
" parameterCd = '00060', \n",
" start = '1900-01-01', \n",
" service = 'dv')\n",
"station_name = nwis.get_record(sites = StaID, service = 'site').loc[0, 'station_nm']"
]
},
{
Expand All @@ -66,7 +69,8 @@
" flow_data['00060_Mean'] = flow_data['00060_Mean'].replace(-999999, np.nan)\n",
"\n",
" # create a filtered version of data of only USGS approved data (quality-assured data that may be published and used in statistical analsysis)\n",
" approved_flow_data = hyswap.utils.filter_approved_data(flow_data, '00060_Mean_cd')\n",
" approved_flow_data = hyswap.utils.filter_approved_data(data = flow_data, \n",
" filter_column = '00060_Mean_cd')\n",
"else:\n",
" print('No standard discharge data column found for site ' + StaID + ', suggest using a different site')"
]
Expand Down Expand Up @@ -98,7 +102,7 @@
"plot_start = \"2010-10-01\"\n",
"plot_end = \"2011-09-30\"\n",
"\n",
"fig, ax = plt.subplots(figsize=(9,4))\n",
"fig, ax = plt.subplots(figsize = (9,4))\n",
"ax = hyswap.plot_hydrograph(flow_data, \n",
" data_col = \"00060_Mean\", \n",
" start_date = plot_start,\n",
Expand All @@ -112,7 +116,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Next, try changing the plot to not have log scale on the y-axis"
"Next, try changing the plot to not have log scale on the y-axis."
]
},
{
Expand All @@ -122,12 +126,12 @@
"outputs": [],
"source": [
"#| fig-cap: Sample HySwap hydrograph plot\n",
"fig, ax = plt.subplots(figsize=(9,4))\n",
"fig, ax = plt.subplots(figsize = (9,4))\n",
"hyswap.plot_hydrograph(flow_data, \n",
" data_col = \"00060_Mean\", \n",
" start_date=plot_start,\n",
" end_date=plot_end,\n",
" title=f\"Hydrograph for {StaID} - {station_name}\",\n",
" start_date = plot_start,\n",
" end_date = plot_end,\n",
" title = f\"Hydrograph for {StaID} - {station_name}\",\n",
" yscale = 'linear',\n",
" ax = ax)\n",
"plt.show()"
Expand All @@ -137,7 +141,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Now test doing some plot customizations including axis labels, colors, plot style"
"Now test doing some plot customizations including axis labels, colors, plot style."
]
},
{
Expand All @@ -148,18 +152,18 @@
"source": [
"#| fig-cap: Sample HySwap hydrograph plot with customized appearance\n",
"plot_start = \"2021-10-01\"\n",
"fig, ax = plt.subplots(figsize=(12,4))\n",
"fig, ax = plt.subplots(figsize = (12,4))\n",
"ax = hyswap.plot_hydrograph(flow_data, \n",
" data_col = \"00060_Mean\", \n",
" start_date=plot_start,\n",
" title=f\"Hydrograph for {StaID} - {station_name}\",\n",
" start_date = plot_start,\n",
" title = f\"Hydrograph for {StaID} - {station_name}\",\n",
" yscale = 'linear',\n",
" ylab = 'Streamflow (cfs)',\n",
" xlab = '',\n",
" color = '#360919',\n",
" ax = ax)\n",
"ax.grid(which = \"major\", axis=\"y\", lw = 1.5)\n",
"ax.grid(which = \"minor\", axis=\"y\", linestyle = \"dashed\")\n",
"ax.grid(which = \"major\", axis = \"y\", lw = 1.5)\n",
"ax.grid(which = \"minor\", axis = \"y\", linestyle = \"dashed\")\n",
"ax.minorticks_on()\n",
"plt.show()"
]
Expand All @@ -169,7 +173,7 @@
"metadata": {},
"source": [
"## Analyze the long-term record of streamflow\n",
"Review summary statistics and flow records using raster hydrographs"
"Review summary statistics and flow records using raster hydrographs."
]
},
{
Expand All @@ -179,7 +183,7 @@
"outputs": [],
"source": [
"# calcualte summary statistics on only approved data (quality-assured data that may be published and used in statistical analsysis)\n",
"summary_stats = hyswap.calculate_summary_statistics(approved_flow_data)"
"summary_stats = hyswap.calculate_summary_statistics(df = approved_flow_data)"
]
},
{
Expand All @@ -196,8 +200,8 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"To view long-term patterns and trends in streamflow, raster hydrographs can be plotted using `hyswap`\n",
"Here, let's utilize a raster hydrograph to see the historical flow at the site from the pst 50 years (1973-2023)"
"To view long-term patterns and trends in streamflow, raster hydrographs can be plotted using `hyswap`.\n",
"Here, let's utilize a raster hydrograph to see the historical flow at the site from the pst 50 years (1973-2023)."
]
},
{
Expand All @@ -207,7 +211,11 @@
"outputs": [],
"source": [
"# format the data\n",
"df_formatted = hyswap.rasterhydrograph.format_data(flow_data, '00060_Mean', year_type=\"calendar\", begin_year=1973, end_year=2023)"
"df_formatted = hyswap.rasterhydrograph.format_data(df = flow_data, \n",
" data_column_name = '00060_Mean', \n",
" year_type = \"calendar\", \n",
" begin_year = 1973, \n",
" end_year = 2023)"
]
},
{
Expand All @@ -218,11 +226,11 @@
"source": [
"#| fig-cap: Sample raster hydrograph showing past 50 years of streamflow\n",
"# make plot\n",
"fig, ax = plt.subplots(figsize=(8,10))\n",
"fig, ax = plt.subplots(figsize = (8,10))\n",
"ax = hyswap.plots.plot_raster_hydrograph(\n",
" df_formatted, \n",
" ax=ax,\n",
" title=f\"Raster Hydrograph for {StaID} - {station_name}\")\n",
" ax = ax,\n",
" title = f\"Raster Hydrograph for {StaID} - {station_name}\")\n",
"plt.show()"
]
},
Expand All @@ -240,10 +248,10 @@
"outputs": [],
"source": [
"# re-format data\n",
"df_formatted = hyswap.rasterhydrograph.format_data(flow_data, \n",
" '00060_Mean', \n",
" year_type=\"water\", \n",
" clip_leap_day=True)"
"df_formatted = hyswap.rasterhydrograph.format_data(df = flow_data, \n",
" data_column_name= '00060_Mean', \n",
" year_type = \"water\", \n",
" clip_leap_day = True)"
]
},
{
Expand All @@ -254,13 +262,13 @@
"source": [
"#| fig-cap: Sample raster hydrograph showing all daily streamflow records from a site\n",
"# make plot\n",
"fig = plt.figure(figsize=(8,18))\n",
"fig = plt.figure(figsize = (8,18))\n",
"ax = fig.add_subplot()\n",
"ax = hyswap.plots.plot_raster_hydrograph(\n",
" df_formatted, \n",
" ax=ax,\n",
" title=f\"Raster Hydrograph for {StaID} - {station_name}\",\n",
" cmap='gist_ncar')\n",
" ax = ax,\n",
" title = f\"Raster Hydrograph for {StaID} - {station_name}\",\n",
" cmap = 'gist_ncar')\n",
"plt.show()"
]
},
Expand All @@ -269,7 +277,7 @@
"metadata": {},
"source": [
"## Analyze annual streamflow through cumulative flow and flow duration curves \n",
"Use calculations of streamflow percentiles (variable by day) to analyze annual patterns in streamflow\n",
"Use calculations of streamflow percentiles (variable by day) to analyze annual patterns in streamflow.\n",
"\n",
"Let's look at the last four years (2020-2023) of cumulative streamflow by plotting a cumulative hydrographs of different water years along with the envelope that 90% of annual cumulative streamflow is expected to be within, and the years with the minimum and maximum annual cumulative streamflows."
]
Expand All @@ -283,26 +291,26 @@
"#| fig-cap: Sample cumulative hydrograph showing multiple water years of cumulative streamflow\n",
"years_to_plot = [2020, 2021, 2022, 2023]\n",
"# plot the cumulative streamflow hydrograph\n",
"fig, ax = plt.subplots(figsize=(10, 5))\n",
"fig, ax = plt.subplots(figsize = (10, 5))\n",
"ax = hyswap.plots.plot_cumulative_hydrograph(\n",
" flow_data,\n",
" data_column_name='00060_Mean',\n",
" target_years=years_to_plot,\n",
" ax=ax, \n",
" title=f'Cumulative Streamflow Hydrograph for {StaID} - {station_name}',\n",
" df = flow_data,\n",
" data_column_name = '00060_Mean',\n",
" target_years = years_to_plot,\n",
" ax = ax, \n",
" title = f'Cumulative Streamflow Hydrograph for {StaID} - {station_name}',\n",
" envelope_pct = [5,95],\n",
" max_year=True, \n",
" min_year=True,\n",
" max_year = True, \n",
" min_year = True,\n",
" year_type = 'water',\n",
" alpha=0.2)\n",
" alpha = 0.2)\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Next, look at the flow duration curve for a site"
"Next, look at the flow duration curve for a site."
]
},
{
Expand All @@ -316,7 +324,9 @@
"values = np.linspace(flow_data['00060_Mean'].min(), flow_data['00060_Mean'].max(), 1000)\n",
"# calculate exceedance probabilities from the daily mean streamflow values using only approved data\n",
"exceedance_probabilities = hyswap.exceedance.calculate_exceedance_probability_from_values_multiple(\n",
" values, approved_flow_data['00060_Mean'])"
" values = values, \n",
" values_to_compare = approved_flow_data['00060_Mean']\n",
" )"
]
},
{
Expand All @@ -327,12 +337,12 @@
"source": [
"#| fig-cap: Example flow duration curve for a single gage\n",
"# plot the flow duration curve\n",
"fig, ax = plt.subplots(figsize=(8, 6))\n",
"fig, ax = plt.subplots(figsize = (8, 6))\n",
"ax = hyswap.plots.plot_flow_duration_curve(\n",
" values, \n",
" exceedance_probabilities, \n",
" ax=ax,\n",
" title=f'Flow Duration Curve for {StaID} - {station_name}')\n",
" values = values, \n",
" exceedance_probabilities = exceedance_probabilities, \n",
" ax = ax,\n",
" title = f'Flow Duration Curve for {StaID} - {station_name}')\n",
"# show the plot\n",
"plt.tight_layout()\n",
"plt.show()"
Expand All @@ -352,8 +362,10 @@
"outputs": [],
"source": [
"# create data for streamflow duration hydrograph from approved flow data\n",
"percentiles_by_day = hyswap.percentiles.calculate_variable_percentile_thresholds_by_day(approved_flow_data, \n",
" \"00060_Mean\")"
"percentiles_by_day = hyswap.percentiles.calculate_variable_percentile_thresholds_by_day(\n",
" df = approved_flow_data, \n",
" data_column_name = \"00060_Mean\"\n",
" )"
]
},
{
Expand Down Expand Up @@ -385,12 +397,12 @@
"df_year = df_indexed[df_indexed['index_year'] == water_year_to_plot].copy()\n",
"# plot data\n",
"ax = hyswap.plots.plot_duration_hydrograph(\n",
" percentiles_by_day,\n",
" df_year,\n",
" \"00060_Mean\",\n",
" ax=ax,\n",
" data_label=f\"Water Year {water_year_to_plot}\",\n",
" title=f\"Streamflow Duration Hydrograph for {StaID} - {station_name}\"\n",
" percentiles_by_day = percentiles_by_day,\n",
" df = df_year,\n",
" data_col = \"00060_Mean\",\n",
" ax = ax,\n",
" data_label = f\"Water Year {water_year_to_plot}\",\n",
" title = f\"Streamflow Duration Hydrograph for {StaID} - {station_name}\"\n",
")\n",
"plt.tight_layout()\n",
"plt.show()"
Expand Down
Loading

0 comments on commit b96b09e

Please sign in to comment.