[frames] | no frames]

# Source Code for Module imagestats.histogram1d'

``` 1  #   Program:    histogram1d.py
2  #   Author:     Christopher Hanley
3  #   Purpose:    Construct a 1 dimentional histogram from an array object
4  #
5
6  from __future__ import division # confidence high
7
8  import numpy as N
9  import buildHistogram
10
11  __version__ = '1.0'
12
13 -class histogram1d:
14      """Populate a 1 dimensional histogram from array object"""
15
16 -    def __init__(self,
17          arrayInput,         # 2D array object
18          nbins,              # Number of bins in the histogram
19          binWidth,           # Width of 1 bin in desired units
20          zeroValue           # Zero value for the histogram range
21          ):
22
23          # Initialize Object Attributes
24          self.__arrayInput = arrayInput.astype(N.float32)
25          self.nbins = nbins
26          self.binWidth = binWidth
27          self.minValue = zeroValue
28
29          # Compute the maximum value the histogram will take on
30          self.maxValue = self.minValue + (self.binWidth * self.nbins)
31
32          # Compute the array of bin center values
33          #   This should be done lazily using the newer-style class definition
34          #   for this class.
35          self.centers = N.array([self.minValue, self.maxValue, self.binWidth])
36
37          # Allocate the memory for the histogram.
38          self.histogram = N.zeros([self.nbins],dtype=N.uint32)
39
40          # Populate the histogram
41          self.__populateHistogram()
42
43 -    def __populateHistogram(self):
44          """Call the C-code that actually populates the histogram"""
45          try :
46              buildHistogram.populate1DHist(self.__arrayInput, self.histogram,
47                  self.minValue, self.maxValue, self.binWidth)
48          except:
49              if ( (self.__arrayInput.max() - self.__arrayInput.min() ) < self.binWidth ):
50                  raise ValueError, "In histogram1d class, the binWidth is greater than the data \
51                  range of the array object."
52              else:
53                  raise SystemError, "An error processing the array object information occured \
54                  in the buildHistogram module of histogram1d."
55
56 -    def getCenters(self):
57          return N.arange(len(self.histogram)) * self.binWidth + self.minValue
58
<!--
expandto(location.href);
// -->

```

 Generated by Epydoc 3.0.1 on Thu Jan 13 11:20:05 2011 http://epydoc.sourceforge.net