|
|
|
|
SynopsisCreate a one-dimensional histogram of a data array Syntaxsimple_hist(array, nbins=10, min=None, max=None, step=None) DescriptionThe simple_hist() routine calculates a one-dimensional histogram of the input data (the array argument). For more control over the calculation use the numpy.histogram() routine. Loading the routineThe routine can be loaded into Sherpa by saying: from ciao_contrib.utils import * Arguments
The return valueThe return value is an object with the following fields:
Histogram calculationThe histogram is calculated using evenly-spaced bins; for all but the last bin the range is half-open, so that if it has edges xlow_i and xhigh_i then a value falls in this bin if it has a value in the range xlow_i <= x < xhigh_i The last bin is considered closed, so a value falls in this bin if xlow_last <= x <= xhigh_last Bin edgesIf step is not given (i.e. it is None), then the bin width is calculated as (max - min) / nbins If step is given then it is used as the bin width and the upper edge will be adjusted to ensure there are an integer number of bins: so if the input values are min=0, max=1, and step=0.4 the histogram will be calculated for the bins 0 to 0.4, 0.4 to 0.8, and 0.8 to 1.2. Example 1chips> x = [0, 1, 2, 3, 2, 3, 4, 2, 1] chips> h = simple_hist(x) chips> add_histogram(h.xlow, h.xhigh, h.y) The return value of h is an object with the fields "xlow", "xhigh", and "y", which contain the lower and upper bin edges and the histogram values respectively. These fields are used to plot up the histogram using the ChIPS add_histogram() routine. chips> print h xlow = Float64[10] xhigh = Float64[10] y = Int32[10] chips> print h.y [1 0 2 0 0 3 0 2 0 1] Example 2chips> x = [0, 1, 2, 3, 2, 3, 4, 2, 1] chips> h = simple_hist(x, step=1) The step size (width) of each bin is set to 1, which results in: chips> print h xlow = Float64[4] xhigh = Float64[4] y = Int32[4] chips> print h.y [1 2 3 3] Example 3
chips> img = read_image("emap.fits")
chips> ivals = get_imagevals(img)
chips> ix = numpy.isfinite(ivals)
chips> h = simple_hist(ivals[ix], nbins=20)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 histogram (using 20 bins). See Also
|
![]() |
The Chandra X-Ray
Center (CXC) is operated for NASA by the Smithsonian Astrophysical Observatory. 60 Garden Street, Cambridge, MA 02138 USA. Email: cxcweb@head.cfa.harvard.edu Smithsonian Institution, Copyright © 1998-2004. All rights reserved. |