Skip to content

Sample Graphic Notebook #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Binary file added boulder_prcp.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions landing-page.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"id": "422cec20-f029-427f-97bd-90e147e2eb0f",
"metadata": {},
"source": [
"<img src=\"images/pretty-earth.png\" alt=\"Pretty Earth\" width=\"600px\">"
"<img src='boulder_prcp.gif' alt=\"Boulder Flood Precipitation\" width=\"600px\">\n"
]
},
{
Expand All @@ -37,7 +37,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand Down
45 changes: 45 additions & 0 deletions page_art.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
###############################################################################
# Import packages

import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.animation as animation
import matplotlib.pyplot as plt
import numpy as np
import xarray as xr

###############################################################################
# Read in the data, file path will need to be updated

ds = xr.open_dataset('daymet_v3_prcp_2013_na_subset.nc', engine='netcdf4')
prcp = ds.prcp

# Create figure for plotting, adding land and state features
fig = plt.figure(figsize=(15, 15), frameon=False)
proj = ccrs.PlateCarree()
ax = plt.axes(projection=proj)
ax.axis('off')
ax.coastlines()
ax.add_feature(cfeature.LAND)
ax.add_feature(cfeature.STATES)

# Create function to loop over precip data and plot each day
anim_artists = [] # Generate empty list to place plots in

for prcp_slice in prcp:
cntr = ax.contourf(
prcp_slice.lon,
prcp_slice.lat,
prcp_slice,
transform=proj,
levels=np.arange(0, 55, 2),
)
anim_artists.append(cntr.collections)

plt.tight_layout()

# Call Matplotlib animation function to create gif
anim = animation.ArtistAnimation(fig, anim_artists, interval=500)

# Uncomment to save gif
# anim.save('boulder_prcp.gif', writer="pillow")
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ select = B,C,E,F,W,T4,B9

[isort]
known_first_party=
known_third_party=
known_third_party=cartopy,matplotlib,numpy,xarray
multi_line_output=3
include_trailing_comma=True
force_grid_wrap=0
Expand Down