Skip to content

Commit

Permalink
docs: change examples
Browse files Browse the repository at this point in the history
  • Loading branch information
nicrie committed Aug 25, 2022
1 parent 462f2fe commit 1c69645
Show file tree
Hide file tree
Showing 50 changed files with 683 additions and 335 deletions.
Binary file modified docs/auto_examples/1eof/images/sphx_glr_plot_eof-smode_001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/auto_examples/1eof/images/sphx_glr_plot_eof-tmode_001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/auto_examples/1eof/images/sphx_glr_plot_mreof_001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 22 additions & 4 deletions docs/auto_examples/1eof/plot_eof-smode.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"outputs": [],
"source": [
"# Load packages and data:\nimport xarray as xr\nimport matplotlib.pyplot as plt\nfrom matplotlib.gridspec import GridSpec\nfrom cartopy.crs import Orthographic, PlateCarree\n\nfrom xeofs.xarray import EOF"
"# Load packages and data:\nimport xarray as xr\nimport matplotlib.pyplot as plt\nfrom matplotlib.gridspec import GridSpec\nfrom cartopy.crs import EqualEarth, PlateCarree\n\nfrom xeofs.xarray import EOF"
]
},
{
Expand All @@ -37,7 +37,7 @@
},
"outputs": [],
"source": [
"t2m = xr.tutorial.load_dataset('air_temperature')['air']"
"sst = xr.tutorial.open_dataset('ersstv5')['sst']"
]
},
{
Expand All @@ -55,7 +55,25 @@
},
"outputs": [],
"source": [
"model = EOF(t2m, n_modes=5, norm=False, dim='time')\nmodel.solve()\nexpvar = model.explained_variance_ratio()\neofs = model.eofs()\npcs = model.pcs()"
"model = EOF(sst, n_modes=5, norm=False, dim='time')\nmodel.solve()\nexpvar = model.explained_variance_ratio()\neofs = model.eofs()\npcs = model.pcs()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Explained variance fraction\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"expvar * 100"
]
},
{
Expand All @@ -73,7 +91,7 @@
},
"outputs": [],
"source": [
"proj = Orthographic(central_latitude=30, central_longitude=-80)\nkwargs = {\n 'cmap' : 'RdBu', 'vmin' : -.05, 'vmax': .05, 'transform': PlateCarree()\n}\n\nfig = plt.figure(figsize=(10, 10))\ngs = GridSpec(3, 4)\nax1 = fig.add_subplot(gs[0, :])\nax2 = fig.add_subplot(gs[1, 2:], projection=proj)\nax3 = fig.add_subplot(gs[1, :2])\nax4 = fig.add_subplot(gs[2, 2:], projection=proj)\nax5 = fig.add_subplot(gs[2, :2])\n\nax2.coastlines(color='.5')\nax4.coastlines(color='.5')\n\nexpvar.plot(ax=ax1, marker='.')\neofs.sel(mode=1).plot(ax=ax2, **kwargs)\npcs.sel(mode=1).plot(ax=ax3)\neofs.sel(mode=2).plot(ax=ax4, **kwargs)\npcs.sel(mode=2).plot(ax=ax5)\nplt.tight_layout()\nplt.savefig('eof-smode.jpg')"
"proj = EqualEarth(central_longitude=180)\nkwargs = {\n 'cmap' : 'RdBu', 'vmin' : -.05, 'vmax': .05, 'transform': PlateCarree()\n}\n\nfig = plt.figure(figsize=(10, 8))\ngs = GridSpec(3, 2, width_ratios=[1, 2])\nax0 = [fig.add_subplot(gs[i, 0]) for i in range(3)]\nax1 = [fig.add_subplot(gs[i, 1], projection=proj) for i in range(3)]\n\nfor i, (a0, a1) in enumerate(zip(ax0, ax1)):\n pcs.sel(mode=i+1).plot(ax=a0)\n a1.coastlines(color='.5')\n eofs.sel(mode=i+1).plot(ax=a1, **kwargs)\n\n a0.set_xlabel('')\n\nplt.tight_layout()\nplt.savefig('eof-smode.jpg')"
]
}
],
Expand Down
40 changes: 20 additions & 20 deletions docs/auto_examples/1eof/plot_eof-smode.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,46 +10,46 @@
import xarray as xr
import matplotlib.pyplot as plt
from matplotlib.gridspec import GridSpec
from cartopy.crs import Orthographic, PlateCarree
from cartopy.crs import EqualEarth, PlateCarree

from xeofs.xarray import EOF

#%%

t2m = xr.tutorial.load_dataset('air_temperature')['air']
sst = xr.tutorial.open_dataset('ersstv5')['sst']

#%%
# Perform the actual analysis

model = EOF(t2m, n_modes=5, norm=False, dim='time')
model = EOF(sst, n_modes=5, norm=False, dim='time')
model.solve()
expvar = model.explained_variance_ratio()
eofs = model.eofs()
pcs = model.pcs()

#%%
# Explained variance fraction
expvar * 100

#%%
# Create figure showing the first two modes

proj = Orthographic(central_latitude=30, central_longitude=-80)
proj = EqualEarth(central_longitude=180)
kwargs = {
'cmap' : 'RdBu', 'vmin' : -.05, 'vmax': .05, 'transform': PlateCarree()
}

fig = plt.figure(figsize=(10, 10))
gs = GridSpec(3, 4)
ax1 = fig.add_subplot(gs[0, :])
ax2 = fig.add_subplot(gs[1, 2:], projection=proj)
ax3 = fig.add_subplot(gs[1, :2])
ax4 = fig.add_subplot(gs[2, 2:], projection=proj)
ax5 = fig.add_subplot(gs[2, :2])

ax2.coastlines(color='.5')
ax4.coastlines(color='.5')

expvar.plot(ax=ax1, marker='.')
eofs.sel(mode=1).plot(ax=ax2, **kwargs)
pcs.sel(mode=1).plot(ax=ax3)
eofs.sel(mode=2).plot(ax=ax4, **kwargs)
pcs.sel(mode=2).plot(ax=ax5)
fig = plt.figure(figsize=(10, 8))
gs = GridSpec(3, 2, width_ratios=[1, 2])
ax0 = [fig.add_subplot(gs[i, 0]) for i in range(3)]
ax1 = [fig.add_subplot(gs[i, 1], projection=proj) for i in range(3)]

for i, (a0, a1) in enumerate(zip(ax0, ax1)):
pcs.sel(mode=i+1).plot(ax=a0)
a1.coastlines(color='.5')
eofs.sel(mode=i+1).plot(ax=a1, **kwargs)

a0.set_xlabel('')

plt.tight_layout()
plt.savefig('eof-smode.jpg')
2 changes: 1 addition & 1 deletion docs/auto_examples/1eof/plot_eof-smode.py.md5
Original file line number Diff line number Diff line change
@@ -1 +1 @@
db54278c998095cf5241baf1933c6720
2b08f77f481d6924ee43333188762cd5
Loading

0 comments on commit 1c69645

Please sign in to comment.