Skip to content

Commit 2b170e7

Browse files
authored
Merge pull request #8 from iuryt/MeanEddy
added mean-eddy decomposition function to utils
2 parents 1e20305 + 5cc9ede commit 2b170e7

File tree

5 files changed

+259
-85
lines changed

5 files changed

+259
-85
lines changed

OceanLab/__init.py__

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from .dyn import zeta, vmode_amp, psi2uv, eqmodes, vmodes
22
from .eof import my_eof_interp, eoft
33
from .oa import scaloa, vectoa
4-
from utils import argdistnear
4+
from .utils import argdistnear, meaneddy
55

6-
__version__ = '0.0.7'
6+
_version_ = '0.1.0'

OceanLab/dyn.py

Lines changed: 101 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,36 @@
22
import numpy as np
33
import seawater as sw
44

5+
# ===========================================================
6+
# DYNAMICAL MODES AMPLITUDE
7+
# ===========================================================
58
def vmode_amp(A,vi):
69
'''
710
This function makes the projection of every vertical mode to
8-
timeseries or section matrix to obtain its amplitude. It will be used to
9-
data reconstruction.
11+
timeseries or section matrix to obtain its amplitude.
12+
It will be used to data reconstruction.
1013
1114
Operation: ((A'*A)^-1)*(A'*vi)
15+
=============================================================
16+
17+
INPUT:
18+
A =
19+
vi =
1220
21+
OUTPUT:
22+
AMP =
23+
24+
==============================================================
1325
'''
14-
return np.dot(np.linalg.inv(np.dot(A.T,A)),np.dot(A.T,vi))
1526

27+
return np.dot(np.linalg.inv(np.dot(A.T,A)),np.dot(A.T,vi))
1628

29+
# ===========================================================
30+
# RELATIVE VORTICITY
31+
# ===========================================================
1732
def zeta(x,y,U,V):
1833
'''
19-
ZETA k-component of rotational by velocity field
34+
ZETA k-component of rotational by velocity field
2035
Returns the scalar field of vorticity from U and V
2136
velocity components. X and Y are longitude and latitude
2237
matrices, respectively, as U and V. All matrices have
@@ -39,25 +54,24 @@ def zeta(x,y,U,V):
3954
(JM = 0) o ---------- o ---------- o ---------- o --- ...
4055
(IM = 0) (IM = 1) (IM = 2) (IM = 3)
4156
42-
-----------------------------------------------------------------
57+
================================================================
58+
USAGE: ZETA = zeta(x,y,u,v)
4359
44-
USAGE: u,v = psi2uv(x,y,psi)
60+
INPUT:
61+
x = decimal degrees (+ve E, -ve W) [-180..+180]
62+
y = decimal degrees (+ve N, -ve S) [- 90.. +90]
63+
u = velocity zonal component [m s^-1]
64+
v = velocity meridional component [m s^-1]
4565
46-
INPUT:
47-
x = decimal degrees (+ve E, -ve W) [-180..+180]
48-
y = decimal degrees (+ve N, -ve S) [- 90.. +90]
49-
u = velocity zonal component [m s^-1]
50-
v = velocity meridional component [m s^-1]
66+
OUTPUT:
67+
ZETA = Relative vorticity field [s^-1]
5168
52-
OUTPUT:
53-
ZETA = Relative vorticity field [s^-1]
54-
55-
AUTHOR:
69+
AUTHOR:
5670
Iury T. Simoes-Sousa and Wandrey Watanabe - 29 Jun 2016
5771
Laboratório de Dinâmica Oceânica - IOUSP
58-
======================================================================
59-
72+
================================================================
6073
'''
74+
6175
#função para cálculo de ângulos
6276
angcalc = lambda dy,dx: np.math.atan2(dy,dx)
6377

@@ -116,16 +130,21 @@ def zeta(x,y,U,V):
116130

117131
return ZETA
118132

133+
# ===========================================================
134+
# U AND V FROM STREAMFUNCTION
135+
# ===========================================================
119136
def psi2uv(x,y,psi):
120137
'''
121-
PSI2UV Velocity components from streamfunction
122-
Returns the velocity components U and V
123-
from streamfunction PSI. X and Y are longitude and latitude matrices,
124-
respectively, as PSI. All matrices have same dimension.
138+
PSI2UV Velocity components from streamfunction
125139
126-
--> !!! IMPORTANT !!! <-----------------------------------------
127-
The grid indexes IM and JM must have origin on the left-inferior
128-
corner, increasing to right and to up, respectively.
140+
Returns the velocity components U and V
141+
from streamfunction PSI. X and Y are longitude and latitude
142+
matrices, respectively, as PSI.
143+
All matrices have same dimension.
144+
145+
--> !!! IMPORTANT !!! <-----------------------------------
146+
The grid indexes IM and JM must have origin on the
147+
lower-left corner, increasing to right and to up.
129148
130149
GRID
131150
: : : :
@@ -139,23 +158,24 @@ def psi2uv(x,y,psi):
139158
(JM = 0) o ---------- o ---------- o ---------- o --- ...
140159
(IM = 0) (IM = 1) (IM = 2) (IM = 3)
141160
142-
-----------------------------------------------------------------
161+
==============================================================
143162
144-
USAGE: u,v = psi2uv(x,y,psi)
163+
USAGE: u,v = psi2uv(x,y,psi)
145164
146-
INPUT:
147-
x = decimal degrees (+ve E, -ve W) [-180..+180]
148-
y = decimal degrees (+ve N, -ve S) [- 90.. +90]
149-
psi = streamfunction [m^2 s^-1]
165+
INPUT:
166+
x = decimal degrees (+ve E, -ve W) [-180..+180]
167+
y = decimal degrees (+ve N, -ve S) [- 90.. +90]
168+
psi = streamfunction [m^2 s^-1]
150169
151-
OUTPUT:
152-
u = velocity zonal component [m s^-1]
153-
v = velocity meridional component [m s^-1]
170+
OUTPUT:
171+
u = velocity zonal component [m s^-1]
172+
v = velocity meridional component [m s^-1]
154173
155-
AUTHOR:
156-
Iury T. Simoes-Sousa and Wandrey Watanabe - 12 May 2016
157-
Laboratório de Dinâmica Oceânica - IOUSP
158-
======================================================================
174+
AUTHOR:
175+
Iury T. Simoes-Sousa and Wandrey Watanabe
176+
May 2016 - Laboratório de Dinâmica Oceânica - IOUSP
177+
Universidade de São Paulo
178+
==========================================================
159179
'''
160180

161181
#função para cálculo de ângulos
@@ -210,45 +230,38 @@ def psi2uv(x,y,psi):
210230

211231
return U,V
212232

213-
233+
# ===========================================================
234+
# EQUATORIAL MODES
235+
# ===========================================================
214236
def eqmodes(N2,z,nm,lat,pmodes=False):
215237
'''
216238
This function computes the equatorial velocity modes
217239
218-
========================================================
219-
220-
Input:
221-
222-
N2 - Brunt-Vaisala frequency data array
223-
224-
z - Depth data array (equaly spaced)
225-
226-
lat - Latitude scalar
227-
228-
nm - Number of modes to be computed
229-
230-
pmodes - If the return of pressure modes is required.
231-
Default is False
232-
233-
========================================================
234-
235-
Output:
236-
237-
Si - Equatorial modes matrix with MxN dimension being:
238-
M = z array size
239-
N = nm
240-
241-
Rdi - Deformation Radii array
242-
243-
Fi - Pressure modes matrix with MxN dimension being:
244-
M = z array size
245-
N = nm
246-
247-
Returned only if input pmodes=True
248-
249-
made by Iury T. Simoes-Sousa, Hélio Almeida and Wandrey Watanabe
250-
Laboratório de Dinâmica Oceânica - Universidade de São Paulo
251-
2016
240+
============================================================
241+
242+
INPUT:
243+
N2 = Brunt-Vaisala frequency data array
244+
z = Depth data array (equaly spaced)
245+
lat = Latitude scalar
246+
nm = Number of modes to be computed
247+
pmodes = If the return of pressure modes is required.
248+
(Default is False)
249+
250+
OUTPUT:
251+
Si = Equatorial modes matrix with MxN dimension being:
252+
M = z array size
253+
N = nm
254+
Rdi = Deformation Radii array
255+
Fi = Pressure modes matrix with MxN dimension being:
256+
M = z array size
257+
N = nm
258+
(Returned only if input pmodes=True)
259+
260+
AUTHOR:
261+
Iury T. Simoes-Sousa, Hélio Almeida and Wandrey Watanabe
262+
2016 Laboratório de Dinâmica Oceânica
263+
Universidade de São Paulo
264+
============================================================
252265
'''
253266

254267
#nm will be the number of baroclinic modes
@@ -352,8 +365,22 @@ def eqmodes(N2,z,nm,lat,pmodes=False):
352365
return Si,radii
353366

354367

355-
368+
# ===========================================================
369+
# DYNAMICAL MODES
370+
# ===========================================================
356371
def vmodes(N2,z,nm,lat,ubdy='N',lbdy='N'):
372+
373+
"""
374+
375+
========================================================
376+
INPUT:
377+
378+
OUTPUT:
379+
380+
AUTHOR:
381+
========================================================
382+
"""
383+
357384
f0 = sw.f(lat)
358385
dz = np.abs(z[1] - z[0])
359386

@@ -417,4 +444,4 @@ def vmodes(N2,z,nm,lat,ubdy='N',lbdy='N'):
417444
radii[0] = np.sqrt(9.81*H)/np.abs(f0)/1000
418445
radii[1:] = 1/np.sqrt(ei[1:])/1000
419446

420-
return fi, radii
447+
return fi, radii

0 commit comments

Comments
 (0)