# gaussian - /usr/bin/env python NAME gaussian FILE...

This preview shows pages 1–3. Sign up to view the full content.

#! /usr/bin/env python ''' NAME gaussian FILE gaussian.py DESCRIPTION Routines for evaluating, estimating parameters of, and fitting Gaussians. PACKAGE CONTENTS N-dimensional functions: gaussian(x, width=1., center=0., height=None, params=None) Evaluate the Gaussian function with given parameters at x (n-dimensional). fitgaussian(y, x) Calculates a Gaussian fit to (y, x) data, returns (width, center, height). 1-dimensional functions: gaussianguess(y, x=None) Crudely estimates the parameters of a Gaussian that fits the (y, x) data. EXAMPLE/TEST: See fitgaussian() example. MODIFICATION HISTORY: 2007-09-17 0.1 [email protected] Initial version 0.01, portions adapted from http://www.scipy.org/Cookbook/FittingData. 2007-10-02 0.2 jh Started making N-dimensional, put width before center in args. 2007-11-13 0.3 [email protected] Made N-dimensional. 2008-12-02 0.4 [email protected] Made fit gaussian return errors, and fixed a bug generating initial guesses ''' import numpy as np import scipy.optimize as so def gaussian(x, width=1., center=0., height=None, param=None): ''' Evaluates the Gaussian with given parameters at locations in x. Parameters ---------- x: ndarray (any shape) Abcissa values. Arranged as the output of np.indices() but may be float. The highest dimension must be equal to the number of other dimensions (i.e., if x has 6 dimensions, the highest dimension must have length 5, and each of those must give the coordinate along the respective axis). May also be 1-dimensional. Default: np.indices(y.shape). width: array_like

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
The width of the Gaussian function, sometimes called sigma. If scalar, assumed constant for all dimensions. If array, must be linear and the same length as the first dimension of x. In this case, each element gives the width of the function in the corresponding dimension. Default: [1.]. center: array_like The mean value of the Gaussian function, sometimes called x0. Same scalar/array behavior as width. Default: [0.]. height: scalar The height of the Gaussian at its center. If not set, initialized to the value that makes the Gaussian integrate to 1. If you want it to integrate to another number, leave height alone and multiply the result by that other number instead. Must be scalar. Default: [product(1./sqrt(2 * pi * width**2))]. param: ndarray or tuple, 3-element Instead of giving width, center, and height separately, give them in an array or tuple, concatenated in this order. So, if width=(2,3), center=(5,6), height=9, using param=[2,3,5,6,9] gives the same effect. If param is defined, width, center, and height are ignored and may be overwritten. This is useful in fitting functions. Returns
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 11/09/2009 for the course AST 4762 taught by Professor Harrington during the Fall '09 term at University of Central Florida.

### Page1 / 7

gaussian - /usr/bin/env python NAME gaussian FILE...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online