Compute all the basic statistics from the array object.

def _computeStats(self):
        """ Compute all the basic statistics from the array object. """

        # Initialize the local max and min
        _clipmin = self.lower
        _clipmax = self.upper

        # Compute the clipped mean iterating the user specified numer of iterations
        for iter in range(self.nclip+1):

            try:
                _npix,_mean,_stddev,_min,_max = computeMean(self.image,_clipmin,_clipmax)
                #print("_npix,_mean,_stddev,_min,_max = ",_npix,_mean,_stddev,_min,_max)
            except:
                raise SystemError("An error processing the array object information occured in \
                                    the computeMean module of imagestats.")

            if _npix <= 0:
                # Compute Global minimum and maximum
                errormsg = self._error_no_valid_pixels(
                    iter, self.min, self.max,
                    _clipmin, _clipmax
                )
                print(errormsg)
                raise ValueError("Not enough data points to compute statistics.")

            if iter < self.nclip:
                # Re-compute limits for iterations
                _clipmin = max(self.lower, _mean - self.lsig * _stddev)
                _clipmax = min(self.upper, _mean + self.usig * _stddev)

        if self.fields.find('median') != -1:
            # Use the clip range to limit the data before computing
            #  the median value using numpy
            if self.nclip > 0:
                _image = self.image[(self.image <= _clipmax) & (self.image >= _clipmin)]
            else:
                _image = self.image
            self.median = np.median(_image)
            # clean-up intermediate product since it is no longer needed
            del _image

        if ( (self.fields.find('mode') != -1) or (self.fields.find('midpt') != -1) ):
            # Populate the historgram
            _hwidth = self.binwidth * _stddev
            _drange = _max - _min
            _minfloatval = 10.0 * np.finfo(dtype=np.float32).eps
            if _hwidth < _minfloatval or abs(_drange) < _minfloatval or \
               _hwidth > _drange:
                _nbins = 1
                _dz = _drange
                print("! WARNING: Clipped data falls within 1 histogram bin")
            else:
                _nbins = int( (_max - _min) / _hwidth ) + 1
                _dz = float(_max - _min) / float(_nbins - 1)

            _hist = histogram1d(self.image, _nbins, _dz, _min)
            self._hist = _hist
            _bins = _hist.histogram

            if (self.fields.find('mode') != -1):
                # Compute the mode, taking into account special cases
                if _nbins == 1:
                    _mode = _min + 0.5 *_hwidth
                elif _nbins == 2:
                    if _bins[0] > _bins[1]:
                        _mode = _min + 0.5 *_hwidth
                    elif _bins[0] < _bins[1]:
                        _mode = _min + 1.5 *_hwidth
                    else:
                        _mode = _min + _hwidth
                else:
                    _peakindex = np.where(_bins == np.maximum.reduce(_bins))[0].tolist()[0]

                    if _peakindex == 0:
                        _mode = _min + 0.5 * _hwidth
                    elif _peakindex == (_nbins - 1):
                        _mode = _min + (_nbins - 0.5) * _hwidth
                    else:
                        _dh1 = _bins[_peakindex] - _bins[_peakindex - 1]
                        _dh2 = _bins[_peakindex] - _bins[_peakindex + 1]
                        _denom = _dh1 + _dh2
                        if _denom == 0:
                            _mode = _min + (_peakindex + 0.5) * _hwidth
                        else:
                            _mode = _peakindex + 1 + (0.5 * (int(_dh1) - int(_dh2))/_denom)
                            _mode = _min + ((_mode - 0.5) * _hwidth)
                # Return the mode
                self.mode = _mode

            if (self.fields.find('midpt') != -1):
                # Compute a pseudo-Median Value using IRAF's algorithm
                _binSum = np.cumsum(_bins).astype(np.float32)
                _binSum = _binSum/_binSum[-1]
                _lo = np.where(_binSum >= 0.5)[0][0]
                _hi = _lo + 1

                _h1 = _min + _lo * _hwidth
                if (_lo == 0):
                    _hdiff = _binSum[_hi-1]
                else:
                    _hdiff = _binSum[_hi-1] - _binSum[_lo-1]

                if (_hdiff == 0):
                    _midpt = _h1
                elif (_lo == 0):
                    _midpt = _h1 + 0.5 / _hdiff * _hwidth
                else:
                    _midpt = _h1 + (0.5 - _binSum[_lo-1])/_hdiff * _hwidth
                self.midpt = _midpt

            # These values will only be returned if the histogram is computed.
            self.hmin = _min + 0.5 * _hwidth
            self.hwidth = _hwidth
            self.histogram  = _bins

        #Return values
        self.stddev = _stddev
        self.mean = _mean
        self.npix = _npix
        self.min = _min
        self.max = _max