sacpy


Namesacpy JSON
Version 0.0.24 PyPI version JSON
download
home_pagehttps://github.com/ZiluM/sacpy
SummaryA repaid Statistical Analysis tool for Climate or Meteorology data.
upload_time2024-02-23 03:28:27
maintainer
docs_urlNone
authorZilu Meng
requires_python
licenseMIT
keywords meteorology data statistic climate
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # SACPY -- A Python Package for Statistical Analysis of Climate

**Sacpy**, an effecient Statistical Analysis tool for Climate and Meteorology data.

Author : Zilu Meng 

e-mail : zilumeng@uw.edu

github : https://github.com/ZiluM/sacpy

pypi : https://pypi.org/project/sacpy/

Document: https://zilum.github.io/sacpy/

version : 0.0.20

## Why choose Sacpy?

### Fast!

For example, Sacpy is more than 60 times faster than the traditional regression analysis with Python (see **speed test**). The following is the time spent performing the same task. Sacpy is fastest.

![](https://raw.githubusercontent.com/ZiluM/sacpy/main/pic/speed_test_00.png)

### Turn to climate data customization!

Compatible with commonly used meteorological calculation libraries such as numpy and xarray.

### Concise code

You can finish drawing a following figure with just seven lines of code. see **examples of concise**.

![](https://raw.githubusercontent.com/ZiluM/sacpy/main/pic/one_test.png)

You can use SVD/MCA to get the image below easily.

![](https://raw.githubusercontent.com/ZiluM/sacpy/main/pic/SVD.png)

## Install and update

You can use pip to install.

    pip install sacpy

Or you can visit https://gitee.com/zilum/sacpy/tree/main/dist to download **.whl file**, then

    pip install .whl_file

update:

    pip install --upgrade sacpy

or you can download **.whl** file and then install use ` pip install .whl_file`.

## Speed

As a comparison, we use the  **corr**  function in the xarray library, **corrcoef** function in numpy library, cdist in scipy, apply_func in xarray  and **for-loop**. The time required to calculate the correlation coefficient between SSTA and nino3.4 for 50 times is shown in the figure below.

It can be seen that we are four times faster than scipy cdist, five times faster than xarray.corr, 60 times faster than forloop, 110 times faster than xr.apply_func and 200 times faster than numpy.corrcoef.

Moreover, xarray and numpy can not return the **p value**. We can simply check the pvalue attribute of sacpy to get the p value.

All in all, if we want to get p-value and correlation or slope, we only to choose **Sacpy is 60 times faster than before**.

![](https://raw.githubusercontent.com/ZiluM/sacpy/main/pic/speed_test_00.png)

## Example

### example1

Calculate the correlation between SST and nino3.4 index

```Python
import numpy as np
import scapy as scp
import matplotlib.pyplot as plt
import sacpy.Map # need cartopy or you can just not import
import cartopy.crs as ccrs

# load sst
sst = scp.load_sst()['sst']
# get ssta (method=1, Remove linear trend;method=0, Minus multi-year average)
ssta = scp.get_anom(sst,method=1)
# calculate Nino3.4
Nino34 = ssta.loc[:,-5:5,190:240].mean(axis=(1,2))
# regression
linreg = scp.LinReg(Nino34,ssta)
# plot
fig = plt.figure(figsize=[7, 3])
ax = plt.axes(projection=ccrs.PlateCarree(central_longitude=180))
lon ,lat = ssta.lon , ssta.lat
# shading
m = ax.scontourf(lon,lat,linreg.corr)
# significant plot
n = ax.sig_plot(lon,lat,linreg.p_value,color="k",marker="..")
# initialize map
ax.init_map(stepx=50, ysmall=2.5)
# colorbar
plt.colorbar(m)
# save
plt.savefig("../pic/nino34.png",dpi=200)

```

Result(For a detailed drawing process, see **example**):

![](https://raw.githubusercontent.com/ZiluM/sacpy/main/pic/nino34.png)

### example2

multiple linear regression on Nino3.4 IOD Index and ssta pattern

```Python
import numpy as np
import scapy as scp
import matplotlib.pyplot as plt


# load sst
sst = scp.load_sst()['sst']
# get ssta (method=1, Remove linear trend;method=0, Minus multi-year average)
ssta = scp.get_anom(sst,method=1)
# calculate Nino3.4
Nino34 = ssta.loc[:,-5:5,190:240].mean(axis=(1,2))
# calculate IODIdex
IODW = ssta.loc[:,-10:10,50:70].mean(axis=(1,2))
IODE = ssta.loc[:,-10:0,90:110].mean(axis=(1,2))
IODI = +IODW - IODE
# get x
X = np.vstack([np.array(Nino34),np.array(IODI)]).T
# multiple linear regression
MLR = scp.MultLinReg(X,ssta)

# plot IOD's effect
import sacpy.Map
import cartopy.crs as ccrs


fig = plt.figure(figsize=[7, 3])
ax = plt.axes(projection=ccrs.PlateCarree(central_longitude=180))
lon ,lat = ssta.lon , ssta.lat
m = ax.scontourf(lon,lat,MLR.slope[1])
# significant plot
n = ax.sig_plot(lon,lat,MLR.pv_i[1],color="k",marker="..")
# initialize map
ax.init_map(stepx=50, ysmall=2.5)
plt.colorbar(m)
plt.savefig("../pic/MLR.png",dpi=200)
```

Result(For a detailed drawing process, see **example**):

![](https://raw.githubusercontent.com/ZiluM/sacpy/main/pic/MLR.png)

### example3

What effect will ENSO have on the sea surface temperature in the next summer?

```Python
import numpy as np
import sacpy as scp
import matplotlib.pyplot as plt
import xarray as xr

# load sst
sst = scp.load_sst()['sst']
ssta = scp.get_anom(sst)

# calculate Nino3.4
Nino34 = ssta.loc[:,-5:5,190:240].mean(axis=(1,2))

# get DJF mean Nino3.4
DJF_nino34 = scp.XrTools.spec_moth_yrmean(Nino34,[12,1,2])

# get JJA mean ssta
JJA_ssta = scp.XrTools.spec_moth_yrmean(ssta, [6,7,8])

# regression
reg = scp.LinReg(DJF_nino34[:-1], JJA_ssta)
# plot
import cartopy.crs as ccrs
import sacpy.Map


fig = plt.figure(figsize=[7, 3])
ax = plt.axes(projection=ccrs.PlateCarree(central_longitude=180))
lon ,lat = np.array(ssta.lon) , np.array(ssta.lat)
m = ax.scontourf(lon,lat,reg.slope)
n = ax.sig_plot(lon,lat,reg.p_value,color="k",marker="///")
ax.init_map(stepx=50, ysmall=2.5)
plt.colorbar(m)
plt.savefig("../pic/ENSO_Next_year_JJA.png",dpi=300)

```

![](https://raw.githubusercontent.com/ZiluM/sacpy/main/pic/ENSO_Next_year_JJA.png)

Same as **Indian Ocean Capacitor Effect on Indo–Western Pacific Climate during the Summer following El Niño** (Xie et al.), the El Nino will lead to Indian ocean warming in next year JJA.

### example4

EOF analysis

```Python
import sacpy as scp
import numpy as np
import matplotlib.pyplot as plt
# get data
sst = scp.load_sst()["sst"].loc[:, -20:30, 150:275]
ssta = scp.get_anom(sst)
# EOF
eof = scp.EOF(np.array(ssta))
eof.solve()
# get spartial pattern and pc
pc = eof.get_pc(npt=2)
pt = eof.get_pt(npt=2)
# plot
import cartopy.crs as ccrs
import sacpy.Map
lon , lat = np.array(ssta.lon) , np.array(ssta.lat)
fig = plt.figure(figsize=[15,10])
ax = fig.add_subplot(221,projection=ccrs.PlateCarree(central_longitude=180))
m1 = ax.scontourf(lon,lat,pt[0,:,:],cmap='RdBu_r',levels=np.linspace(-0.75,0.75,15),extend="both")
ax.scontour(m1,colors="black")
ax.init_map(ysmall=2.5)
# plt.colorbar(m1)
ax2 = fig.add_subplot(222)
ax2.plot(sst.time,pc[0])
ax3 = fig.add_subplot(223,projection=ccrs.PlateCarree(central_longitude=180))
m2 = ax3.scontourf(lon,lat,pt[1,:,:],cmap='RdBu_r',levels=np.linspace(-0.75,0.75,15),extend="both")
ax3.scontour(m2,colors="black")
ax3.init_map(ysmall=2.5)
ax4 = fig.add_subplot(224)
ax4.plot(sst.time,pc[1])
cb_ax = fig.add_axes([0.1,0.06,0.4,0.02])
fig.colorbar(m1,cax=cb_ax,orientation="horizontal")
plt.savefig("../pic/eof_ana.png",dpi=300)
```

![](https://raw.githubusercontent.com/ZiluM/sacpy/main/pic/eof_ana.png)

## example5

Mean value (Composite Analysis) t-test for super El Nino (DJF Nino3.4 > 1)

```Python

import sacpy as scp
import numpy as np
import matplotlib.pyplot as plt

sst = scp.load_sst()["sst"]
ssta = scp.get_anom(sst, method=0)
# get Dec Jan Feb SSTA
ssta_djf = scp.XrTools.spec_moth_yrmean(ssta,[12,1,2])
Nino34 = ssta_djf.loc[:, -5:5, 190:240].mean(axis=(1, 2))
# select year of Super El Nino
select = Nino34 >= 1
ssta_sl = ssta_djf[select]
mean, pv = scp.one_mean_test(ssta_sl)
# plot
import sacpy.Map
import cartopy.crs as ccrs
fig = plt.figure(figsize=[7, 3])
ax = plt.axes(projection=ccrs.PlateCarree(central_longitude=180))
lon ,lat = np.array(ssta.lon) , np.array(ssta.lat)
m = ax.scontourf(lon,lat,mean)
n = ax.sig_plot(lon,lat,pv,color="k",marker="..")
ax.init_map(stepx=50, ysmall=2.5)
plt.colorbar(m)
plt.savefig("../pic/one_test.png")
```

Result:

![](https://raw.githubusercontent.com/ZiluM/sacpy/main/pic/one_test.png)

## example6

SVD(MCA) analysis.

```Python
import sacpy as scp
import xarray as xr
import matplotlib.pyplot as plt
import numpy as np
from xmca import array
import sacpy.Map
import cartopy.crs as ccrs

# load data
sst = scp.load_sst()['sst'].loc["1991":"2021", -20:30, 150:275]
ssta = scp.get_anom(sst)
u = scp.load_10mwind()['u']
v = scp.load_10mwind()['v']

uua = scp.get_anom(u)
vua = scp.get_anom(v)
uv = np.concatenate([np.array(uua)[...,np.newaxis],np.array(vua)[...,np.newaxis]],axis=-1)
# calculation
svd = scp.SVD(ssta,uv,complex=False)
svd.solve()
ptl, ptr = svd.get_pt(3)
pcl,pcr = svd.get_pc(3)
upt ,vpt = ptr[...,0] , ptr[...,1]
sst_pt = ptl
# plot progress, see example/SVD.ipynb
```

result:

![](https://raw.githubusercontent.com/ZiluM/sacpy/main/pic/SVD.png)

## examples of concise

If you want to plot example1's figure , you need write:

```Python
from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter
from matplotlib.ticker import MultipleLocator
import cartopy.crs as ccrs
plt.rc('font', family='Times New Roman', size=12)
ax = plt.axes(projection=ccrs.PlateCarree(central_longitude=180))
m = ax.contourf(ssta.lon,ssta.lat,linreg.corr,
                cmap="RdBu_r",
                levels=np.linspace(-1, 1, 15),
                extend="both",
                transform=ccrs.PlateCarree())
n = plt.contourf(ssta.lon,ssta.lat,linreg.p_value,
                 levels=[0, 0.05, 1],
                 zorder=1,
                 hatches=['..', None],
                 colors="None",
                 transform=ccrs.PlateCarree())
xtk = np.arange(-180,181,60)
ax.set_xticks(xtk)
# ax.set_xticks(xtk,crs=ccrs.PlateCarree())
ax.set_yticks(np.arange(-50,51,20),crs=ccrs.PlateCarree())
ax.yaxis.set_major_formatter(LatitudeFormatter())
ax.xaxis.set_major_formatter(LongitudeFormatter(zero_direction_label=True))
ax.xaxis.set_minor_locator(MultipleLocator(10))
ax.yaxis.set_minor_locator(MultipleLocator(5))
ax.coastlines()
ax.set_aspect("auto")
plt.colorbar(m)

```

**So troublesome!!!**

But if you `import sacpy.Map`, you can easily write:

```Python
import sacpy.Map
import cartopy.crs as ccrs
fig = plt.figure(figsize=[7, 3])
ax = plt.axes(projection=ccrs.PlateCarree(central_longitude=180))
lon ,lat = ssta.lon , ssta.lat
m = ax.scontourf(lon,lat,rvalue)
n = ax.sig_plot(lon,lat,p,color="k",marker="..")
ax.init_map(stepx=50, ysmall=2.5)
plt.colorbar(m)
```

How wonderful, how concise !

## Acknowledgements

Thank Prof. Feng Zhu (NUIST,https://fzhu2e.github.io/) for his guidance of this project.

Thank for Prof. Tim Li (University of Hawaii at Mānoa, http://iprc.soest.hawaii.edu/people/li.php) ,Prof. Lin Chen (NUIST, https://faculty.nuist.edu.cn/chenlin12/zh_CN/index.htm) and Dr. Ming Sun (NUIST) 's help.

Sepcial thanks: Lifei Lin (Sun Yat-sen University) 's `repr_html.py` to visualize class in jupyter!


# Change Log

## version 0.0.1

Nothing!

## version 0.0.5

First official edition

## version 0.0.6

Updated the speed test and changed small errors

## version 0.0.7

Add examples and change README.md

## version 0.0.9

Add mult_corr,partial_corr in LinReg.py and spec_moth_dat, spec_moth_yrmean in XrTools.

Change examples.

## version 0.0.10

Add EOF analysis

## version 0.0.11

Change Example Data

## version 0.0.12

Fix a bug in XrTools

Add Map.py for quick plot

## version 0.0.13

Change example!

## version 0.0.14

Add SVD(MCA) analysis and visualization of LinReg in Jupyter.

## version 0.0.15

Add Map.py for test and new wrapper progress for Map.py and Linreg

## version 0.0.16

Optimized support for xarray

## version 0.0.17

1. update mask function for LinReg 
2. add shp mask function
3. correct SVD

## version 0.0.18

1. add new function of EOF
2. correct some errors of EOF and SVD 

## version 0.0.19 

1. add new function for Map
2. fix some errors of Map

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ZiluM/sacpy",
    "name": "sacpy",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "meteorology data statistic climate",
    "author": "Zilu Meng",
    "author_email": "zilumeng@uw.edu",
    "download_url": "https://files.pythonhosted.org/packages/96/0a/387759b7f8e475271cd85345d52e3aa1ef8212aa96abec7f9bcd0e754458/sacpy-0.0.24.tar.gz",
    "platform": null,
    "description": "# SACPY -- A Python Package for Statistical Analysis of Climate\n\n**Sacpy**, an effecient Statistical Analysis tool for Climate and Meteorology data.\n\nAuthor : Zilu Meng \n\ne-mail : zilumeng@uw.edu\n\ngithub : https://github.com/ZiluM/sacpy\n\npypi : https://pypi.org/project/sacpy/\n\nDocument: https://zilum.github.io/sacpy/\n\nversion : 0.0.20\n\n## Why choose Sacpy?\n\n### Fast!\n\nFor example, Sacpy is more than 60 times faster than the traditional regression analysis with Python (see **speed test**). The following is the time spent performing the same task. Sacpy is fastest.\n\n![](https://raw.githubusercontent.com/ZiluM/sacpy/main/pic/speed_test_00.png)\n\n### Turn to climate data customization!\n\nCompatible with commonly used meteorological calculation libraries such as numpy and xarray.\n\n### Concise code\n\nYou can finish drawing a following figure with just seven lines of code. see **examples of concise**.\n\n![](https://raw.githubusercontent.com/ZiluM/sacpy/main/pic/one_test.png)\n\nYou can use SVD/MCA to get the image below easily.\n\n![](https://raw.githubusercontent.com/ZiluM/sacpy/main/pic/SVD.png)\n\n## Install and update\n\nYou can use pip to install.\n\n    pip install sacpy\n\nOr you can visit https://gitee.com/zilum/sacpy/tree/main/dist to download **.whl file**, then\n\n    pip install .whl_file\n\nupdate:\n\n    pip install --upgrade sacpy\n\nor you can download **.whl** file and then install use ` pip install .whl_file`.\n\n## Speed\n\nAs a comparison, we use the  **corr**  function in the xarray library, **corrcoef** function in numpy library, cdist in scipy, apply_func in xarray  and **for-loop**. The time required to calculate the correlation coefficient between SSTA and nino3.4 for 50 times is shown in the figure below.\n\nIt can be seen that we are four times faster than scipy cdist, five times faster than xarray.corr, 60 times faster than forloop, 110 times faster than xr.apply_func and 200 times faster than numpy.corrcoef.\n\nMoreover, xarray and numpy can not return the **p value**. We can simply check the pvalue attribute of sacpy to get the p value.\n\nAll in all, if we want to get p-value and correlation or slope, we only to choose **Sacpy is 60 times faster than before**.\n\n![](https://raw.githubusercontent.com/ZiluM/sacpy/main/pic/speed_test_00.png)\n\n## Example\n\n### example1\n\nCalculate the correlation between SST and nino3.4 index\n\n```Python\nimport numpy as np\nimport scapy as scp\nimport matplotlib.pyplot as plt\nimport sacpy.Map # need cartopy or you can just not import\nimport cartopy.crs as ccrs\n\n# load sst\nsst = scp.load_sst()['sst']\n# get ssta (method=1, Remove linear trend;method=0, Minus multi-year average)\nssta = scp.get_anom(sst,method=1)\n# calculate Nino3.4\nNino34 = ssta.loc[:,-5:5,190:240].mean(axis=(1,2))\n# regression\nlinreg = scp.LinReg(Nino34,ssta)\n# plot\nfig = plt.figure(figsize=[7, 3])\nax = plt.axes(projection=ccrs.PlateCarree(central_longitude=180))\nlon ,lat = ssta.lon , ssta.lat\n# shading\nm = ax.scontourf(lon,lat,linreg.corr)\n# significant plot\nn = ax.sig_plot(lon,lat,linreg.p_value,color=\"k\",marker=\"..\")\n# initialize map\nax.init_map(stepx=50, ysmall=2.5)\n# colorbar\nplt.colorbar(m)\n# save\nplt.savefig(\"../pic/nino34.png\",dpi=200)\n\n```\n\nResult(For a detailed drawing process, see **example**):\n\n![](https://raw.githubusercontent.com/ZiluM/sacpy/main/pic/nino34.png)\n\n### example2\n\nmultiple linear regression on Nino3.4 IOD Index and ssta pattern\n\n```Python\nimport numpy as np\nimport scapy as scp\nimport matplotlib.pyplot as plt\n\n\n# load sst\nsst = scp.load_sst()['sst']\n# get ssta (method=1, Remove linear trend;method=0, Minus multi-year average)\nssta = scp.get_anom(sst,method=1)\n# calculate Nino3.4\nNino34 = ssta.loc[:,-5:5,190:240].mean(axis=(1,2))\n# calculate IODIdex\nIODW = ssta.loc[:,-10:10,50:70].mean(axis=(1,2))\nIODE = ssta.loc[:,-10:0,90:110].mean(axis=(1,2))\nIODI = +IODW - IODE\n# get x\nX = np.vstack([np.array(Nino34),np.array(IODI)]).T\n# multiple linear regression\nMLR = scp.MultLinReg(X,ssta)\n\n# plot IOD's effect\nimport sacpy.Map\nimport cartopy.crs as ccrs\n\n\nfig = plt.figure(figsize=[7, 3])\nax = plt.axes(projection=ccrs.PlateCarree(central_longitude=180))\nlon ,lat = ssta.lon , ssta.lat\nm = ax.scontourf(lon,lat,MLR.slope[1])\n# significant plot\nn = ax.sig_plot(lon,lat,MLR.pv_i[1],color=\"k\",marker=\"..\")\n# initialize map\nax.init_map(stepx=50, ysmall=2.5)\nplt.colorbar(m)\nplt.savefig(\"../pic/MLR.png\",dpi=200)\n```\n\nResult(For a detailed drawing process, see **example**):\n\n![](https://raw.githubusercontent.com/ZiluM/sacpy/main/pic/MLR.png)\n\n### example3\n\nWhat effect will ENSO have on the sea surface temperature in the next summer?\n\n```Python\nimport numpy as np\nimport sacpy as scp\nimport matplotlib.pyplot as plt\nimport xarray as xr\n\n# load sst\nsst = scp.load_sst()['sst']\nssta = scp.get_anom(sst)\n\n# calculate Nino3.4\nNino34 = ssta.loc[:,-5:5,190:240].mean(axis=(1,2))\n\n# get DJF mean Nino3.4\nDJF_nino34 = scp.XrTools.spec_moth_yrmean(Nino34,[12,1,2])\n\n# get JJA mean ssta\nJJA_ssta = scp.XrTools.spec_moth_yrmean(ssta, [6,7,8])\n\n# regression\nreg = scp.LinReg(DJF_nino34[:-1], JJA_ssta)\n# plot\nimport cartopy.crs as ccrs\nimport sacpy.Map\n\n\nfig = plt.figure(figsize=[7, 3])\nax = plt.axes(projection=ccrs.PlateCarree(central_longitude=180))\nlon ,lat = np.array(ssta.lon) , np.array(ssta.lat)\nm = ax.scontourf(lon,lat,reg.slope)\nn = ax.sig_plot(lon,lat,reg.p_value,color=\"k\",marker=\"///\")\nax.init_map(stepx=50, ysmall=2.5)\nplt.colorbar(m)\nplt.savefig(\"../pic/ENSO_Next_year_JJA.png\",dpi=300)\n\n```\n\n![](https://raw.githubusercontent.com/ZiluM/sacpy/main/pic/ENSO_Next_year_JJA.png)\n\nSame as **Indian Ocean Capacitor Effect on Indo\u2013Western Pacific Climate during the Summer following El Ni\u00f1o** (Xie et al.), the El Nino will lead to Indian ocean warming in next year JJA.\n\n### example4\n\nEOF analysis\n\n```Python\nimport sacpy as scp\nimport numpy as np\nimport matplotlib.pyplot as plt\n# get data\nsst = scp.load_sst()[\"sst\"].loc[:, -20:30, 150:275]\nssta = scp.get_anom(sst)\n# EOF\neof = scp.EOF(np.array(ssta))\neof.solve()\n# get spartial pattern and pc\npc = eof.get_pc(npt=2)\npt = eof.get_pt(npt=2)\n# plot\nimport cartopy.crs as ccrs\nimport sacpy.Map\nlon , lat = np.array(ssta.lon) , np.array(ssta.lat)\nfig = plt.figure(figsize=[15,10])\nax = fig.add_subplot(221,projection=ccrs.PlateCarree(central_longitude=180))\nm1 = ax.scontourf(lon,lat,pt[0,:,:],cmap='RdBu_r',levels=np.linspace(-0.75,0.75,15),extend=\"both\")\nax.scontour(m1,colors=\"black\")\nax.init_map(ysmall=2.5)\n# plt.colorbar(m1)\nax2 = fig.add_subplot(222)\nax2.plot(sst.time,pc[0])\nax3 = fig.add_subplot(223,projection=ccrs.PlateCarree(central_longitude=180))\nm2 = ax3.scontourf(lon,lat,pt[1,:,:],cmap='RdBu_r',levels=np.linspace(-0.75,0.75,15),extend=\"both\")\nax3.scontour(m2,colors=\"black\")\nax3.init_map(ysmall=2.5)\nax4 = fig.add_subplot(224)\nax4.plot(sst.time,pc[1])\ncb_ax = fig.add_axes([0.1,0.06,0.4,0.02])\nfig.colorbar(m1,cax=cb_ax,orientation=\"horizontal\")\nplt.savefig(\"../pic/eof_ana.png\",dpi=300)\n```\n\n![](https://raw.githubusercontent.com/ZiluM/sacpy/main/pic/eof_ana.png)\n\n## example5\n\nMean value (Composite Analysis) t-test for super El Nino (DJF Nino3.4 > 1)\n\n```Python\n\nimport sacpy as scp\nimport numpy as np\nimport matplotlib.pyplot as plt\n\nsst = scp.load_sst()[\"sst\"]\nssta = scp.get_anom(sst, method=0)\n# get Dec Jan Feb SSTA\nssta_djf = scp.XrTools.spec_moth_yrmean(ssta,[12,1,2])\nNino34 = ssta_djf.loc[:, -5:5, 190:240].mean(axis=(1, 2))\n# select year of Super El Nino\nselect = Nino34 >= 1\nssta_sl = ssta_djf[select]\nmean, pv = scp.one_mean_test(ssta_sl)\n# plot\nimport sacpy.Map\nimport cartopy.crs as ccrs\nfig = plt.figure(figsize=[7, 3])\nax = plt.axes(projection=ccrs.PlateCarree(central_longitude=180))\nlon ,lat = np.array(ssta.lon) , np.array(ssta.lat)\nm = ax.scontourf(lon,lat,mean)\nn = ax.sig_plot(lon,lat,pv,color=\"k\",marker=\"..\")\nax.init_map(stepx=50, ysmall=2.5)\nplt.colorbar(m)\nplt.savefig(\"../pic/one_test.png\")\n```\n\nResult:\n\n![](https://raw.githubusercontent.com/ZiluM/sacpy/main/pic/one_test.png)\n\n## example6\n\nSVD(MCA) analysis.\n\n```Python\nimport sacpy as scp\nimport xarray as xr\nimport matplotlib.pyplot as plt\nimport numpy as np\nfrom xmca import array\nimport sacpy.Map\nimport cartopy.crs as ccrs\n\n# load data\nsst = scp.load_sst()['sst'].loc[\"1991\":\"2021\", -20:30, 150:275]\nssta = scp.get_anom(sst)\nu = scp.load_10mwind()['u']\nv = scp.load_10mwind()['v']\n\nuua = scp.get_anom(u)\nvua = scp.get_anom(v)\nuv = np.concatenate([np.array(uua)[...,np.newaxis],np.array(vua)[...,np.newaxis]],axis=-1)\n# calculation\nsvd = scp.SVD(ssta,uv,complex=False)\nsvd.solve()\nptl, ptr = svd.get_pt(3)\npcl,pcr = svd.get_pc(3)\nupt ,vpt = ptr[...,0] , ptr[...,1]\nsst_pt = ptl\n# plot progress, see example/SVD.ipynb\n```\n\nresult:\n\n![](https://raw.githubusercontent.com/ZiluM/sacpy/main/pic/SVD.png)\n\n## examples of concise\n\nIf you want to plot example1's figure , you need write:\n\n```Python\nfrom cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter\nfrom matplotlib.ticker import MultipleLocator\nimport cartopy.crs as ccrs\nplt.rc('font', family='Times New Roman', size=12)\nax = plt.axes(projection=ccrs.PlateCarree(central_longitude=180))\nm = ax.contourf(ssta.lon,ssta.lat,linreg.corr,\n                cmap=\"RdBu_r\",\n                levels=np.linspace(-1, 1, 15),\n                extend=\"both\",\n                transform=ccrs.PlateCarree())\nn = plt.contourf(ssta.lon,ssta.lat,linreg.p_value,\n                 levels=[0, 0.05, 1],\n                 zorder=1,\n                 hatches=['..', None],\n                 colors=\"None\",\n                 transform=ccrs.PlateCarree())\nxtk = np.arange(-180,181,60)\nax.set_xticks(xtk)\n# ax.set_xticks(xtk,crs=ccrs.PlateCarree())\nax.set_yticks(np.arange(-50,51,20),crs=ccrs.PlateCarree())\nax.yaxis.set_major_formatter(LatitudeFormatter())\nax.xaxis.set_major_formatter(LongitudeFormatter(zero_direction_label=True))\nax.xaxis.set_minor_locator(MultipleLocator(10))\nax.yaxis.set_minor_locator(MultipleLocator(5))\nax.coastlines()\nax.set_aspect(\"auto\")\nplt.colorbar(m)\n\n```\n\n**So troublesome!!!**\n\nBut if you `import sacpy.Map`, you can easily write:\n\n```Python\nimport sacpy.Map\nimport cartopy.crs as ccrs\nfig = plt.figure(figsize=[7, 3])\nax = plt.axes(projection=ccrs.PlateCarree(central_longitude=180))\nlon ,lat = ssta.lon , ssta.lat\nm = ax.scontourf(lon,lat,rvalue)\nn = ax.sig_plot(lon,lat,p,color=\"k\",marker=\"..\")\nax.init_map(stepx=50, ysmall=2.5)\nplt.colorbar(m)\n```\n\nHow wonderful, how concise !\n\n## Acknowledgements\n\nThank Prof. Feng Zhu (NUIST,https://fzhu2e.github.io/) for his guidance of this project.\n\nThank for Prof. Tim Li (University of Hawaii at M\u0101noa, http://iprc.soest.hawaii.edu/people/li.php) ,Prof. Lin Chen (NUIST, https://faculty.nuist.edu.cn/chenlin12/zh_CN/index.htm) and Dr. Ming Sun (NUIST) 's help.\n\nSepcial thanks: Lifei Lin (Sun Yat-sen University) 's `repr_html.py` to visualize class in jupyter!\n\n\n# Change Log\n\n## version 0.0.1\n\nNothing!\n\n## version 0.0.5\n\nFirst official edition\n\n## version 0.0.6\n\nUpdated the speed test and changed small errors\n\n## version 0.0.7\n\nAdd examples and change README.md\n\n## version 0.0.9\n\nAdd mult_corr,partial_corr in LinReg.py and spec_moth_dat, spec_moth_yrmean in XrTools.\n\nChange examples.\n\n## version 0.0.10\n\nAdd EOF analysis\n\n## version 0.0.11\n\nChange Example Data\n\n## version 0.0.12\n\nFix a bug in XrTools\n\nAdd Map.py for quick plot\n\n## version 0.0.13\n\nChange example!\n\n## version 0.0.14\n\nAdd SVD(MCA) analysis and visualization of LinReg in Jupyter.\n\n## version 0.0.15\n\nAdd Map.py for test and new wrapper progress for Map.py and Linreg\n\n## version 0.0.16\n\nOptimized support for xarray\n\n## version 0.0.17\n\n1. update mask function for LinReg \n2. add shp mask function\n3. correct SVD\n\n## version 0.0.18\n\n1. add new function of EOF\n2. correct some errors of EOF and SVD \n\n## version 0.0.19 \n\n1. add new function for Map\n2. fix some errors of Map\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A repaid Statistical Analysis tool for Climate or Meteorology data.",
    "version": "0.0.24",
    "project_urls": {
        "Homepage": "https://github.com/ZiluM/sacpy"
    },
    "split_keywords": [
        "meteorology",
        "data",
        "statistic",
        "climate"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "787404ce38c7e2909a4964c9b9726559c6e59ce5e44ad41e556def6b1fda4f84",
                "md5": "605fcd8415421e6eba128ec5a503f606",
                "sha256": "c2a992386d7be444ab52c2b9a079a22b50f9ebc7dabff730533619c83800019a"
            },
            "downloads": -1,
            "filename": "sacpy-0.0.24-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "605fcd8415421e6eba128ec5a503f606",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 1821091,
            "upload_time": "2024-02-23T03:28:23",
            "upload_time_iso_8601": "2024-02-23T03:28:23.922515Z",
            "url": "https://files.pythonhosted.org/packages/78/74/04ce38c7e2909a4964c9b9726559c6e59ce5e44ad41e556def6b1fda4f84/sacpy-0.0.24-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "960a387759b7f8e475271cd85345d52e3aa1ef8212aa96abec7f9bcd0e754458",
                "md5": "f9f8b54ae6493259088e72c32868a26d",
                "sha256": "8fa315d2e11ac66c2f57bd7ac633ed367ca6a3341cede4b84e38ee1921ada5db"
            },
            "downloads": -1,
            "filename": "sacpy-0.0.24.tar.gz",
            "has_sig": false,
            "md5_digest": "f9f8b54ae6493259088e72c32868a26d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 1807859,
            "upload_time": "2024-02-23T03:28:27",
            "upload_time_iso_8601": "2024-02-23T03:28:27.392618Z",
            "url": "https://files.pythonhosted.org/packages/96/0a/387759b7f8e475271cd85345d52e3aa1ef8212aa96abec7f9bcd0e754458/sacpy-0.0.24.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-23 03:28:27",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ZiluM",
    "github_project": "sacpy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "sacpy"
}
        
Elapsed time: 0.25568s