def test_fitting(): psf = gaussian_psf(2.5, size=9) model_orig = create_model() imfit = Imfit(model_orig, psf=psf, quiet=False) noise_level = 0.1 shape = (100, 100) image = imfit.getModelImage(shape) noise = image * noise_level image += (np.random.random(shape) * noise) mask = np.zeros_like(image, dtype='bool') imfit.fit(image, noise, mask) model_fitted = imfit.getModelDescription() orig_params = get_model_param_array(model_orig) fitted_params = get_model_param_array(model_fitted) assert_allclose(orig_params, fitted_params, rtol=noise_level)
logger.info('Creating original B-D models.') norm_model = get_model(args.trueModel, with_default=True) model_deriv = np.array(get_model(args.trueModelDeriv).getParams(), dtype=norm_model.dtype) original_models = linear_model(norm_model, model_deriv, l_ssp) logger.info('Original model at normalization window:\n%s\n' % str(norm_model)) imshape = (72,77) ifsshape = (len(l_ssp),) + imshape norm_y0 = norm_model.y0.value norm_x0 = norm_model.x0.value flagged = distance(imshape, norm_x0, norm_y0) > 32.0 noise = 0.05 flux_unit = 1e-16 logger.info('Creating original PSF (FWHM = %.2f ")' % args.truePsfFWHM) original_PSF = gaussian_psf(args.truePsfFWHM, size=15) logger.info('Creating model images.') bulge_image = np.ma.empty(ifsshape) disk_image = np.ma.empty(ifsshape) for i, model in enumerate(original_models): bulge_image[i], disk_image[i] = create_model_images(model, imshape, original_PSF) bulge_image[:,flagged] = np.ma.masked disk_image[:,flagged] = np.ma.masked model_image = bulge_image + disk_image #model_noise = model_image * noise logger.info('Creating IFS.') bulge_spectra = bulge_image * (flux_unit * bulge_flux[..., np.newaxis, np.newaxis]) disk_spectra = disk_image * (flux_unit * disk_flux[..., np.newaxis, np.newaxis]) full_spectra = bulge_spectra + disk_spectra
def setSynthPSF(self, FWHM=0.0, beta=None, size=15): if beta is not None: self.setPSF(moffat_psf(FWHM, beta, size=size)) else: self.setPSF(gaussian_psf(FWHM, size=size))