[Scipy-svn] r4643 - in branches/Interpolate1D: . docs
scipy-svn at scipy.org
scipy-svn at scipy.org
Tue Aug 12 15:15:14 EDT 2008
Author: fcady
Date: 2008-08-12 14:15:11 -0500 (Tue, 12 Aug 2008)
New Revision: 4643
Added:
branches/Interpolate1D/docs/README.txt
Modified:
branches/Interpolate1D/docs/tutorial.rst
branches/Interpolate1D/interpolate2d.py
branches/Interpolate1D/setup.py
Log:
added README.txt file that describes organization of the module so that future developers can understand the design and rational behind it easily.
Added: branches/Interpolate1D/docs/README.txt
===================================================================
--- branches/Interpolate1D/docs/README.txt 2008-08-12 17:15:10 UTC (rev 4642)
+++ branches/Interpolate1D/docs/README.txt 2008-08-12 19:15:11 UTC (rev 4643)
@@ -0,0 +1,71 @@
+README
+
+
+This file contains information about the architecture (not the api) of the module
+and license information. It is designed mostly for developers who need to
+understand the organization of the files, extensions, etc and the logic (or lack thereof)
+behind them so that they can continue development of the module.
+
+The key the understanding the module is to understand where it came from.
+Interpolation code in a variety of different forms for a variety of different purposes
+had been spread throughout the various parts of Enthought code. The goal was to
+collect these various pieces of code and combine them into one module with a
+reasonable, intuitive api. But under the hood, there are several extension
+modules whose functionalities overlap or do not naturally dovetail.
+
+Main Files:
+interpolate1d.py :
+ Contains the Interpolate1d class and the interp1d functional wrapper
+ around it. This mostly provides a user-interface; the user passes in
+ keywords, and according to those keywords, Interpolate1d will call functions
+ and classes in the wrapper files.
+interpolate2d.py :
+ Completely analogous to interpolate1d.py. A user interface that calls machinery
+ in the wrapper files. Its organization is also almost completely analogous to
+ that of interpolate1d.py.
+interpolateNd.py :
+ This file doubles as a user interface and wrapper file around the _nd_image
+ extension. Interpolate1d and 2d are both operated by inputting lists of
+ points, which is pretty generic and lends itself to removing bad data etc.
+ But the _nd_image extension requires a uniform grid, so this file only performs
+ interpolation with the _nd_image extension. _nd_image interpolates array entries,
+ so this file handles 1) formatting, and 2) translations between spatial coordinates and
+ array indices.
+
+ The spline filtering step is carried over from ndimage, and is necessary to make
+ the extension module work properly. In the future, it could be good to modify
+ the _nd_image module to include this annoying step itself and hide it from the
+ developer.
+
+Wrapper files:
+fitpack_wrapper.py :
+ This file provides the Spline and Spline2d classes which provide a variety of 1d and
+ 2d spline functions. It is these classes which are accessed by Interpolate1d and
+ Interpolate2d, but note that only part of their functionality is accessed. Things like
+ smoothing and seeing spline coefficients are supported by Spline and Spline2d but to
+ exported. Internally, these classes call the _dfitpack extension.
+
+ This is based on code that was in scipy.interpolate. Much of the functionality that was
+ in scipy.interpolate is not reproduced here.
+
+interpolate_wrapper.py :
+ A variety of 1d interpolation functions. Most of them are just wrappers around _interpolate,
+ but others are stand-alone.
+
+algorithm526_wrapper.py :
+ very simple interface to the _interp_526 module. The main reason for the new file is so
+ that the imported function is recognized by Interpolate2d as a function, rather than a
+ Fortran object so that _init_xyz works.
+
+Extensions:
+_dfitpack :
+ Fortran extension module. This wraps part of the functionality of the fitpack library.
+_interpolate :
+ C extension module with basic functions.
+_nd_image :
+ C extensions module. It uses spline interpolation of various orders to interpolate entries
+ in an array.
+_interp_526 :
+ Fortran extension module implementing TOMS Algorithm 526. Taken from the Pore Pressure
+ project.
+
Property changes on: branches/Interpolate1D/docs/README.txt
___________________________________________________________________
Name: svn:executable
+ *
Modified: branches/Interpolate1D/docs/tutorial.rst
===================================================================
--- branches/Interpolate1D/docs/tutorial.rst 2008-08-12 17:15:10 UTC (rev 4642)
+++ branches/Interpolate1D/docs/tutorial.rst 2008-08-12 19:15:11 UTC (rev 4643)
@@ -23,6 +23,8 @@
them at work in realistic sample sessions. These sessions demonstrate how to use the
interpolate module, but also highlight some of the uses of interpolation techniques.
+
+
======================
1D Interpolation
======================
@@ -85,7 +87,7 @@
Out []: array([ NaN, NaN, 0.63661977, 0.72676046])
If we want a type of interpolation other than linear, there is a range of options which we can specify
-with the keyword argument "kind", which is usually a string. Continuing from the previous example,::
+with the keyword argument "kind", which is usually a (non-case-sensitive) string. Continuing from the previous example,::
# If we want quadratic (2nd order) spline interpolation, we can use the string 'quadratic'
In []: new_y_quadratic = interp1d(x, y, new_x, kind = 'quadratic')
@@ -738,5 +740,5 @@
Still in development.
Ideally the range of interpolation would be the convex hull of the known
- data points, and a Delaunay triangulation would be determined and stored
- at instantiation. Then again, that would be VERY expensive.
\ No newline at end of file
+ data points, and a Delaunay tesselation would be determined and stored
+ at instantiation. Then again, that would be very expensive.
\ No newline at end of file
Modified: branches/Interpolate1D/interpolate2d.py
===================================================================
--- branches/Interpolate1D/interpolate2d.py 2008-08-12 17:15:10 UTC (rev 4642)
+++ branches/Interpolate1D/interpolate2d.py 2008-08-12 19:15:11 UTC (rev 4643)
@@ -9,6 +9,7 @@
return np.atleast_1d( np.ascontiguousarray(ary, dtype) )
# dictionary of interpolation functions/classes/objects
+# keys are possible values of keyword "kind"
method_register = \
{
'linear' : Spline2d(kx=1, ky=1),
@@ -16,24 +17,28 @@
'quadratic' : Spline2d(kx=2, ky=2),
'quad' : Spline2d(kx=2, ky=2),
'cubic' : Spline2d(kx=3, ky=3),
+ 'natural' : Spline2d(kx=3, ky=3),
'quartic' : Spline2d(kx=4, ky=4),
'quar' : Spline2d(kx=4, ky=4),
'quintic' : Spline2d(kx=5, ky=5),
'quin' : Spline2d(kx=5, ky=5),
'526' : algorithm526, 'algorithm526':algorithm526,
- 'natural' : Spline2d(kx=3, ky=3),
}
# dictionary of types for casting. key = possible datatype, value = datatype it is cast to
# BEWARE : if you cast things to integers, you will lose interpolation ability
-dtype_register = {np.float32 : np.float32,
- np.float64 : np.float64
- }
+dtype_register = {
+ np.float32 : np.float32,
+ np.float64 : np.float64
+ }
+# input will be cast to this type if it's not a key in dtype_register
dtype_default = np.float64
+# functional interface: creates and calls an instance of objective interface
def interp2d(x, y, z, newx, newy, kind='linear', out=NaN, bad_data=None):
return Interpolate2d(x, y, z, kind=kind, out=out, bad_data=bad_data)(newx, newy)
-
+
+# objective interface
class Interpolate2d:
""" A callable class for interpolation of 1D, real-valued data.
@@ -141,14 +146,6 @@
def _init_xyz(self, x, y, z, bad_data):
# FIXME : perhaps allow 2D input if it is inthe form of meshgrid
-
- if bad_data is not None:
- try: # check that bad_data contains only numerical values
- sum_of_bad_data = sum(bad_data)
- except:
- raise TypeError, "bad_data must be either None \
- or a list of numbers"
- x, y, z = self._remove_bad_data(x, y, z, bad_data)
# check acceptable sizes and dimensions
x = np.atleast_1d(x)
@@ -160,6 +157,15 @@
assert z.ndim == 1 , "z must be one-dimensional"
assert len(x) == len(y) , "x and y must be of the same length"
assert len(x) == len(z) , "x and z must be of the same length"
+
+ # remove bad data if applicable
+ if bad_data is not None:
+ try: # check that bad_data contains only numerical values
+ sum_of_bad_data = sum(bad_data)
+ except:
+ raise TypeError, "bad_data must be either None \
+ or a list of numbers. Sorry."
+ x, y, z = self._remove_bad_data(x, y, z, bad_data)
# select proper dataypes and make arrays
self._xdtype = dtype_register.setdefault(type(x[0]), dtype_default)
Modified: branches/Interpolate1D/setup.py
===================================================================
--- branches/Interpolate1D/setup.py 2008-08-12 17:15:10 UTC (rev 4642)
+++ branches/Interpolate1D/setup.py 2008-08-12 19:15:11 UTC (rev 4643)
@@ -41,7 +41,7 @@
)
# implements algorithm 526 for 2D interpolation
- config.add_extension('interp_526',
+ config.add_extension('_interp_526',
sources = ['extensions/interp_526a.pyf',
'extensions/interp_526.f']
)
More information about the Scipy-svn
mailing list