Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
23 changes: 7 additions & 16 deletions OceanLab/eof.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import numpy as np
import scipy.linalg as la
from dask import delayed
from scipy.signal import hilbert
import xarray as xr
from dask.distributed import Client, LocalCluster

# functions
#=========================================
Expand Down Expand Up @@ -130,23 +128,21 @@ def my_eof_interp(M,nmodes,errmin=1e-15,repmax=None):
#=========================================
# PERFORM COMPLEX EOF
#=========================================
def ceof(lon, lat, data, nkp = 10, parallel = True):
def ceof(lon, lat, data, nkp = 10):
''' Complex (Hilbert) EOF to detect propagating features: waves, meanders, etc.
Note: the mean field in each coordinate is subtracted within the function.
Do not subtract the time-mean field before inputing.
NaN values are removed in the algorithm.
NaN values are removed in the algorithm.
The user can input the data as it is.
First written in MATLAB and found in Prof. Daniel J. Vimont webpage

First written in MATLAB and found in Prof. Daniel J. Vimont webpage
(https://www.aos.wisc.edu/~dvimont/matlab/Stat_Tools/complex_eof.html)
==============================================================================
INPUT:
lon = longitudes (array)
lat = latitude (array)
data = original data set [time, lat, lon]
nkp = number of modes to return (default = 10)
parallel = create a standard client kernel for parallel computing
[switch parallel to False, in case you created your own client]

OUTPUT:
The variables below return inside a DataArray.
Expand All @@ -158,12 +154,7 @@ def ceof(lon, lat, data, nkp = 10, parallel = True):
TAmp = temporal amplitude [time, nkp]
TPhase = temporal phase [time, nkp]
==============================================================================
'''
# Configure client for parallel computing
if parallel:
cluster = LocalCluster()
client = Client(cluster)

'''
# Organizing the data as time vs space
data_ceof = _org_data_ceof(lon, lat, data)
# We need to remove the mean field (i.e., the trend) in each coordinate to
Expand All @@ -184,9 +175,9 @@ def ceof(lon, lat, data, nkp = 10, parallel = True):
data_hilbert = hilbert(data_ceof)
# Compute the covariance matrix in the Hilbert transform
print('2: Computing covariance matrix')
c = delayed(np.dot)(data_hilbert.conjugate().T, data_hilbert).compute()/ntim
c = np.dot(data_hilbert.conjugate().T, data_hilbert)/ntim
print('3: Solving the eigenvalue problem')
lamda, loadings = delayed(la.eig)(c).compute() # lamda: eigenvalue, loadings: eigenvectors
lamda, loadings = la.eig(c) # lamda: eigenvalue, loadings: eigenvectors

l = lamda.conjugate().T
k = np.argsort(l)
Expand Down
27 changes: 0 additions & 27 deletions OceanLab/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import scipy.signal as sg
import xarray as xr

from dask.distributed import Client

##### User functions
#=============================================================================
# NEAREST DISTANCE
Expand Down Expand Up @@ -133,29 +131,4 @@ def timefilter(prop,filtdays=60):
return m_prop,p_prop
#=============================================================================

##### Functions for relative imports
# =============================================================================
# KERNEL FOR PARALLEL COMPUTING
# =============================================================================
def _parallel_client(cpu_params=dict(tpw=2,nw=4,ml=7.5)):
"""
Create client kernel for parallel computing
====================================================
INPUT:
-> cpu_params: dict containing floats with keys
-> tpw: threads_per_worker
-> nw: n_workers
-> ml: memory_limit per worker [GB]
OUTPUT:
-> client: configuration of parallel computing
====================================================
"""

client = Client(threads_per_worker=cpu_params['tpw'],
n_workers=cpu_params['nw'],
memory_limit=str(cpu_params['ml'])+'GB')
return client
#=============================================================================



12 changes: 3 additions & 9 deletions examples/DYN_EOF.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,10 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from sympy import *\n",
"from OceanLab import EOF,DYN\n",
"import seawater as sw"
]
"source": "import numpy as np\nimport matplotlib.pyplot as plt\nfrom sympy import *\nimport OceanLab.eof as EOF\nimport OceanLab.dyn as DYN\nimport seawater as sw"
},
{
"cell_type": "code",
Expand Down Expand Up @@ -447,4 +441,4 @@
},
"nbformat": 4,
"nbformat_minor": 4
}
}
11 changes: 3 additions & 8 deletions examples/OA.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@
"cells": [
{
"cell_type": "code",
"execution_count": 102,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from sympy import *\n",
"from OceanLab import OA"
]
"source": "import numpy as np\nimport matplotlib.pyplot as plt\nfrom sympy import *\nimport OceanLab.oa as OA"
},
{
"cell_type": "code",
Expand Down Expand Up @@ -168,4 +163,4 @@
},
"nbformat": 4,
"nbformat_minor": 4
}
}
4 changes: 1 addition & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
numpy >= 1.8.2
seawater >= 3.3.1
numpy >= 1.8.2
scipy >= 1.6.3
xarray >= 0.18.2
dask >= 2021.06.0
dask[distributed] >= 2021.06.0
10 changes: 4 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@ def read(file):
"Operating System :: OS Independent",
],
install_requires = [
'seawater ~= 3.3',
'numpy ~= 1.18',
'scipy ~= 1.6',
'xarray ~= 0.18',
'dask ~= 2021.06',
'dask[distributed] ~= 2021.06'
'seawater >= 3.3',
'numpy >= 1.8.2',
'scipy >= 1.6',
'xarray >= 0.18',
],
)