code: def fit_richness(self, atol=1.e-3, maxiter=50):
          
          # Check whether the signal probability for all objects are zero
          # This can occur for finite kernels on the edge of the survey footprint
          if np.isnan(self.u).any():
              logger.warning("NaN signal probability found")
              return 0., 0., None
          
          if not np.any(self.u):
              logger.warning("Signal probability is zero for all objects")
              return 0., 0., None
  
          if self.f == 0:
              logger.warning("Observable fraction is zero")
              return 0., 0., None
  
          # Richness corresponding to 0, 1, and 10 observable stars
          richness = np.array([0., 1./self.f, 10./self.f])
          loglike = np.array([self.value(richness=r) for r in richness])
  
          found_maximum = False
          iteration = 0
          while not found_maximum:
              parabola = ugali.utils.parabola.Parabola(richness, 2.*loglike)
              if parabola.vertex_x < 0.:
                  found_maximum = True
              else:
                  richness = np.append(richness, parabola.vertex_x)
                  loglike  = np.append(loglike, self.value(richness=richness[-1]))
  
                  if np.fabs(loglike[-1] - np.max(loglike[0: -1])) < atol:
                      found_maximum = True
              iteration+=1
              if iteration > maxiter:
                  logger.warning("Maximum number of iterations reached")
                  break
              
          index = np.argmax(loglike)
          return loglike[index], richness[index], parabola
docs: Maximize the log-likelihood as a function of richness.
  
          ADW 2018-06-04: Does it make sense to set the richness to the mle?
  
          Parameters:
          -----------
          atol : absolute tolerence for conversion
          maxiter : maximum number of iterations
  
          Returns:
          --------
          loglike, richness, parabola : the maximum loglike, the mle, and the parabola