

def ResolutionFitError(self, resolution, data, model):
    '\n        This function gets called by scipy.optimize.fminbound in FitResolution.\n        Not meant to be called directly by the user!\n        '
    resolution = max(1000.0, float(int((float(resolution) + 0.5))))
    if (self.debug and (self.debug_level >= 5)):
        logging.debug('Saving inputs for R = {}'.format(resolution))
        logging.debug(' to Debug_ResFit.log and Debug_ResFit2.log')
        np.savetxt('Debug_ResFit.log', np.transpose((data.x, data.y, data.cont)))
        np.savetxt('Debug_Resfit2.log', np.transpose((model.x, model.y)))
    newmodel = FittingUtilities.ReduceResolution(model, resolution, extend=False)
    newmodel = FittingUtilities.RebinData(newmodel, data.x, synphot=False)
    good = np.arange(data.x.size, dtype=np.int32)
    if ((len(self.ignore) > 0) and all([(len(region) > 0) for region in self.ignore])):
        for region in self.ignore:
            x0 = min(region)
            x1 = max(region)
            tmp1 = [(data.x[i] in data.x[good]) for i in range(data.x.size)]
            tmp2 = np.logical_or((data.x < x0), (data.x > x1))
            good = np.where(np.logical_and(tmp1, tmp2))[0]
    weights = (1.0 / (data.err ** 2))
    returnvec = ((((data.y - (data.cont * newmodel.y))[good] ** 2) * weights[good]) + FittingUtilities.bound(self.resolution_bounds, resolution))
    logging.debug('Resolution-fitting X^2 = {} at R = {}'.format((np.sum(returnvec) / float(good.size)), resolution))
    if np.isnan(np.sum((returnvec ** 2))):
        print('Error! NaN found in ResolutionFitError!')
        outfile = open('ResolutionFitError.log', 'a')
        outfile.write(('#Error attempting R = %g\n' % resolution))
        np.savetxt(outfile, np.transpose((data.x, data.y, data.cont, newmodel.x, newmodel.y)), fmt='%.10g')
        outfile.write('\n\n\n\n')
        np.savetxt(outfile, np.transpose((model.x, model.y)), fmt='%.10g')
        outfile.write('\n\n\n\n')
        outfile.close()
        raise ValueError
    return returnvec

dataset/ETHPy150Open kgullikson88/Telluric-Fitter/src/TelluricFitter.py TelluricFitter.ResolutionFitError/original