Skip to content

Commit 2c3c589

Browse files
authored
Create client within ceof
I added the parallel option to build a standard client within the ceof function. In case the user doesn't want a standard client, he/she can turn the option to False and build the client with other settings.
1 parent a329446 commit 2c3c589

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

OceanLab/eof.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from dask import delayed
44
from scipy.signal import hilbert
55
import xarray as xr
6+
from dask.distributed import Client, LocalCluster
67

78
# functions
89
#=========================================
@@ -129,7 +130,7 @@ def my_eof_interp(M,nmodes,errmin=1e-15,repmax=None):
129130
#=========================================
130131
# PERFORM COMPLEX EOF
131132
#=========================================
132-
def ceof(lon, lat, data, nkp = 10):
133+
def ceof(lon, lat, data, nkp = 10, parallel = True):
133134
''' Complex (Hilbert) EOF to detect propagating features: waves, meanders, etc.
134135
Note: the mean field in each coordinate is subtracted within the function.
135136
Do not subtract the time-mean field before inputing.
@@ -140,22 +141,29 @@ def ceof(lon, lat, data, nkp = 10):
140141
(https://www.aos.wisc.edu/~dvimont/matlab/Stat_Tools/complex_eof.html)
141142
==============================================================================
142143
INPUT:
143-
lon = longitudes (array)
144-
lat = latitude (array)
145-
data = original data set [time, lat, lon]
146-
nkp = number of modes to return (default = 10)
144+
lon = longitudes (array)
145+
lat = latitude (array)
146+
data = original data set [time, lat, lon]
147+
nkp = number of modes to return (default = 10)
148+
parallel = create a standard client kernel for parallel computing
149+
[switch parallel to False, in case you created your own client]
147150
148151
OUTPUT:
149152
The variables below return inside a DataArray.
150-
per = percent variance explained (real eigenvalues)
151-
modes = first nkp complex loadings or eigenvectors [lat, lon, nkp]
152-
SpAmp = spatial amplitude [lat, lon, nkp]
153-
SpPhase = spatial phase [lat, lon, nkp]
154-
pcs = first nkp complex principal components or amplitudes [time, nkp]
155-
TAmp = temporal amplitude [time, nkp]
156-
TPhase = temporal phase [time, nkp]
153+
per = percent variance explained (real eigenvalues)
154+
modes = first nkp complex loadings or eigenvectors [lat, lon, nkp]
155+
SpAmp = spatial amplitude [lat, lon, nkp]
156+
SpPhase = spatial phase [lat, lon, nkp]
157+
pcs = first nkp complex principal components or amplitudes [time, nkp]
158+
TAmp = temporal amplitude [time, nkp]
159+
TPhase = temporal phase [time, nkp]
157160
==============================================================================
158161
'''
162+
# Configure client for parallel computing
163+
if parallel:
164+
cluster = LocalCluster()
165+
client = Client(cluster)
166+
159167
# Organizing the data as time vs space
160168
data_ceof = _org_data_ceof(lon, lat, data)
161169
# We need to remove the mean field (i.e., the trend) in each coordinate to

0 commit comments

Comments
 (0)