xvortices 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- xvortices-0.1.0/LICENSE +22 -0
- xvortices-0.1.0/MANIFEST.in +19 -0
- xvortices-0.1.0/PKG-INFO +151 -0
- xvortices-0.1.0/README.md +118 -0
- xvortices-0.1.0/notebooks/1.TCExample.ipynb +116 -0
- xvortices-0.1.0/notebooks/2.EddyExample.ipynb +129 -0
- xvortices-0.1.0/pyproject.toml +49 -0
- xvortices-0.1.0/requirements.txt +3 -0
- xvortices-0.1.0/scripts/benchmark_backend.py +87 -0
- xvortices-0.1.0/scripts/validate_ibtracs.py +63 -0
- xvortices-0.1.0/setup.cfg +4 -0
- xvortices-0.1.0/setup.py +199 -0
- xvortices-0.1.0/tests/test_core.py +205 -0
- xvortices-0.1.0/xvortices/__init__.py +18 -0
- xvortices-0.1.0/xvortices/_core_module.c +348 -0
- xvortices-0.1.0/xvortices/core.py +354 -0
- xvortices-0.1.0/xvortices/meson.build +103 -0
- xvortices-0.1.0/xvortices/py.typed +1 -0
- xvortices-0.1.0/xvortices/src/core.f90 +246 -0
- xvortices-0.1.0/xvortices/utils.py +225 -0
- xvortices-0.1.0/xvortices/xvortices.py +12 -0
- xvortices-0.1.0/xvortices.egg-info/PKG-INFO +151 -0
- xvortices-0.1.0/xvortices.egg-info/SOURCES.txt +24 -0
- xvortices-0.1.0/xvortices.egg-info/dependency_links.txt +1 -0
- xvortices-0.1.0/xvortices.egg-info/requires.txt +3 -0
- xvortices-0.1.0/xvortices.egg-info/top_level.txt +1 -0
xvortices-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Yu-Kun Qian
|
|
4
|
+
Copyright (c) 2026 Qianye Su
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
include LICENSE
|
|
2
|
+
include README.md
|
|
3
|
+
include pyproject.toml
|
|
4
|
+
include setup.py
|
|
5
|
+
include requirements.txt
|
|
6
|
+
recursive-include xvortices *.py *.typed *.c *.f90 meson.build
|
|
7
|
+
recursive-include tests *.py
|
|
8
|
+
recursive-include scripts *.py
|
|
9
|
+
recursive-include notebooks *.ipynb
|
|
10
|
+
global-exclude __pycache__
|
|
11
|
+
global-exclude *.py[cod]
|
|
12
|
+
global-exclude *.so
|
|
13
|
+
global-exclude *.pyd
|
|
14
|
+
global-exclude *.dll
|
|
15
|
+
global-exclude *.dylib
|
|
16
|
+
global-exclude *.dll.a
|
|
17
|
+
global-exclude *.o
|
|
18
|
+
global-exclude *.obj
|
|
19
|
+
prune xvortices/build
|
xvortices-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: xvortices
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Viewing vortices in a translating cylindrical coordinate
|
|
5
|
+
Home-page: https://github.com/QianyeSu/xvortices
|
|
6
|
+
Author: Qianye Su
|
|
7
|
+
Author-email: Qianye Su <suqianye2000@gmail.com>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
Project-URL: Homepage, https://github.com/QianyeSu/xvortices
|
|
10
|
+
Project-URL: Repository, https://github.com/QianyeSu/xvortices
|
|
11
|
+
Keywords: vortex,vortices,xarray,dask,numpy,typhoon
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: Topic :: Scientific/Engineering :: Atmospheric Science
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
21
|
+
Classifier: Operating System :: MacOS
|
|
22
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
23
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
24
|
+
Requires-Python: >=3.9
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
License-File: LICENSE
|
|
27
|
+
Requires-Dist: numpy
|
|
28
|
+
Requires-Dist: xarray
|
|
29
|
+
Requires-Dist: dask
|
|
30
|
+
Dynamic: author
|
|
31
|
+
Dynamic: home-page
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
|
|
34
|
+
# xvortices
|
|
35
|
+
|
|
36
|
+

|
|
37
|
+
|
|
38
|
+

|
|
39
|
+
|
|
40
|
+
## 1. Introduction
|
|
41
|
+
`xvortices` is a python package built on [`xarray`](http://xarray.pydata.org/en/stable/) (starts with an `x`), targeting at extracting information about moving vortices from lat/lon gridded datasets. Moving vortices include [tornado](https://en.wikipedia.org/wiki/Tornado), [tropical cyclone](https://en.wikipedia.org/wiki/Tropical_cyclone), [extratropical cyclone](https://en.wikipedia.org/wiki/Extratropical_cyclone), [polar vortex](https://en.wikipedia.org/wiki/Polar_vortex) in the atmospheric context, as well as [mesoscale eddy](https://en.wikipedia.org/wiki/Eddy_(fluid_dynamics)) and [ocean gyre](https://en.wikipedia.org/wiki/Ocean_gyre) in the oceanic context. These moving vortices are usually described in a moving (also known as quasi-Lagrangian) cylindrical coordinate. As the coordinate system moves on the spherical earth as a whole, one could take a view of the vortex dynamics from a quasi-Lagrangian perspective instead of the traditional Eulerian perspective.
|
|
42
|
+
|
|
43
|
+
Basically, this package would do the following jobs:
|
|
44
|
+
- accept an `xarray.Dataset` (or a list of `xarray.DataArray`) as an input dataset, usually in a fashion of lat/lon grid;
|
|
45
|
+
- interpolate the data onto the cylindrical coordinates once the origin of the moving coordinate is given;
|
|
46
|
+
- return the interpolated fields, including scalars and vectors;
|
|
47
|
+
- re-project the vectors onto the azimuthal/radial directions;
|
|
48
|
+
|
|
49
|
+
With this tool, one can perform quasi-Lagrangian diagnoses of the structure, evolution, budget, intensity etc in a perspective different from the Eulerian one.
|
|
50
|
+
|
|
51
|
+

|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## 2. How to install
|
|
56
|
+
**Requirements**
|
|
57
|
+
`xvortices` is developed under the environment with `numpy` (=version 1.15.4), `xarray` (=version 0.15.1), `matplotlib` (=version 3.4.3) and `cartopy` (=version 0.18.0). Older versions of these packages are not well tested.
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
**Install from github**
|
|
61
|
+
```
|
|
62
|
+
git clone https://github.com/QianyeSu/xvortices.git
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## 3. Examples
|
|
68
|
+
### 3.1 A moving tropical cyclone
|
|
69
|
+
Here we demonstrate an application to the case of a moving tropical cyclone (TC) over the western North Pacific. One may need [`besttracks`](https://github.com/miniufo/besttracks) to load TC best-track data and cooperate with `xvortices`:
|
|
70
|
+
```python
|
|
71
|
+
import xarray as xr
|
|
72
|
+
from xvortices import load_cylind, project_to_cylind
|
|
73
|
+
|
|
74
|
+
azimNum, radiNum, radMax = 72, 31, 6
|
|
75
|
+
|
|
76
|
+
# variables inside are [u, v, w, h]
|
|
77
|
+
dset = xr.open_dataset('gridded.nc')
|
|
78
|
+
|
|
79
|
+
# one can obtain tropical cyclone (TC) best-track
|
|
80
|
+
# data from the `besttracks` package
|
|
81
|
+
olon = TC.get_as_xarray('lon') # timeseries of center longitudes
|
|
82
|
+
olat = TC.get_as_xarray('lat') # timeseries of center latitudes
|
|
83
|
+
uovel = TC.get_as_xarray('uo') # timeseries of center u-vel
|
|
84
|
+
vovel = TC.get_as_xarray('vo') # timeseries of center v-vel
|
|
85
|
+
|
|
86
|
+
[u, v, w, h], lons, lats, etas = load_cylind(dset, olon=olon, olat=olat,
|
|
87
|
+
azimNum=azimNum, radiNum=radiNum,
|
|
88
|
+
radMax=radMax)
|
|
89
|
+
urel = u - uovel # storm-relative u
|
|
90
|
+
vrel = v - vorel # storm-relative v
|
|
91
|
+
|
|
92
|
+
# storm-relative azimuthal/radial winds
|
|
93
|
+
uaz, vra = project_to_cylind(urel, vrel, etas)
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+

|
|
97
|
+
|
|
98
|
+
Plotting its 3D structure is also easy:
|
|
99
|
+
```python
|
|
100
|
+
from xvortices import plot3D
|
|
101
|
+
|
|
102
|
+
# select the first time step to show
|
|
103
|
+
plot3D(lons[0], lats[0], uaz[0])
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+

|
|
107
|
+
|
|
108
|
+
More details can be found at this [TC notebook](./notebooks/1.TCExample.ipynb).
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
### 3.2 A moving mesoscale eddy
|
|
113
|
+
This is a mesoscale eddy case over the southern Indian Ocean.
|
|
114
|
+
```python
|
|
115
|
+
import pandas as pd
|
|
116
|
+
import xarray as xr
|
|
117
|
+
from xvortices import load_cylind, project_to_cylind
|
|
118
|
+
|
|
119
|
+
# load an eddy positions from the "Mesoscale Eddy Trajectory Atlas" product
|
|
120
|
+
eddy = pd.read_csv('d:/SETIO2021.txt', sep='\s+', index_col='time', parse_dates=True)
|
|
121
|
+
# load AVISO gridded sea level anomaly and associated flow
|
|
122
|
+
dset = xr.open_dataset('D:/dataset-duacs-nrt-global-merged-allsat-phy-l4_SETIO_Eddy.nc')
|
|
123
|
+
|
|
124
|
+
# parameters of the cylindrical coordinates
|
|
125
|
+
azimNum, radiNum, radMax = 72, 31, 3
|
|
126
|
+
|
|
127
|
+
# interpolate from lat/lon grid to cylindrical grid
|
|
128
|
+
azimNum, radiNum, radMax = 72, 31, 4
|
|
129
|
+
[sla, adt, ugos, vgos], lons, lats, etas = load_cylind(dset[['sla','adt','ugos','vgos']],
|
|
130
|
+
olon=eddy.lons.to_xarray(),
|
|
131
|
+
olat=eddy.lats.to_xarray(),
|
|
132
|
+
azimNum=azimNum, radiNum=radiNum,
|
|
133
|
+
radMax=radMax,
|
|
134
|
+
lonname='longitude',
|
|
135
|
+
latname='latitude')
|
|
136
|
+
|
|
137
|
+
# calculate eddy's translating speed
|
|
138
|
+
uo = (eddy['lons'].diff()/86400*np.cos(np.deg2rad(eddy['lats']))).to_xarray()
|
|
139
|
+
vo = (eddy['lats'].diff()/86400).to_xarray()
|
|
140
|
+
|
|
141
|
+
# calculate eddy-relative current components
|
|
142
|
+
u_r = ugos - uo
|
|
143
|
+
v_r = vgos - vo
|
|
144
|
+
|
|
145
|
+
# project u/v to azimuthal/radial components
|
|
146
|
+
uaz, vra = project_to_cylind(u_r, v_r, etas)
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+

|
|
150
|
+
|
|
151
|
+
More details can be found at this [notebook](./notebooks/2.EddyExample.ipynb).
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# xvortices
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
## 1. Introduction
|
|
8
|
+
`xvortices` is a python package built on [`xarray`](http://xarray.pydata.org/en/stable/) (starts with an `x`), targeting at extracting information about moving vortices from lat/lon gridded datasets. Moving vortices include [tornado](https://en.wikipedia.org/wiki/Tornado), [tropical cyclone](https://en.wikipedia.org/wiki/Tropical_cyclone), [extratropical cyclone](https://en.wikipedia.org/wiki/Extratropical_cyclone), [polar vortex](https://en.wikipedia.org/wiki/Polar_vortex) in the atmospheric context, as well as [mesoscale eddy](https://en.wikipedia.org/wiki/Eddy_(fluid_dynamics)) and [ocean gyre](https://en.wikipedia.org/wiki/Ocean_gyre) in the oceanic context. These moving vortices are usually described in a moving (also known as quasi-Lagrangian) cylindrical coordinate. As the coordinate system moves on the spherical earth as a whole, one could take a view of the vortex dynamics from a quasi-Lagrangian perspective instead of the traditional Eulerian perspective.
|
|
9
|
+
|
|
10
|
+
Basically, this package would do the following jobs:
|
|
11
|
+
- accept an `xarray.Dataset` (or a list of `xarray.DataArray`) as an input dataset, usually in a fashion of lat/lon grid;
|
|
12
|
+
- interpolate the data onto the cylindrical coordinates once the origin of the moving coordinate is given;
|
|
13
|
+
- return the interpolated fields, including scalars and vectors;
|
|
14
|
+
- re-project the vectors onto the azimuthal/radial directions;
|
|
15
|
+
|
|
16
|
+
With this tool, one can perform quasi-Lagrangian diagnoses of the structure, evolution, budget, intensity etc in a perspective different from the Eulerian one.
|
|
17
|
+
|
|
18
|
+

|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## 2. How to install
|
|
23
|
+
**Requirements**
|
|
24
|
+
`xvortices` is developed under the environment with `numpy` (=version 1.15.4), `xarray` (=version 0.15.1), `matplotlib` (=version 3.4.3) and `cartopy` (=version 0.18.0). Older versions of these packages are not well tested.
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
**Install from github**
|
|
28
|
+
```
|
|
29
|
+
git clone https://github.com/QianyeSu/xvortices.git
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## 3. Examples
|
|
35
|
+
### 3.1 A moving tropical cyclone
|
|
36
|
+
Here we demonstrate an application to the case of a moving tropical cyclone (TC) over the western North Pacific. One may need [`besttracks`](https://github.com/miniufo/besttracks) to load TC best-track data and cooperate with `xvortices`:
|
|
37
|
+
```python
|
|
38
|
+
import xarray as xr
|
|
39
|
+
from xvortices import load_cylind, project_to_cylind
|
|
40
|
+
|
|
41
|
+
azimNum, radiNum, radMax = 72, 31, 6
|
|
42
|
+
|
|
43
|
+
# variables inside are [u, v, w, h]
|
|
44
|
+
dset = xr.open_dataset('gridded.nc')
|
|
45
|
+
|
|
46
|
+
# one can obtain tropical cyclone (TC) best-track
|
|
47
|
+
# data from the `besttracks` package
|
|
48
|
+
olon = TC.get_as_xarray('lon') # timeseries of center longitudes
|
|
49
|
+
olat = TC.get_as_xarray('lat') # timeseries of center latitudes
|
|
50
|
+
uovel = TC.get_as_xarray('uo') # timeseries of center u-vel
|
|
51
|
+
vovel = TC.get_as_xarray('vo') # timeseries of center v-vel
|
|
52
|
+
|
|
53
|
+
[u, v, w, h], lons, lats, etas = load_cylind(dset, olon=olon, olat=olat,
|
|
54
|
+
azimNum=azimNum, radiNum=radiNum,
|
|
55
|
+
radMax=radMax)
|
|
56
|
+
urel = u - uovel # storm-relative u
|
|
57
|
+
vrel = v - vorel # storm-relative v
|
|
58
|
+
|
|
59
|
+
# storm-relative azimuthal/radial winds
|
|
60
|
+
uaz, vra = project_to_cylind(urel, vrel, etas)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+

|
|
64
|
+
|
|
65
|
+
Plotting its 3D structure is also easy:
|
|
66
|
+
```python
|
|
67
|
+
from xvortices import plot3D
|
|
68
|
+
|
|
69
|
+
# select the first time step to show
|
|
70
|
+
plot3D(lons[0], lats[0], uaz[0])
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+

|
|
74
|
+
|
|
75
|
+
More details can be found at this [TC notebook](./notebooks/1.TCExample.ipynb).
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
### 3.2 A moving mesoscale eddy
|
|
80
|
+
This is a mesoscale eddy case over the southern Indian Ocean.
|
|
81
|
+
```python
|
|
82
|
+
import pandas as pd
|
|
83
|
+
import xarray as xr
|
|
84
|
+
from xvortices import load_cylind, project_to_cylind
|
|
85
|
+
|
|
86
|
+
# load an eddy positions from the "Mesoscale Eddy Trajectory Atlas" product
|
|
87
|
+
eddy = pd.read_csv('d:/SETIO2021.txt', sep='\s+', index_col='time', parse_dates=True)
|
|
88
|
+
# load AVISO gridded sea level anomaly and associated flow
|
|
89
|
+
dset = xr.open_dataset('D:/dataset-duacs-nrt-global-merged-allsat-phy-l4_SETIO_Eddy.nc')
|
|
90
|
+
|
|
91
|
+
# parameters of the cylindrical coordinates
|
|
92
|
+
azimNum, radiNum, radMax = 72, 31, 3
|
|
93
|
+
|
|
94
|
+
# interpolate from lat/lon grid to cylindrical grid
|
|
95
|
+
azimNum, radiNum, radMax = 72, 31, 4
|
|
96
|
+
[sla, adt, ugos, vgos], lons, lats, etas = load_cylind(dset[['sla','adt','ugos','vgos']],
|
|
97
|
+
olon=eddy.lons.to_xarray(),
|
|
98
|
+
olat=eddy.lats.to_xarray(),
|
|
99
|
+
azimNum=azimNum, radiNum=radiNum,
|
|
100
|
+
radMax=radMax,
|
|
101
|
+
lonname='longitude',
|
|
102
|
+
latname='latitude')
|
|
103
|
+
|
|
104
|
+
# calculate eddy's translating speed
|
|
105
|
+
uo = (eddy['lons'].diff()/86400*np.cos(np.deg2rad(eddy['lats']))).to_xarray()
|
|
106
|
+
vo = (eddy['lats'].diff()/86400).to_xarray()
|
|
107
|
+
|
|
108
|
+
# calculate eddy-relative current components
|
|
109
|
+
u_r = ugos - uo
|
|
110
|
+
v_r = vgos - vo
|
|
111
|
+
|
|
112
|
+
# project u/v to azimuthal/radial components
|
|
113
|
+
uaz, vra = project_to_cylind(u_r, v_r, etas)
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+

|
|
117
|
+
|
|
118
|
+
More details can be found at this [notebook](./notebooks/2.EddyExample.ipynb).
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
{
|
|
2
|
+
"cells": [
|
|
3
|
+
{
|
|
4
|
+
"cell_type": "markdown",
|
|
5
|
+
"id": "26147d64",
|
|
6
|
+
"metadata": {},
|
|
7
|
+
"source": [
|
|
8
|
+
"# Tropical cyclone cylindrical transform\n",
|
|
9
|
+
"\n",
|
|
10
|
+
"Runnable smoke notebook for the Fortran-backed xvortices core."
|
|
11
|
+
]
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"cell_type": "code",
|
|
15
|
+
"execution_count": null,
|
|
16
|
+
"id": "9c0aa2c1",
|
|
17
|
+
"metadata": {
|
|
18
|
+
"execution": {
|
|
19
|
+
"iopub.execute_input": "2026-06-22T10:40:29.904839Z",
|
|
20
|
+
"iopub.status.busy": "2026-06-22T10:40:29.903840Z",
|
|
21
|
+
"iopub.status.idle": "2026-06-22T10:40:35.096187Z",
|
|
22
|
+
"shell.execute_reply": "2026-06-22T10:40:35.094671Z"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"outputs": [],
|
|
26
|
+
"source": [
|
|
27
|
+
"from pathlib import Path\n",
|
|
28
|
+
"import sys\n",
|
|
29
|
+
"\n",
|
|
30
|
+
"import numpy as np\n",
|
|
31
|
+
"import xarray as xr\n",
|
|
32
|
+
"\n",
|
|
33
|
+
"sys.path.insert(0, str(Path.cwd().parent if Path.cwd().name == 'notebooks' else Path.cwd()))\n",
|
|
34
|
+
"from xvortices import load_cylind, project_to_cylind, storm_relative\n",
|
|
35
|
+
"\n",
|
|
36
|
+
"root = Path.cwd().parent if Path.cwd().name == 'notebooks' else Path.cwd()\n",
|
|
37
|
+
"ds = xr.open_dataset(root / 'Data' / 'Haima2004.nc')\n",
|
|
38
|
+
"ds = ds[['u', 'v', 'w', 'h']].isel(lev=slice(0, 8))\n",
|
|
39
|
+
"ds"
|
|
40
|
+
]
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"cell_type": "code",
|
|
44
|
+
"execution_count": null,
|
|
45
|
+
"id": "be37e289",
|
|
46
|
+
"metadata": {
|
|
47
|
+
"execution": {
|
|
48
|
+
"iopub.execute_input": "2026-06-22T10:40:35.101187Z",
|
|
49
|
+
"iopub.status.busy": "2026-06-22T10:40:35.100189Z",
|
|
50
|
+
"iopub.status.idle": "2026-06-22T10:40:35.164655Z",
|
|
51
|
+
"shell.execute_reply": "2026-06-22T10:40:35.163648Z"
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
"outputs": [],
|
|
55
|
+
"source": [
|
|
56
|
+
"times = ds.time\n",
|
|
57
|
+
"olon = xr.DataArray(np.linspace(121.0, 131.5, times.size), dims=('time',), coords={'time': times}, name='olon')\n",
|
|
58
|
+
"olat = xr.DataArray(np.linspace(17.0, 25.0, times.size), dims=('time',), coords={'time': times}, name='olat')\n",
|
|
59
|
+
"\n",
|
|
60
|
+
"fields, lons, lats, etas = load_cylind(ds, olon=olon, olat=olat, azimNum=72, radiNum=31, radMax=6)\n",
|
|
61
|
+
"u, v, w, h = fields\n",
|
|
62
|
+
"assert u.dims == ('time', 'lev', 'radi', 'azim')\n",
|
|
63
|
+
"assert lons.dims == ('time', 'radi', 'azim')\n",
|
|
64
|
+
"float(u.mean())"
|
|
65
|
+
]
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
"cell_type": "code",
|
|
69
|
+
"execution_count": null,
|
|
70
|
+
"id": "179ab7a2",
|
|
71
|
+
"metadata": {
|
|
72
|
+
"execution": {
|
|
73
|
+
"iopub.execute_input": "2026-06-22T10:40:35.167655Z",
|
|
74
|
+
"iopub.status.busy": "2026-06-22T10:40:35.166655Z",
|
|
75
|
+
"iopub.status.idle": "2026-06-22T10:40:35.235061Z",
|
|
76
|
+
"shell.execute_reply": "2026-06-22T10:40:35.233988Z"
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
"outputs": [],
|
|
80
|
+
"source": [
|
|
81
|
+
"uaz, vra = project_to_cylind(u, v, etas)\n",
|
|
82
|
+
"uc = xr.DataArray(np.gradient(olon.values), dims=('time',), coords={'time': times})\n",
|
|
83
|
+
"vc = xr.DataArray(np.gradient(olat.values), dims=('time',), coords={'time': times})\n",
|
|
84
|
+
"uaz_rel, vra_rel = storm_relative(uc, vc, uaz, vra)\n",
|
|
85
|
+
"\n",
|
|
86
|
+
"summary = xr.Dataset({\n",
|
|
87
|
+
" 'azimuthal_mean_wind': uaz_rel.mean(('time', 'azim')),\n",
|
|
88
|
+
" 'radial_mean_wind': vra_rel.mean(('time', 'azim')),\n",
|
|
89
|
+
" 'height_anomaly': (h - h.mean('azim')).mean('time'),\n",
|
|
90
|
+
"})\n",
|
|
91
|
+
"summary"
|
|
92
|
+
]
|
|
93
|
+
}
|
|
94
|
+
],
|
|
95
|
+
"metadata": {
|
|
96
|
+
"kernelspec": {
|
|
97
|
+
"display_name": "Python 3",
|
|
98
|
+
"language": "python",
|
|
99
|
+
"name": "python3"
|
|
100
|
+
},
|
|
101
|
+
"language_info": {
|
|
102
|
+
"codemirror_mode": {
|
|
103
|
+
"name": "ipython",
|
|
104
|
+
"version": 3
|
|
105
|
+
},
|
|
106
|
+
"file_extension": ".py",
|
|
107
|
+
"mimetype": "text/x-python",
|
|
108
|
+
"name": "python",
|
|
109
|
+
"nbconvert_exporter": "python",
|
|
110
|
+
"pygments_lexer": "ipython3",
|
|
111
|
+
"version": "3.12.11"
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
"nbformat": 4,
|
|
115
|
+
"nbformat_minor": 5
|
|
116
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
{
|
|
2
|
+
"cells": [
|
|
3
|
+
{
|
|
4
|
+
"cell_type": "markdown",
|
|
5
|
+
"id": "d65174a1",
|
|
6
|
+
"metadata": {},
|
|
7
|
+
"source": [
|
|
8
|
+
"# Ocean eddy cylindrical transform\n",
|
|
9
|
+
"\n",
|
|
10
|
+
"Runnable smoke notebook for the Fortran-backed xvortices core."
|
|
11
|
+
]
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"cell_type": "code",
|
|
15
|
+
"execution_count": null,
|
|
16
|
+
"id": "ee20c234",
|
|
17
|
+
"metadata": {
|
|
18
|
+
"execution": {
|
|
19
|
+
"iopub.execute_input": "2026-06-22T10:40:37.833990Z",
|
|
20
|
+
"iopub.status.busy": "2026-06-22T10:40:37.833990Z",
|
|
21
|
+
"iopub.status.idle": "2026-06-22T10:40:40.882408Z",
|
|
22
|
+
"shell.execute_reply": "2026-06-22T10:40:40.881396Z"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"outputs": [],
|
|
26
|
+
"source": [
|
|
27
|
+
"from pathlib import Path\n",
|
|
28
|
+
"import sys\n",
|
|
29
|
+
"\n",
|
|
30
|
+
"import numpy as np\n",
|
|
31
|
+
"import xarray as xr\n",
|
|
32
|
+
"\n",
|
|
33
|
+
"sys.path.insert(0, str(Path.cwd().parent if Path.cwd().name == 'notebooks' else Path.cwd()))\n",
|
|
34
|
+
"from xvortices import load_cylind, project_to_cylind, storm_relative\n",
|
|
35
|
+
"\n",
|
|
36
|
+
"time = np.arange(12)\n",
|
|
37
|
+
"lat = np.linspace(-40, -20, 161)\n",
|
|
38
|
+
"lon = np.linspace(140, 180, 241)\n",
|
|
39
|
+
"lon2d, lat2d = np.meshgrid(lon, lat)\n",
|
|
40
|
+
"\n",
|
|
41
|
+
"olon = xr.DataArray(np.linspace(150, 166, time.size), dims=('time',), coords={'time': time})\n",
|
|
42
|
+
"olat = xr.DataArray(-30 + 2 * np.sin(np.linspace(0, 2*np.pi, time.size)), dims=('time',), coords={'time': time})\n",
|
|
43
|
+
"\n",
|
|
44
|
+
"frames = []\n",
|
|
45
|
+
"for x0, y0 in zip(olon.values, olat.values):\n",
|
|
46
|
+
" r2 = (lon2d - x0) ** 2 + (lat2d - y0) ** 2\n",
|
|
47
|
+
" sla = np.exp(-r2 / 18.0)\n",
|
|
48
|
+
" ugos = -(lat2d - y0) * sla / 5.0\n",
|
|
49
|
+
" vgos = (lon2d - x0) * sla / 5.0\n",
|
|
50
|
+
" frames.append(np.stack([sla, ugos, vgos], axis=0))\n",
|
|
51
|
+
"arr = np.stack(frames, axis=0)\n",
|
|
52
|
+
"ds = xr.Dataset(\n",
|
|
53
|
+
" {name: (('time', 'lat', 'lon'), arr[:, i]) for i, name in enumerate(['sla', 'ugos', 'vgos'])},\n",
|
|
54
|
+
" coords={'time': time, 'lat': lat, 'lon': lon},\n",
|
|
55
|
+
")\n",
|
|
56
|
+
"ds"
|
|
57
|
+
]
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"cell_type": "code",
|
|
61
|
+
"execution_count": null,
|
|
62
|
+
"id": "f46bf514",
|
|
63
|
+
"metadata": {
|
|
64
|
+
"execution": {
|
|
65
|
+
"iopub.execute_input": "2026-06-22T10:40:40.889938Z",
|
|
66
|
+
"iopub.status.busy": "2026-06-22T10:40:40.888939Z",
|
|
67
|
+
"iopub.status.idle": "2026-06-22T10:40:40.941581Z",
|
|
68
|
+
"shell.execute_reply": "2026-06-22T10:40:40.939573Z"
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
"outputs": [],
|
|
72
|
+
"source": [
|
|
73
|
+
"fields, lons, lats, etas = load_cylind(ds, olon=olon, olat=olat, azimNum=90, radiNum=41, radMax=5)\n",
|
|
74
|
+
"sla, ugos, vgos = fields\n",
|
|
75
|
+
"uaz, vra = project_to_cylind(ugos, vgos, etas)\n",
|
|
76
|
+
"uc = xr.DataArray(np.gradient(olon.values), dims=('time',), coords={'time': time})\n",
|
|
77
|
+
"vc = xr.DataArray(np.gradient(olat.values), dims=('time',), coords={'time': time})\n",
|
|
78
|
+
"uaz_rel, vra_rel = storm_relative(uc, vc, uaz, vra)\n",
|
|
79
|
+
"\n",
|
|
80
|
+
"assert sla.dims == ('time', 'radi', 'azim')\n",
|
|
81
|
+
"assert np.isfinite(sla).any()\n",
|
|
82
|
+
"float(uaz_rel.mean())"
|
|
83
|
+
]
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"cell_type": "code",
|
|
87
|
+
"execution_count": null,
|
|
88
|
+
"id": "b89b93f3",
|
|
89
|
+
"metadata": {
|
|
90
|
+
"execution": {
|
|
91
|
+
"iopub.execute_input": "2026-06-22T10:40:40.945582Z",
|
|
92
|
+
"iopub.status.busy": "2026-06-22T10:40:40.944582Z",
|
|
93
|
+
"iopub.status.idle": "2026-06-22T10:40:40.983835Z",
|
|
94
|
+
"shell.execute_reply": "2026-06-22T10:40:40.982827Z"
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
"outputs": [],
|
|
98
|
+
"source": [
|
|
99
|
+
"azimuthal_structure = xr.Dataset({\n",
|
|
100
|
+
" 'sla_mean': sla.mean('azim'),\n",
|
|
101
|
+
" 'tangential_mean': uaz_rel.mean('azim'),\n",
|
|
102
|
+
" 'radial_mean': vra_rel.mean('azim'),\n",
|
|
103
|
+
"})\n",
|
|
104
|
+
"azimuthal_structure"
|
|
105
|
+
]
|
|
106
|
+
}
|
|
107
|
+
],
|
|
108
|
+
"metadata": {
|
|
109
|
+
"kernelspec": {
|
|
110
|
+
"display_name": "Python 3",
|
|
111
|
+
"language": "python",
|
|
112
|
+
"name": "python3"
|
|
113
|
+
},
|
|
114
|
+
"language_info": {
|
|
115
|
+
"codemirror_mode": {
|
|
116
|
+
"name": "ipython",
|
|
117
|
+
"version": 3
|
|
118
|
+
},
|
|
119
|
+
"file_extension": ".py",
|
|
120
|
+
"mimetype": "text/x-python",
|
|
121
|
+
"name": "python",
|
|
122
|
+
"nbconvert_exporter": "python",
|
|
123
|
+
"pygments_lexer": "ipython3",
|
|
124
|
+
"version": "3.12.11"
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
"nbformat": 4,
|
|
128
|
+
"nbformat_minor": 5
|
|
129
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = [
|
|
3
|
+
"setuptools>=61.0",
|
|
4
|
+
"wheel",
|
|
5
|
+
"numpy>=1.24.0",
|
|
6
|
+
"meson",
|
|
7
|
+
"ninja",
|
|
8
|
+
]
|
|
9
|
+
build-backend = "setuptools.build_meta"
|
|
10
|
+
|
|
11
|
+
[project]
|
|
12
|
+
name = "xvortices"
|
|
13
|
+
dynamic = ["version", "dependencies"]
|
|
14
|
+
description = "Viewing vortices in a translating cylindrical coordinate"
|
|
15
|
+
readme = "README.md"
|
|
16
|
+
authors = [{ name = "Qianye Su", email = "suqianye2000@gmail.com" }]
|
|
17
|
+
license = "MIT"
|
|
18
|
+
license-files = ["LICENSE"]
|
|
19
|
+
requires-python = ">=3.9"
|
|
20
|
+
keywords = ["vortex", "vortices", "xarray", "dask", "numpy", "typhoon"]
|
|
21
|
+
classifiers = [
|
|
22
|
+
"Intended Audience :: Science/Research",
|
|
23
|
+
"Topic :: Scientific/Engineering :: Atmospheric Science",
|
|
24
|
+
"Programming Language :: Python :: 3",
|
|
25
|
+
"Programming Language :: Python :: 3.9",
|
|
26
|
+
"Programming Language :: Python :: 3.10",
|
|
27
|
+
"Programming Language :: Python :: 3.11",
|
|
28
|
+
"Programming Language :: Python :: 3.12",
|
|
29
|
+
"Programming Language :: Python :: 3.13",
|
|
30
|
+
"Programming Language :: Python :: 3.14",
|
|
31
|
+
"Operating System :: MacOS",
|
|
32
|
+
"Operating System :: Microsoft :: Windows",
|
|
33
|
+
"Operating System :: POSIX :: Linux",
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
[project.urls]
|
|
37
|
+
Homepage = "https://github.com/QianyeSu/xvortices"
|
|
38
|
+
Repository = "https://github.com/QianyeSu/xvortices"
|
|
39
|
+
|
|
40
|
+
[tool.setuptools]
|
|
41
|
+
packages = ["xvortices"]
|
|
42
|
+
|
|
43
|
+
[tool.setuptools.dynamic]
|
|
44
|
+
version = { attr = "xvortices.__version__" }
|
|
45
|
+
dependencies = { file = ["requirements.txt"] }
|
|
46
|
+
|
|
47
|
+
[tool.pytest.ini_options]
|
|
48
|
+
testpaths = ["tests"]
|
|
49
|
+
python_files = ["test_*.py"]
|