def _test(self): # pull proper data and coefs coefs = self.coefs[modeltype] data = self.data[modeltype] # add noise if snr: if fittype == "ls": amp = coefs[0] noise_data = (amp / snr) * RNG.normal(size=data.shape) noisy_data = data + noise_data # this is a heuristic and should be replaced with a better # reasone parameter rtol = 1 / snr elif fittype == "mle": noisy_data = RNG.poisson(data) rtol = 1 / coefs[0] else: noisy_data = data rtol = 1e-7 # build object to test test_g = Gauss2D(noisy_data) # speficify guesses if not guess: guess_coefs = None else: guess_coefs = coefs.copy() # grab optimized coefs test_coefs = test_g.optimize_params(guess_params=guess_coefs, modeltype=modeltype, fittype=fittype) # do the actual test assert_allclose(test_coefs, coefs, rtol=rtol)
def _test(self): area = self.gauss.area() model = self.gauss.fit_model numeric_area = model.sum() assert_allclose(area, numeric_area, err_msg="Failed with GT params") assert_allclose( Gauss2D(model).area(guess_params=self.gauss._popt), numeric_area, err_msg="Failed when optimizing params", )
def setUp(self): # make x, y ranges self.x = np.arange(64) self.y = np.arange(128) # make meshgrid self.xx, self.yy = np.meshgrid(self.x, self.y) self.noisy_data = tif.imread( os.path.join(os.path.dirname(__file__), "..", "fixtures", "noisy_data.tif")) self.raw_data = tif.imread( os.path.join(os.path.dirname(__file__), "..", "fixtures", "raw_data.tif")) self.myg = Gauss2D(self.noisy_data)
def setUp(self): """Basic set up""" data = np.zeros((2001, 2001)) self.gauss = Gauss2D(data)