Chandra X-Ray Observatory
	(CXC)
Skip to the navigation links
Last modified: June 2010

URL: http://cxc.harvard.edu/ciao/ahelp/simple_stats.html
Jump to: Description · Examples · See Also


AHELP for CIAO 4.9

simple_stats

Context: contrib

Synopsis

Calculate several basic statistic values for a data array

Syntax

simple_stats(array)

Description

The simple_stats() routine calculates several simple statistics for the input data (the array argument), such as the mean, median, and standard deviation. For more control over the calculation use the routines in the numpy module.

Loading the routine

The routine can be loaded into Sherpa by saying:

from ciao_contrib.utils import *

Arguments

Name Description
array The array of data used to calculate the statistic values.

The return value

The return value is an object with the following fields:

Field Value
npts The number of elements in the array.
min The minimum value in the array.
max The maximum value in the array.
total The sum of all the array elements.
mean The mean value of the array.
median The median value of the array.
stddev The standard deviation of the array, calculated using the biased estimator (so the mean level is calculated using the number of elements and not "number of elements - 1").

Example 1

chips> x = [0, 1, 2, 3, 2, 3, 4, 2, 1, 5]
chips> s = simple_stats(x)

The return value of s is an object which contains the calculated statistics of the array:

chips> print (s)
npts   = 10
min    = 0
max    = 5
total  = 23
mean   = 2.3
median = 2.0
stddev = 1.41774468788
chips> print ("The mean is {0} +- {1}".format(s.mean, s.stddev))
The mean is 2.3 +- 1.41774

Example 2

chips> img = read_image("emap.fits")
chips> ivals = get_imagevals(img)
chips> ix = numpy.isfinite(ivals)
chips> simg = simple_stats(ivals[ix])

Here we use the Crates read_image() and get_imagevals() to read in the contents of the image "emap.fits". Since it may contain "invalid" numbers, such as NaN and Infinity, we filter out these values before calculating the statistics (simg).

See Also

contrib
simple_hist
tools
detilt, dewiggle, symmetrize

Last modified: June 2010
Smithsonian Institute Smithsonian Institute

The Chandra X-Ray Center (CXC) is operated for NASA by the Smithsonian Astrophysical Observatory. 60 Garden Street, Cambridge, MA 02138 USA.   Email:   cxchelp@head.cfa.harvard.edu Smithsonian Institution, Copyright © 1998-2017. All rights reserved.