Skip to content

Commit

Permalink
Merge pull request #14 from jukent/add-all
Browse files Browse the repository at this point in the history
add current content
  • Loading branch information
jukent authored Nov 1, 2023
2 parents 55d6772 + 629a3ab commit 8063b2f
Show file tree
Hide file tree
Showing 6 changed files with 709 additions and 4 deletions.
13 changes: 9 additions & 4 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ message: "If you use this cookbook, please cite it as below."
authors:
# add additional entries for each author -- see https://github.com/citation-file-format/citation-file-format/blob/main/schema-guide.md
- family-names: Kent
given-names: Julia
orcid: https://orcid.org/0000-0002-5611-8986
website: https://github.com/jukent
affiliation: UCAR/NCAR
given-names: Julia
orcid: https://orcid.org/0000-0002-5611-8986
website: https://github.com/jukent
affiliation: UCAR/NCAR
- family-names: Clyne
given-names: John
orcid: https://orcid.org/0000-0003-2788-9017
website: https://github.com/clyne
affiliation: UCAR/NCAR
- name: "Advanced Visualization Cookbook contributors" # use the 'name' field to acknowledge organizations
website: "https://github.com/ProjectPythia/advanced-viz-cookbook/graphs/contributors"
title: "Advanced Visualization Cookbook"
Expand Down
7 changes: 7 additions & 0 deletions _toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ parts:
- caption: Specialty Plots
chapters:
- file: notebooks/taylor-diagrams
- file: notebooks/skewt
- caption: Visualization of Structured Grids
chapters:
- file: notebooks/spagetti
- caption: Interactive Visualization
chapters:
- file: notebooks/mpas-datshader
- caption: Animation
chapters:
- file: notebooks/animatioin
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies:
- seaborn
- bokeh
- uxarray
- datashader
- geocat-datafiles
- tropycal
- pip
Expand Down
238 changes: 238 additions & 0 deletions notebooks/animation.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Animation"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"source": [
"time stamp at 1:19"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"NCL_animate_1\n",
"\n",
"Please note:\n",
" - Executing this script will not display a gif, but you have the option to uncomment a line at the bottom that will save a gif in the same directory as this script.\n",
"\n",
"[GeoCAT-examples](https://geocat-examples.readthedocs.io/en/latest/gallery/Animations/NCL_animate_1.html)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Import packages:\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
"import cartopy.crs as ccrs\n",
"import matplotlib.animation as animation\n",
"import numpy as np\n",
"import xarray as xr\n",
"from matplotlib import pyplot as plt\n",
"\n",
"import geocat.datafiles as gdf\n",
"import geocat.viz as gv"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Read in data:\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
"# Open a netCDF data file using xarray default engine and load the data into xarrays\n",
"# Disable time decoding due to missing necessary metadata\n",
"ds = xr.open_dataset(gdf.get(\"netcdf_files/meccatemp.cdf\"), decode_times=False)\n",
"\n",
"tas = ds.t\n",
"tas"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Create animation:\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
"# Set up Axes with Cartopy Projection\n",
"fig = plt.figure(figsize=(10, 8))\n",
"ax = plt.axes(projection=ccrs.PlateCarree(central_longitude=150))\n",
"ax.coastlines(linewidths=0.5)\n",
"ax.set_extent([-180, 180, -90, 90], ccrs.PlateCarree())\n",
"\n",
"# Use geocat.viz.util convenience function to set axes limits & tick values\n",
"gv.set_axes_limits_and_ticks(ax,\n",
" xlim=(-180, 180),\n",
" ylim=(-90, 90),\n",
" xticks=np.linspace(-180, 180, 13),\n",
" yticks=np.linspace(-90, 90, 7))\n",
"\n",
"# Use geocat.viz.util convenience function to add minor and major tick lines\n",
"gv.add_major_minor_ticks(ax, labelsize=10)\n",
"\n",
"# Use geocat.viz.util convenience function to make latitude, longitude tick labels\n",
"gv.add_lat_lon_ticklabels(ax)\n",
"\n",
"# create initial plot that establishes a colorbar\n",
"tas[0, :, :].plot.contourf(ax=ax,\n",
" transform=ccrs.PlateCarree(),\n",
" vmin=195,\n",
" vmax=328,\n",
" levels=53,\n",
" cmap=\"inferno\",\n",
" cbar_kwargs={\n",
" \"extendrect\": True,\n",
" \"orientation\": \"horizontal\",\n",
" \"ticks\": np.arange(195, 332, 9),\n",
" \"label\": \"\",\n",
" \"shrink\": 0.90\n",
" })\n",
"\n",
"\n",
"# animate function for matplotlib FuncAnimation\n",
"def animate(i):\n",
" tas[i, :, :].plot.contourf(\n",
" ax=ax,\n",
" transform=ccrs.PlateCarree(),\n",
" vmin=195,\n",
" vmax=328,\n",
" levels=53,\n",
" cmap=\"inferno\",\n",
" add_colorbar=False,\n",
" )\n",
"\n",
" gv.set_titles_and_labels(\n",
" ax,\n",
" maintitle=\"January Global Surface Temperature (K) - Day \" +\n",
" str(tas.coords['time'].values[i])[:13],\n",
" xlabel=\"\",\n",
" ylabel=\"\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"jupyter": {
"outputs_hidden": false
}
},
"source": [
"### Run:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
"# runs the animation initiated with the frame from init and progressed with the animate function\n",
"anim = animation.FuncAnimation(fig, animate, frames=30, interval=200)"
]
},
{
"cell_type": "markdown",
"metadata": {
"jupyter": {
"outputs_hidden": false
}
},
"source": [
"### Save:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
"# Uncomment this line to save the created animation\n",
"anim.save('images/animate_1.gif', writer='pillow', fps=5);"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Loading

0 comments on commit 8063b2f

Please sign in to comment.