code: def chisq(psr,formbats=False):
      
      
      if formbats:
          psr.formbats()
  
      res, err = psr.residuals(removemean=False)[psr.deleted == 0], psr.toaerrs[psr.deleted == 0]
      
      res -= numpy.sum(res/err**2) / numpy.sum(1/err**2)
  
      return numpy.sum(res * res / (1e-12 * err * err))
docs: Return the total chisq for the current timing solution,
      removing noise-averaged mean residual, and ignoring deleted points.