[Scipy-svn] r4559 - branches/Interpolate1D
scipy-svn at scipy.org
scipy-svn at scipy.org
Wed Jul 23 16:49:38 EDT 2008
Author: fcady
Date: 2008-07-23 15:49:37 -0500 (Wed, 23 Jul 2008)
New Revision: 4559
Modified:
branches/Interpolate1D/Interpolate1D.py
branches/Interpolate1D/TODO.txt
branches/Interpolate1D/interpolate1d.py
Log:
various minor edits
Modified: branches/Interpolate1D/Interpolate1D.py
===================================================================
--- branches/Interpolate1D/Interpolate1D.py 2008-07-23 13:47:31 UTC (rev 4558)
+++ branches/Interpolate1D/Interpolate1D.py 2008-07-23 20:49:37 UTC (rev 4559)
@@ -145,8 +145,9 @@
the range of x. If a string is passed, it will look for an object
or function with that name and call it when evaluating. If
a function or object is passed, it will be called when interpolating.
- If nothing else, assumes the argument is intended as a value
- to be returned for all arguments. Defaults to linear interpolation.
+ A constant signifies a function which returns that constant
+ (e.g. val and lambda x : val are equivalent). Defaults to linear
+ interpolation.
kindkw -- dictionary
If kind is a class, function or string, additional keyword arguments
@@ -195,10 +196,11 @@
def __init__(self, x, y, kind='linear', low=np.NaN, high=np.NaN, \
kindkw={}, lowkw={}, highkw={}, \
remove_bad_data = False, bad_data=[]):
-
+
+ # store properly-formatted versions of x and y
self._format_array(x, y, remove_bad_data = remove_bad_data, bad_data = bad_data)
-
+ # store interpolation functions for each range
self.kind = self._init_interp_method(self._x, self._y, kind, kindkw)
self.low = self._init_interp_method(self._x, self._y, low, lowkw)
self.high = self._init_interp_method(self._x, self._y, high, highkw)
@@ -230,7 +232,7 @@
x = x[mask]
y = y[mask]
- # collect dataypes and make arrays
+ # select proper dataypes and make arrays
self._xdtype = {np.float32 : np.float32}.setdefault(type(x[0]), np.float64) # unless data is float32, cast to float64
self._ydtype = {np.float32 : np.float32}.setdefault(type(y[0]), np.float64)
self._x = make_array_safe(x, self._xdtype).copy()
@@ -255,12 +257,15 @@
# FIXME : more string options available ('cubic', etc)
if interp_arg in ['linear', 'logarithmic', 'block', 'block_average_above']:
+ # string used to indicate interpolation method, Select appropriate function
func = {'linear':linear, 'logarithmic':logarithmic, 'block':block, \
'block_average_above':block_average_above}[interp_arg]
result = lambda new_x : func(self._x, self._y, new_x, **kw)
elif interp_arg in ['Spline', Spline, 'spline']:
+ # spline is a special case of above
result = Spline(self._x, self._y, **kw)
elif isfunction(interp_arg):
+ # assume user has passed a function
result = lambda new_x : interp_arg(new_x, **kw)
elif isclass(interp_arg):
result = interp_arg(x, y, **kw)
@@ -276,10 +281,13 @@
"""
x = make_array_safe(x)
+
+ # masks indicate which elements fall into which interpolation region
low_mask = x<self._x[0]
high_mask = x>self._x[-1]
interp_mask = (~low_mask) & (~high_mask)
+ # use correct function for x values in each region
if len(x[low_mask]) == 0: new_low=np.array([]) # FIXME : remove need for if/else.
# if/else is a hack, since vectorize is failing
# to work on lists/arrays of length 0
Modified: branches/Interpolate1D/TODO.txt
===================================================================
--- branches/Interpolate1D/TODO.txt 2008-07-23 13:47:31 UTC (rev 4558)
+++ branches/Interpolate1D/TODO.txt 2008-07-23 20:49:37 UTC (rev 4559)
@@ -52,12 +52,10 @@
not just R1 -> R1. This requires some thinking about axes.
-**write regression tests
+**improve regression tests
desired for fitpack_wrapper and _interpolate_wrapper
-as well as interpolate1d. Recommend using the
-shelve module
+as well as interpolate1d.
-
**pick best spline
Under-the-hood machinery currently comes from _interpolate.cpp
(used in enthought.interpolate) and FITPACK (Fortran, used in
@@ -73,7 +71,14 @@
the capabilities are and which should be added, large-scale
architecture of the module, etc.
+It might note which underlying C/Fortran modules can or should
+be modified or merged. It would be great if either 1) there were
+only 1 extension module, or 2) the modules showed natural
+differentiation of functionality (one for splines, one for simple
+operations, etc), rather than being a holdover of where they
+were stolen from.
+
**update for 2D and ND
This will probably take the form of two additional
classes both based on interpolate1d. Thus it probably
Modified: branches/Interpolate1D/interpolate1d.py
===================================================================
--- branches/Interpolate1D/interpolate1d.py 2008-07-23 13:47:31 UTC (rev 4558)
+++ branches/Interpolate1D/interpolate1d.py 2008-07-23 20:49:37 UTC (rev 4559)
@@ -145,8 +145,9 @@
the range of x. If a string is passed, it will look for an object
or function with that name and call it when evaluating. If
a function or object is passed, it will be called when interpolating.
- If nothing else, assumes the argument is intended as a value
- to be returned for all arguments. Defaults to linear interpolation.
+ A constant signifies a function which returns that constant
+ (e.g. val and lambda x : val are equivalent). Defaults to linear
+ interpolation.
kindkw -- dictionary
If kind is a class, function or string, additional keyword arguments
@@ -195,10 +196,11 @@
def __init__(self, x, y, kind='linear', low=np.NaN, high=np.NaN, \
kindkw={}, lowkw={}, highkw={}, \
remove_bad_data = False, bad_data=[]):
-
+
+ # store properly-formatted versions of x and y
self._format_array(x, y, remove_bad_data = remove_bad_data, bad_data = bad_data)
-
+ # store interpolation functions for each range
self.kind = self._init_interp_method(self._x, self._y, kind, kindkw)
self.low = self._init_interp_method(self._x, self._y, low, lowkw)
self.high = self._init_interp_method(self._x, self._y, high, highkw)
@@ -230,7 +232,7 @@
x = x[mask]
y = y[mask]
- # collect dataypes and make arrays
+ # select proper dataypes and make arrays
self._xdtype = {np.float32 : np.float32}.setdefault(type(x[0]), np.float64) # unless data is float32, cast to float64
self._ydtype = {np.float32 : np.float32}.setdefault(type(y[0]), np.float64)
self._x = make_array_safe(x, self._xdtype).copy()
@@ -255,12 +257,15 @@
# FIXME : more string options available ('cubic', etc)
if interp_arg in ['linear', 'logarithmic', 'block', 'block_average_above']:
+ # string used to indicate interpolation method, Select appropriate function
func = {'linear':linear, 'logarithmic':logarithmic, 'block':block, \
'block_average_above':block_average_above}[interp_arg]
result = lambda new_x : func(self._x, self._y, new_x, **kw)
elif interp_arg in ['Spline', Spline, 'spline']:
+ # spline is a special case of above
result = Spline(self._x, self._y, **kw)
elif isfunction(interp_arg):
+ # assume user has passed a function
result = lambda new_x : interp_arg(new_x, **kw)
elif isclass(interp_arg):
result = interp_arg(x, y, **kw)
@@ -276,10 +281,13 @@
"""
x = make_array_safe(x)
+
+ # masks indicate which elements fall into which interpolation region
low_mask = x<self._x[0]
high_mask = x>self._x[-1]
interp_mask = (~low_mask) & (~high_mask)
+ # use correct function for x values in each region
if len(x[low_mask]) == 0: new_low=np.array([]) # FIXME : remove need for if/else.
# if/else is a hack, since vectorize is failing
# to work on lists/arrays of length 0
More information about the Scipy-svn
mailing list