Table Of Contents

Previous topic

Image Access Modules

Next topic

Cookbook for Building TEAL Interfaces

This Page

Data Analysis Routines

These modules provide basic data analysis or data fitting functionality.

linefit

Fit a line to a data set with optional weights.

Returns the parameters of the model, bo, b1: Y = b0 + b1* X

author:
 Nadia Dencheva
version:
 ‘1.0 (2007-02-20)’
pytools.linefit.linefit(x, y, weights=None)
Parameters :
 

y: 1D numpy array :

The data to be fitted

x: 1D numpy array :

The x values of the y array. x and y must have the same shape.

weights: 1D numpy array, must have the same shape as x and y :

weight values

Examples

>>> x=N.array([-5, -4 ,-3 ,-2 ,-1, 0, 1, 2, 3, 4, 5])
>>> y=N.array([1, 5, 4, 7, 10, 8, 9, 13, 14, 13, 18])
>>> around(linefit(x,y), decimals=5)
array([ 9.27273,  1.43636])
>>> x=N.array([1.3,1.3,2.0,2.0,2.7,3.3,3.3,3.7,3.7,4.,4.,4.,4.7,4.7,5.,5.3,5.3,5.3,5.7,6.,6.,6.3,6.7])
>>> y = N.array([2.3,1.8,2.8,1.5,2.2,3.8,1.8,3.7,1.7,2.8,2.8,2.2,3.2,1.9,1.8,3.5,2.8,2.1,3.4,3.2,3.,3.,5.9])
>>> around(linefit(x,y), decimals=5)
array([ 1.42564,  0.31579])

nmpfit

Python/Numeric version of this module was called mpfit. This version was modified to use numpy.

xyinterp

Module:
 xyinterp.py

Interpolates y based on the given xval.

x and y are a pair of independent/dependent variable arrays that must be the same length. The x array must also be sorted. xval is a user-specified value. This routine looks up xval in the x array and uses that information to properly interpolate the value in the y array.

author:
 Vicki Laidler
version:
 ‘0.1 (2006-07-06)’
pytools.xyinterp.xyinterp(x, y, xval)
Purpose :
 Interpolates y based on the given xval.

x and y are a pair of independent/dependent variable arrays that must be the same length. The x array must also be sorted. xval is a user-specified value. This routine looks up xval in the x array and uses that information to properly interpolate the value in the y array.

Parameters :
 

x: 1D numpy array :

independent variable array: MUST BE SORTED

y: 1D numpy array :

dependent variable array

xval: float :

the x value at which you want to know the value of y

Returns :
 

y: float :

the value of y corresponding to xval

Raises :
 

ValueError: :

If arrays are unequal length; or x array is unsorted; or if xval falls outside the bounds of x (extrapolation is unsupported

:version: 0.1 last modified 2006-07-06 :

See also

numpy

Notes

Use the searchsorted method on the X array to determine the bin in which xval falls; then use that information to compute the corresponding y value.

gfit

Return the gaussian fit of a 1D array.

Uses mpfit.py - a python implementation of the Levenberg-Marquardt least-squares minimization, based on MINPACK-1. See nmpfit.py for the history of this module (fortran -> idl -> python). nmpfit.py is a version of mpfit.py which uses numarray.

@author: Nadia Dencheva @version: ‘1.0 (2007-02-20)’

pytools.gfit.gfit1d(y, x=None, err=None, weights=None, par=None, parinfo=None, maxiter=200, quiet=0)

Return the gaussian fit as an object.

Parameters :
 

y: 1D Numarray array :

The data to be fitted

x: 1D Numarray array :

(optional) The x values of the y array. x and y must have the same shape.

err: 1D Numarray array :

(optional) 1D array with measurement errors, must be the same shape as y

weights: 1D Numarray array :

(optiional) 1D array with weights, must be the same shape as y

par: List :

(optional) Starting values for the parameters to be fitted

parinfo: Dictionary of lists :

(optional) provides additional information for the parameters. For a detailed description see nmpfit.py. Parinfo can be used to limit parameters or keep some of them fixed.

maxiter: number :

Maximum number of iterations to perform Default: 200

quiet: number :

if set to 1, nmpfit does not print to the screen Default: 0

Examples

>>> x=N.arange(10,20, 0.1)
>>> y= 10*N.e**(-(x-15)**2/4)
>>> print gfit1d(y,x=x, maxiter=20,quiet=1).params
[ 10.          15.           1.41421356]

Image Combination Modules

The numcombine module serves as a limited replacement for IRAF’s ‘imcombine’ task.

class pytools.numcombine.numCombine(numarrayObjectList, numarrayMaskList=None, combinationType='median', nlow=0, nhigh=0, nkeep=1, upper=None, lower=None)

A lite version of the imcombine IRAF task