Skip to content

Commit

Permalink
Merge pull request #17 from nicrie/develop
Browse files Browse the repository at this point in the history
Release 0.5.0
  • Loading branch information
nicrie authored Mar 12, 2022
2 parents 934677b + 375d675 commit a830a54
Show file tree
Hide file tree
Showing 33 changed files with 1,243 additions and 363 deletions.
14 changes: 7 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
:alt: PyPI - Downloads
.. |badge5| image:: https://codecov.io/gh/nicrie/xeofs/branch/main/graph/badge.svg?token=8040ZDH6U7
:target: https://codecov.io/gh/nicrie/xeofs

.. role:: red
.. |badge6| image:: https://zenodo.org/badge/DOI/10.5281/zenodo.6323012.svg
:target: https://doi.org/10.5281/zenodo.6323012

=================================
xeofs: EOF analysis and variants
Expand Down Expand Up @@ -40,7 +40,7 @@ Package eofs_ pyEOF_ xeof_ xMCA_ xmca2_
EOF analysis ✅ ✅ ✅ ✅ ✅ ✅
Rotated EOF analysis ❌ ✅ ❌ ❌ ✅ ✅
Complex EOF analysis ❌ ❌ ❌ ❌ ✅ ❌
Multivariate EOF ✅ ❌ ❌ ❌ ❌
Multivariate EOF ✅ ❌ ❌ ❌ ❌
MCA ❌ ❌ ❌ ✅ ✅ ❌
Rotated MCA ❌ ❌ ❌ ❌ ✅ ❌
Complex MCA ❌ ❌ ❌ ❌ ✅ ❌
Expand Down Expand Up @@ -100,24 +100,24 @@ How to use it?
----------------------
Documentation_ is work in progress. Meanwhile check out some examples_ to get started:

Examples:

+ EOF analysis (S-mode_)
+ EOF analysis (T-mode_)
+ Rotated_ EOF analysis (Varimax, Promax)
+ Weighted_ EOF analysis
+ Multivariate_ EOF analysis

.. _T-mode: https://xeofs.readthedocs.io/en/latest/auto_examples/1uni/plot_eof-tmode.html#sphx-glr-auto-examples-1uni-plot-eof-tmode-py
.. _S-mode: https://xeofs.readthedocs.io/en/latest/auto_examples/1uni/plot_eof-smode.html#sphx-glr-auto-examples-1uni-plot-eof-smode-py
.. _Weighted: https://xeofs.readthedocs.io/en/latest/auto_examples/1uni/plot_weighted_eof.html#sphx-glr-auto-examples-1uni-plot-weighted-eof-py
.. _Rotated: https://xeofs.readthedocs.io/en/latest/auto_examples/1uni/plot_rotated_eof.html#sphx-glr-auto-examples-1uni-plot-rotated-eof-py
.. _Multivariate: https://xeofs.readthedocs.io/en/latest/auto_examples/1uni/plot_multivariate-eof-analysis.html#sphx-glr-auto-examples-1uni-plot-multivariate-eof-analysis-py
.. _Documentation: https://xeofs.readthedocs.io/en/latest/
.. _examples: https://xeofs.readthedocs.io/en/latest/auto_examples/index.html


************************

Credits
************************
----------------------

- Project folder structure: yngvem_
- Testing data: xarray_ \& pooch_
Expand Down
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.
108 changes: 108 additions & 0 deletions docs/auto_examples/1uni/plot_multivariate-eof.ipynb
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
}
74 changes: 74 additions & 0 deletions docs/auto_examples/1uni/plot_multivariate-eof.py
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')
1 change: 1 addition & 0 deletions docs/auto_examples/1uni/plot_multivariate-eof.py.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f6a78a0349bdc68043e00652415b3a8d
Loading

0 comments on commit a830a54

Please sign in to comment.