In [1]:
import subprocess
from io import BytesIO
import folium
import hvplot.pandas
import pandas as pd
import requests
import warnings
warnings.filterwarnings('ignore')
In [2]:
sg_lat = 40.66563889
sg_lon = -73.5700833
# Initialize map and tweak settings
m = folium.Map(
# Location to display
location=(sg_lat, sg_lon),
# Turns off annoying zooming while trying to scroll to the next cell
scrollWheelZoom=False,
)
# Put a marker at the stream gauge location
folium.Marker(
[sg_lat, sg_lon], popup="Stream Gage in Long Island, New York"
).add_to(m)
m
Out[2]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [3]:
nwis_url = (
"https://waterdata.usgs.gov/nwis/dv?cb_00060=on&format=rdb&site_no="
"01310500&legacy=&referred_module=sw&period=&begin_date=2001-09-01&end_"
"date=2023-09-01 "
)
# Send an HTTP GET request to the URL
nwis_response = requests.get(nwis_url)
nwis_response.raise_for_status()
In [4]:
ny_q_df = pd.read_csv(
BytesIO(nwis_response.content),
comment="#",
delimiter="\t",
skiprows=[29, 30],
names=["agency_cd", "site_no", "datetime", "streamflow_cfs", "code"],
index_col="datetime",
parse_dates=True,
na_values="Ice",
)
In [5]:
ny_flood_df = ny_q_df["2005-09":"2022-09"]
In [6]:
ny_ann_max_q_df = ny_q_df[['streamflow_cfs']].resample('AS').max()
In [7]:
ny_time_plot = ny_ann_max_q_df.hvplot(
x='datetime', y='streamflow_cfs',
title='Streamflows in New York',
xlabel='Year', ylabel='Streamflow in cubic feet per second'
)
ny_time_plot
Out[7]:
In [ ]:
%%capture
%%bash
jupyter nbconvert ny-timeseries.ipynb --to html --no-input