Skip to content

Commit 0d4529d

Browse files
v2.0.1 Replace cppEDM with numpy/scipy
1 parent a72bd52 commit 0d4529d

File tree

125 files changed

+5504
-12624
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+5504
-12624
lines changed

.gitignore

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1+
etc
12
__pycache__
2-
cppEDM/lib/
3-
pyEDM/__pycache__
4-
pyEDM/tests/__pycache__
3+
src/pyEDM.egg-info
4+
src/pyEDM/__pycache__
5+
src/pyEDM/tests/__pycache__

CITATION.cff

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
cff-version: 1.2.0
22
title: pyEDM
33
message: >-
4-
If you use this software please cite. Licensed by the
5-
University of California for educational, research and
6-
non-profit purposes.
4+
If you use this software please cite.
75
type: software
86
authors:
97
- given-names: Joseph
108
family-names: Park
119
1210
orcid: 'https://orcid.org/0000-0001-5411-1409'
13-
- given-names: Cameron
14-
family-names: Smith
15-
orcid: 'https://orcid.org/0000-0003-0020-5607'
16-
1711
- {}
1812
identifiers:
1913
- type: url
@@ -22,5 +16,5 @@ repository-code: 'https://github.com/SugiharaLab/pyEDM'
2216
url: 'https://github.com/SugiharaLab/pyEDM#readme'
2317
repository: 'https://pypi.org/project/pyEDM/'
2418
abstract: >-
25-
Python wrapper of C++ EDM tools. UCSD Scripps Institution
26-
of Oceanography, Sugihara Lab.
19+
Python implementation of EDM tools developed at the
20+
Sugihara Lab, UCSD Scripps Institution of Oceanography.

MANIFEST.in

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
include cppEDM/src/*
2-
include src/bindings/*
1+
include src/pyEDM/data/*.csv
2+
include src/pyEDM/tests/*.py
3+
include src/pyEDM/tests/validation/*.csv

README.md

+3-24
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Empirical Dynamic Modeling (EDM)
22
---
3-
This package provides a Python/Pandas DataFrame interface to the [cppEDM](https://github.com/SugiharaLab/cppEDM "cppEDM") library for [EDM analysis](http://deepeco.ucsd.edu/nonlinear-dynamics-research/edm/ "EDM @ Sugihara Lab"). Introduction and documentation are are avilable [online](https://sugiharalab.github.io/EDM_Documentation/ "EDM Docs"), or in the package [API docs](https://github.com/SugiharaLab/pyEDM/blob/master/doc/pyEDM.pdf "pyEDM API"). A Jupyter notebook interface is available at [jpyEDM](https://github.com/SugiharaLab/jpyEDM#empirical-dynamic-modeling-edm-jupyter-notebook).
3+
This package provides a Python/Pandas DataFrame toolset for [EDM analysis](http://deepeco.ucsd.edu/nonlinear-dynamics-research/edm/ "EDM @ Sugihara Lab"). Introduction and documentation are are avilable [online](https://sugiharalab.github.io/EDM_Documentation/ "EDM Docs"), or in the package [API docs](https://github.com/SugiharaLab/pyEDM/blob/master/doc/pyEDM.pdf "pyEDM API"). A Jupyter notebook interface is available at [jpyEDM](https://github.com/SugiharaLab/jpyEDM#empirical-dynamic-modeling-edm-jupyter-notebook).
44

55
Functionality includes:
66
* Simplex projection ([Sugihara and May 1990](https://www.nature.com/articles/344734a0))
@@ -13,32 +13,11 @@ Functionality includes:
1313
## Installation
1414

1515
### Python Package Index (PyPI)
16-
Certain MacOS, Linux and Windows platforms are supported with prebuilt binary distributions hosted on PyPI [pyEDM](https://pypi.org/project/pyEDM/).
17-
18-
Command line using the Python pip module: `python -m pip install pyEDM`
19-
20-
### Manual Install
21-
If a pre-built binary distribution is not available the user can build the cppEDM library, then install the Python package using pip. On OSX and Linux this requires g++. On Windows, the mingw-w64 GCC is available as in [MSYS2](https://www.msys2.org/).
22-
23-
Note the [LAPACK](http://www.netlib.org/lapack/explore-html/index.html) library is required to build cppEDM and pyEDM. As of version 1.15.1, LAPACK is not required on Windows.
24-
25-
#### OSX and Linux
26-
1. Download pyEDM: `git clone https://github.com/SugiharaLab/pyEDM`
27-
2. Build cppEDM library: `cd pyEDM/cppEDM/src; make`
28-
3. Build and install package: `cd ../..; python -m pip install . --user`
29-
30-
#### Windows
31-
0. If a Windows binary is not available, these suggestions may be useful.
32-
1. mingw-w64 GCC is available in [MSYS2](https://www.msys2.org/).
33-
2. Prior to version 1.15.1, [gfortran](https://gcc.gnu.org/wiki/GFortranBinariesWindows) and [OpenBLAS](https://www.openblas.net/) libraries are required.
34-
3. Download pyEDM: `git clone https://github.com/SugiharaLab/pyEDM`
35-
4. Build cppEDM library: `cd pyEDM\cppEDM\src; make`
36-
5. Adjust paths to find gfortran and openblas libraries (pyEDM/pyEDM/etc/windows/libopenblas.a). You may need to rename libEDM.a to EDM.lib, and openblas.a to openblas.lib.
37-
6. Build and install package in `pyEDM\`: `python -m pip install . --user`
16+
Certain MacOS, Linux and Windows platforms are supported with prebuilt binary distributions hosted on PyPI [pyEDM](https://pypi.org/project/pyEDM/) and can be installed with the Python pip module: `python -m pip install pyEDM`
3817

3918
---
4019
## Usage
41-
Example usage at the python prompt:
20+
Examples can be executed in the python command line:
4221
```python
4322
>>> import pyEDM
4423
>>> pyEDM.Examples()
File renamed without changes.

pyEDM/etc/apps/EmbedDim_Multiprocess_Columns.py apps/CrossMap_Multiprocess_Columns.py

+44-57
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@
55
from itertools import repeat
66

77
from pandas import DataFrame, read_csv, concat
8-
from pyEDM import EmbedDimension, sampleData
8+
from pyEDM import Simplex, sampleData
99
from matplotlib import pyplot as plt
1010

1111
#----------------------------------------------------------------------------
1212
#
1313
#----------------------------------------------------------------------------
14-
def EmbedDim_Columns( data, target = None, maxE = 20,
14+
def CrossMap_Columns( data, target = None, E = 0,
1515
Tp = 1, tau = -1, exclusionRadius = 0,
16-
lib = None, pred = None, numThreads = 4, cores = 5,
16+
lib = None, pred = None, cores = 5,
1717
outputFile = None, noTime = False,
1818
verbose = False, plot = False ):
1919

20-
'''Use multiprocessing Pool to process parallelise EmbedDimension.
20+
'''Use multiprocessing Pool to process parallelise Simplex.
2121
The target (-t) argument specifies a column against which all
22-
other columns will be cross mapped.
22+
other columns are cross mapped.
2323
'''
2424

2525
startTime = time.time()
@@ -37,69 +37,62 @@ def EmbedDim_Columns( data, target = None, maxE = 20,
3737
if not noTime :
3838
columns = data.columns[ 1 : len(data.columns) ].to_list()
3939

40-
# Dictionary of arguments for Pool : EmbedDimFunc
41-
argsD = { 'lib' : lib, 'pred' : pred, 'maxE' : maxE,
40+
# Dictionary of arguments for Pool : SimplexFunc
41+
argsD = { 'lib' : lib, 'pred' : pred, 'E' : E,
4242
'exclusionRadius' : exclusionRadius, 'Tp' : Tp,
43-
'tau' : tau, 'target' : target,
44-
'numThreads' : numThreads, 'noTime' : noTime }
43+
'tau' : tau, 'target' : target, 'noTime' : noTime }
4544

4645
# Create iterable for Pool.starmap, use repeated copies of argsD, data
4746
poolArgs = zip( columns, repeat( argsD ), repeat( data ) )
4847

4948
# Use pool.starmap to distribute among cores
50-
pool = Pool( processes = cores )
51-
52-
# starmap: elements of the iterable argument are iterables
53-
# that are unpacked as arguments
54-
EDList = pool.starmap( EmbedDimFunc, poolArgs )
49+
with Pool( processes = cores ) as pool :
50+
CMList = pool.starmap( SimplexFunc, poolArgs )
5551

56-
# Load EDList results into dictionary : DataFrame
52+
# Load CMList results into dictionary
5753
D = {}
58-
D[ 'E' ] = EDList[0]['E'].astype( int )
5954
for i in range( len( columns ) ) :
60-
D[ f'{columns[i]}:{target}' ] = EDList[ i ]['rho']
61-
62-
df = DataFrame( D )
55+
D[ f'{columns[i]}:{target}' ] = CMList[ i ]
6356

6457
print( "Elapsed time:", round( time.time() - startTime, 2 ) )
6558

6659
if verbose :
67-
print( df )
60+
print( D.keys() )
6861

6962
if plot :
70-
df.plot( 'E', df.columns[1:], linewidth = 3,
71-
ylabel = 'Prediction ρ' )
63+
df = D[ list( D.keys() )[-1] ]
64+
df.plot( df.columns[0], df.columns[1:3], linewidth = 3,
65+
ylabel = list( D.keys() )[-1] )
7266
plt.show()
7367

7468
if outputFile :
7569
df.to_csv( outputFile )
7670

77-
return df
71+
return D
7872

7973
#----------------------------------------------------------------------------
8074
#----------------------------------------------------------------------------
81-
def EmbedDimFunc( column, argsD, data ):
75+
def SimplexFunc( column, argsD, data ):
8276
'''Call pyEDM EmbedDimension using the column, args, and data'''
8377

84-
ed = EmbedDimension( dataFrame = data,
85-
lib = argsD['lib'],
86-
pred = argsD['pred'],
87-
maxE = argsD['maxE'],
88-
exclusionRadius = argsD['exclusionRadius'],
89-
Tp = argsD['Tp'],
90-
tau = argsD['tau'],
91-
columns = column,
92-
target = argsD['target'],
93-
numThreads = argsD['numThreads'],
94-
noTime = argsD['noTime'],
95-
showPlot = False )
96-
97-
return ed
78+
df = Simplex( dataFrame = data,
79+
columns = column,
80+
target = argsD['target'],
81+
lib = argsD['lib'],
82+
pred = argsD['pred'],
83+
E = argsD['E'],
84+
exclusionRadius = argsD['exclusionRadius'],
85+
Tp = argsD['Tp'],
86+
tau = argsD['tau'],
87+
noTime = argsD['noTime'],
88+
showPlot = False )
89+
90+
return df
9891

9992
#----------------------------------------------------------------------------
10093
#----------------------------------------------------------------------------
101-
def EmbedDim_Columns_CmdLine():
102-
'''Wrapper for EmbedDim_Columns with command line parsing'''
94+
def CrossMap_Columns_CmdLine():
95+
'''Wrapper for CrossMap_Columns with command line parsing'''
10396

10497
args = ParseCmdLine()
10598

@@ -112,20 +105,20 @@ def EmbedDim_Columns_CmdLine():
112105
else:
113106
raise RuntimeError( "Invalid inputFile or inputData" )
114107

115-
# Call EmbedDim_Columns()
116-
df = EmbedDim_Columns( data = dataFrame, target = args.target,
117-
maxE = args.maxE, Tp = args.Tp, tau = args.tau,
108+
# Call CrossMap_Columns()
109+
df = CrossMap_Columns( data = dataFrame, target = args.target,
110+
E = args.E, Tp = args.Tp, tau = args.tau,
118111
exclusionRadius = args.exclusionRadius,
119112
lib = args.lib, pred = args.pred,
120-
numThreads = args.numThreads, cores = args.cores,
121-
outputFile = args.outputFile, noTime = args.noTime,
113+
cores = args.cores, noTime = args.noTime,
114+
outputFile = args.outputFile,
122115
verbose = args.verbose, plot = args.Plot )
123116

124117
#----------------------------------------------------------------------------
125118
#----------------------------------------------------------------------------
126119
def ParseCmdLine():
127120

128-
parser = argparse.ArgumentParser( description = 'EmbedDimension MultiProc' )
121+
parser = argparse.ArgumentParser( description = 'CrossMap Columns' )
129122

130123
parser.add_argument('-i', '--inputFile',
131124
dest = 'inputFile', type = str,
@@ -145,11 +138,11 @@ def ParseCmdLine():
145138
default = None,
146139
help = 'Output file.')
147140

148-
parser.add_argument('-E', '--maxE',
149-
dest = 'maxE', type = int,
141+
parser.add_argument('-E', '--E',
142+
dest = 'E', type = int,
150143
action = 'store',
151-
default = 20,
152-
help = 'Maximum embedding dimension.')
144+
default = 0,
145+
help = 'E.')
153146

154147
parser.add_argument('-x', '--exclusionRadius',
155148
dest = 'exclusionRadius', type = int,
@@ -187,12 +180,6 @@ def ParseCmdLine():
187180
default = [],
188181
help = 'prediction indices.')
189182

190-
parser.add_argument('-n', '--numThreads',
191-
dest = 'numThreads', type = int,
192-
action = 'store',
193-
default = 3,
194-
help = 'EmbedDimension numThreads.')
195-
196183
parser.add_argument('-C', '--cores',
197184
dest = 'cores', type = int,
198185
action = 'store',
@@ -224,4 +211,4 @@ def ParseCmdLine():
224211
#----------------------------------------------------------------------------
225212
# Provide for cmd line invocation and clean module loading
226213
if __name__ == "__main__":
227-
EmbedDim_Columns_CmdLine()
214+
CrossMap_Columns_CmdLine()

0 commit comments

Comments
 (0)