Skip to content

Commit

Permalink
Public release (under GPL version 2) of formerly UBC-licensesed code
Browse files Browse the repository at this point in the history
  • Loading branch information
henryk-modzelewski committed Sep 18, 2017
0 parents commit f9880d1
Show file tree
Hide file tree
Showing 19 changed files with 1,899 additions and 0 deletions.
361 changes: 361 additions & 0 deletions LICENSE.md

Large diffs are not rendered by default.

64 changes: 64 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
PyCurvelab - Python Wrappers for CurveLab

This software was written by Darren Thomson and Gilles Hennenfent.
Copyright owned by The University of British Columbia, 2006. This
software is distributed and certain rights granted under a License
Agreement with The University of British Columbia. Please contact the
authors or the UBC University Industry Liaison Office at 604-822-8580
for further information.
____________________________________________

Pre-requisites:

1. Python
-> version 2.3 or above
-> http://www.python.org

2. SWIG
-> version 1.3 or above
-> http://www.swig.org

3. Numpy
-> module must be available in your PYTHONPATH environment variable in order to be found by
-> version 1.0 or above
-> http://numpy.scipy.org/

4. CurveLab
-> version 2.0.2 or above
-> http://www.curvelet.org

____________________________________________

Installation:

1. Unpack the PyCurvelab tarball

2. Set these required environment variables:
-> FDCT: folder where your CurveLab installation is
-> FFTW: folder where your fftw installation is

3. In the PyCurvelab folder, run the following command:
-> python setup.py build install
-> the package will be installed as pyct module

4. In python, simply "import pyct" and you're off

5. To see how to use, type "help(pyct.fdct2)" or "help(pyct.fdct3)"

********
setup.py uses python's distutils, which offers many options for a customized installation.
run "python setup.py install --help" for more information
********

____________________________________________

Troubleshooting:

1. Subscribe to http://slim.eos.ubc.ca/mailman/listinfo/pycurvelab and post the message there.

____________________________________________

SLIM Software Administrator ([email protected])
Seismic Laboratory for Imaging and Modeling
Dept. of Earth and Ocean Sciences
The University of British Columbia
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build_ext]
swig_opts=-c++
54 changes: 54 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env python

# This software was written by Darren Thomson and Gilles Hennenfent.
# Copyright owned by The University of British Columbia, 2006. This
# software is distributed and certain rights granted under a License
# Agreement with The University of British Columbia. Please contact
# the authors or the UBC University Industry Liaison Office at
# 604-822-8580 for further information.

import sys
import os
import string

FFTW = os.environ['FFTW']
FDCT = os.environ['FDCT']

for arg in sys.argv:
a = string.split(arg,'=')
if len(a)==2:
if a[0] in ['FFTW','FDCT']:
exec '%s = "%s"' %tuple(a)

fftw_inc = os.path.join(FFTW,'include')
fftw_lib = os.path.join(FFTW,'lib')
fdct2 = os.path.join(FDCT,'fdct_wrapping_cpp','src')
fdct3 = os.path.join(FDCT,'fdct3d','src')
pycl_inc = 'src'

try:
import numpy
npy_inc = os.path.join(os.path.split(numpy.__file__)[0],'core','include','numpy')
except:
print "ERROR: numpy installation is necessary to install CurveLab"


from distutils.core import setup,Extension


setup(name='pyct',
version='1.0',
description='Python Wrappers for CurveLab-2.0',
author='Darren Thomson and Gilles Hennenfent',
author_email='dthomson,[email protected]',
url='http://slim.eos.ubc.ca',
ext_package='pyct',
ext_modules=[Extension('_fdct2_wrapper',[os.path.join('src','fdct2_wrapper.cpp'),os.path.join('src','fdct2_wrapper.i')],
include_dirs=[fdct2,fftw_inc,npy_inc,pycl_inc],
library_dirs=[fdct2,fftw_lib],libraries=['fdct_wrapping','fftw']),
Extension('_fdct3_wrapper',[os.path.join('src','fdct3_wrapper.cpp'),os.path.join('src','fdct3_wrapper.i')],
include_dirs=[fdct3,fftw_inc,npy_inc,pycl_inc],
library_dirs=[fdct3,fftw_lib],libraries=['fdct3d','fftw'])],
package_dir = {'pyct':'src'},
packages=['pyct']
)
140 changes: 140 additions & 0 deletions src/CLarray.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
"""
Definition of CLarray and CLsarray
Both are subclasses of numpy.ndarray
Used to store curvelet coefficients
generated by CurveLab
"""

# This software was written by Darren Thomson and Gilles Hennenfent.
# Copyright owned by The University of British Columbia, 2006. This
# software is distributed and certain rights granted under a License
# Agreement with The University of British Columbia. Please contact
# the authors or the UBC University Industry Liaison Office at
# 604-822-8580 for further information.

import numpy as __n
_CLsarray__n = __n
_CLarray__n = __n


class CLsarray(__n.ndarray):
"""
Curvelet Scale array
Returned when one scale is taken from a CLarray
given a CLsarray cs:
cs(an) returns the data at this CLsarray's scale
and the angle an
cs(an,x) return the value at this CLsarray's scale,
angle an, and the row x
cs(an,x,y) return the value at this CLsarray's scale,
angle an, and location (x,y)
User should normally never need to create these objects
"""
def __new__(subtype,data,fdct_op=None,fdct_scale=None,dtype=None,copy=False):
"""
data - any sequence to be wrapped into the CLarray
fdct_op - fdct operator object that created this CLsarray (or could have)
fdct_scale - curvelet scale for this object
dtype - used to force data type to switch
copy - used to force data copying on CLarray creation
"""
if not hasattr(subtype,'fdct_op'):
subtype.fdct_op = fdct_op
if not hasattr(subtype,'fdct_scale'):
subtype.fdct_op = fdct_scale

if isinstance(data,__n.ndarray):
if not copy and (dtype==data.dtype or dtype is None):
return data.view(subtype)
else:
return data.astype(dtype).view(subtype)

return __n.array(data).view(subtype)

def __call__(self,*args):
i0 = self.fdct_op.getindex((self.fdct_scale,0,0,0))
if len(args)==0:
return self
elif len(args)==1:
ind = self.fdct_op.index(self.fdct_scale,args[0])
return __n.array(self[ind[0]-i0:ind[1]-i0]).reshape(self.fdct_op.sizes[self.fdct_scale][args[0]])
elif len(args)==2:
ind = self.fdct_op.index(self.fdct_scale,args[0],args[1])
return __n.array(self[ind[0]-i0:ind[1]-i0])
elif len(args)==3:
return self[self.fdct_op.index(self.fdct_scale,args[0],args[1],args[2])-i0]

def __array_finalize__(self,obj):
if hasattr(obj,"fdct_op"):
self.fdct_op = obj.fdct_op
if hasattr(obj,"fdct_scale"):
self.fdct_scale = obj.fdct_op


class CLarray(__n.ndarray):
"""
Curvelet Array
returned from a forward curvelet transform
given a CLarray c:
c(sc) returns the data at scale sc
c(sc,an) returns the data at scale sc
and the angle an
c(sc,an,x) return the value at scale sc,
angle an, and the row x
c(sc,an,x,y) return the value at scale sc,
angle an, and location (x,y)
User should normally never need to create these objects
"""
def __new__(subtype,data,fdct_op=None,dtype=None,copy=False):
"""
data - any sequence to be wrapped into the CLarray
fdct_op - fdct operator object that created this CLarray (or could have)
dtype - used to force data type to switch
copy - used to force data copying on CLarray creation
"""
if not hasattr(subtype,'fdct_op'):
subtype.fdct_op = fdct_op

if isinstance(data,__n.ndarray):
if not copy and (dtype==data.dtype or dtype is None):
return data.view(subtype)
else:
return data.astype(dtype).view(subtype)

return __n.array(data).view(subtype)

def __call__(self,*args):
if len(args)==0:
return self
elif len(args)==1:
ind = self.fdct_op.index(args[0])
x = CLsarray(self[ind[0]:ind[1]],fdct_op=self.fdct_op,fdct_scale=args[0])
x.fdct_scale = args[0]
return x
elif len(args)==2:
ind = self.fdct_op.index(args[0],args[1])
return __n.array(self[ind[0]:ind[1]]).reshape(self.fdct_op.sizes[args[0]][args[1]])
elif len(args)==3:
ind = self.fdct_op.index(args[0],args[1],args[2])
return __n.array(self[ind[0]:ind[1]])
elif len(args)==4:
return self[self.fdct_op.index(args[0],args[1],args[2],args[3])]

def __array_finalize__(self,obj):
if hasattr(obj,"fdct_op"):
self.fdct_op = obj.fdct_op
35 changes: 35 additions & 0 deletions src/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""
Fast Discrete Curvelet Transform
Uses libraries from CurveLab 2.0
developed by:
Emmanuel Candes, Laurent Demanet, and Lexing Ying
California Institute of Technology
this wrapper developed by:
Darren Thomson and Gilles Hennenfent
Seismic Laboratory for Imaging and Modeling
University of British Columbia
"""

# This software was written by Darren Thomson and Gilles Hennenfent.
# Copyright owned by The University of British Columbia, 2006. This
# software is distributed and certain rights granted under a License
# Agreement with The University of British Columbia. Please contact
# the authors or the UBC University Industry Liaison Office at
# 604-822-8580 for further information.

try:
from fdct2 import *
except:
pass

try:
from fdct3 import *
except:
pass

from test import test,normtest


Loading

0 comments on commit f9880d1

Please sign in to comment.