-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from nicrie/develop
Release 0.5.0
- Loading branch information
Showing
33 changed files
with
1,243 additions
and
363 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+73.8 KB
docs/auto_examples/1uni/images/sphx_glr_plot_multivariate-eof_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 added
BIN
+45.6 KB
docs/auto_examples/1uni/images/thumb/sphx_glr_plot_multivariate-eof_thumb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"%matplotlib inline" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"\n# Varimax-rotated Multivariate EOF analysis\n\nMultivariate EOF analysis with additional Varimax rotation.\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"# Load packages and data:\nimport xarray as xr\nimport matplotlib.pyplot as plt\nfrom matplotlib.gridspec import GridSpec\nfrom cartopy.crs import PlateCarree\n\nfrom xeofs.xarray import EOF, Rotator" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Create four different dataarrayss\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"t2m = xr.tutorial.load_dataset('air_temperature')['air']\nsubset1 = t2m.isel(lon=slice(0, 4))\nsubset2 = t2m.isel(lon=slice(5, 14))\nsubset3 = t2m.isel(lon=slice(15, 34))\nsubset4 = t2m.isel(lon=slice(35, None))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Perform the actual analysis\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"mpca = EOF(\n [subset1, subset2, subset3, subset4],\n dim='time',\n norm=False,\n weights='coslat'\n)\nmpca.solve()\nrot = Rotator(mpca, n_rot=50)\nreofs = rot.eofs()\nrpcs = rot.pcs()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Plot mode 1\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"mode = 1\nproj = PlateCarree()\nkwargs = {\n 'cmap' : 'RdBu',\n 'vmin' : -.1,\n 'vmax': .1,\n 'transform': proj,\n 'add_colorbar': False\n}\n\nfig = plt.figure(figsize=(7.3, 6))\nfig.subplots_adjust(wspace=0)\ngs = GridSpec(2, 4, figure=fig, width_ratios=[1, 2, 3, 2])\nax = [fig.add_subplot(gs[0, i], projection=proj) for i in range(4)]\nax_pc = fig.add_subplot(gs[1, :])\n\n# PC\nrpcs.sel(mode=mode).plot(ax=ax_pc)\nax_pc.set_xlabel('')\nax_pc.set_title('')\n\n# EOFs\nfor i, (a, eof) in enumerate(zip(ax, reofs)):\n a.coastlines(color='.5')\n eof.sel(mode=mode).plot(ax=a, **kwargs)\n a.set_xticks([])\n a.set_yticks([])\n a.set_xlabel('')\n a.set_ylabel('')\n a.set_title('Subset {:}'.format(i+1))\nax[0].set_ylabel('EOFs')\nfig.suptitle('Mode {:}'.format(mode))\nplt.savefig('multivariate-eof-analysis.jpg')" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"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.8.12" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
""" | ||
Varimax-rotated Multivariate EOF analysis | ||
============================================ | ||
Multivariate EOF analysis with additional Varimax rotation. | ||
""" | ||
|
||
|
||
# Load packages and data: | ||
import xarray as xr | ||
import matplotlib.pyplot as plt | ||
from matplotlib.gridspec import GridSpec | ||
from cartopy.crs import PlateCarree | ||
|
||
from xeofs.xarray import EOF, Rotator | ||
|
||
#%% | ||
# Create four different dataarrayss | ||
t2m = xr.tutorial.load_dataset('air_temperature')['air'] | ||
subset1 = t2m.isel(lon=slice(0, 4)) | ||
subset2 = t2m.isel(lon=slice(5, 14)) | ||
subset3 = t2m.isel(lon=slice(15, 34)) | ||
subset4 = t2m.isel(lon=slice(35, None)) | ||
|
||
#%% | ||
# Perform the actual analysis | ||
|
||
mpca = EOF( | ||
[subset1, subset2, subset3, subset4], | ||
dim='time', | ||
norm=False, | ||
weights='coslat' | ||
) | ||
mpca.solve() | ||
rot = Rotator(mpca, n_rot=50) | ||
reofs = rot.eofs() | ||
rpcs = rot.pcs() | ||
|
||
#%% | ||
# Plot mode 1 | ||
|
||
mode = 1 | ||
proj = PlateCarree() | ||
kwargs = { | ||
'cmap' : 'RdBu', | ||
'vmin' : -.1, | ||
'vmax': .1, | ||
'transform': proj, | ||
'add_colorbar': False | ||
} | ||
|
||
fig = plt.figure(figsize=(7.3, 6)) | ||
fig.subplots_adjust(wspace=0) | ||
gs = GridSpec(2, 4, figure=fig, width_ratios=[1, 2, 3, 2]) | ||
ax = [fig.add_subplot(gs[0, i], projection=proj) for i in range(4)] | ||
ax_pc = fig.add_subplot(gs[1, :]) | ||
|
||
# PC | ||
rpcs.sel(mode=mode).plot(ax=ax_pc) | ||
ax_pc.set_xlabel('') | ||
ax_pc.set_title('') | ||
|
||
# EOFs | ||
for i, (a, eof) in enumerate(zip(ax, reofs)): | ||
a.coastlines(color='.5') | ||
eof.sel(mode=mode).plot(ax=a, **kwargs) | ||
a.set_xticks([]) | ||
a.set_yticks([]) | ||
a.set_xlabel('') | ||
a.set_ylabel('') | ||
a.set_title('Subset {:}'.format(i+1)) | ||
ax[0].set_ylabel('EOFs') | ||
fig.suptitle('Mode {:}'.format(mode)) | ||
plt.savefig('multivariate-eof-analysis.jpg') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
f6a78a0349bdc68043e00652415b3a8d |
Oops, something went wrong.