def test_obslist_set(): rng = np.random.RandomState(seed=11) meta = {'duh': 5} obslist = ObsList(meta=meta) for _ in range(3): obslist.append(Observation(image=rng.normal(size=(13, 15)))) assert obslist.meta == meta new_meta = {'blah': 6} obslist.meta = new_meta assert obslist.meta == new_meta obslist.meta = None assert len(obslist.meta) == 0 with pytest.raises(TypeError): obslist.meta = [10] with pytest.raises(TypeError): obslist.set_meta([10]) new_meta = {'bla': 6} new_meta.update(obslist.meta) obslist.update_meta_data({'bla': 6}) assert obslist.meta == new_meta with pytest.raises(TypeError): obslist.update_meta_data([10]) rng = np.random.RandomState(seed=12) new_obs = Observation(image=rng.normal(size=(13, 15))) rng = np.random.RandomState(seed=11) for obs in obslist: assert np.all(obs.image == rng.normal(size=(13, 15))) obslist[1] = new_obs assert np.all(obslist[1].image == new_obs.image)
def obslist_data(): dims = (12, 12) rng = np.random.RandomState(seed=10) jac = DiagonalJacobian(x=5.5, y=5.5, scale=0.25) obslist = ObsList() obslist.append( Observation( image=rng.normal(size=dims), jacobian=jac.copy(), weight=np.exp(rng.normal(size=dims)), meta={"blue": 10}, ) ) obslist.append( Observation( image=rng.normal(size=dims), jacobian=jac.copy(), weight=np.exp(rng.normal(size=dims)), meta={"blue": 8}, ) ) psf = Observation( image=rng.normal(size=dims), weight=np.exp(rng.normal(size=dims)), jacobian=jac.copy(), meta={"blue": 5}, ) obslist[1].psf = psf return obslist
def get_exp_list(self, psf2=None): if psf2 is None: psf2 = self.psfs obs_list = ObsList() psf_list = ObsList() w = [] for i in range(len(self.gals)): im = self.gals[i].array im_psf = self.psfs[i].array im_psf2 = psf2[i].array weight = 1 / self.skys[i].array jacob = self.gals[i].wcs.jacobian() dx = self.offsets[i].x dy = self.offsets[i].y gal_jacob = Jacobian(row=self.gals[i].true_center.y + dy, col=self.gals[i].true_center.x + dx, dvdrow=jacob.dvdy, dvdcol=jacob.dvdx, dudrow=jacob.dudy, dudcol=jacob.dudx) psf_jacob2 = gal_jacob mask = np.where(weight != 0) w.append(np.mean(weight[mask])) noise = old_div(np.ones_like(weight), w[-1]) psf_obs = Observation(im_psf, jacobian=gal_jacob, meta={ 'offset_pixels': None, 'file_id': None }) psf_obs2 = Observation(im_psf2, jacobian=psf_jacob2, meta={ 'offset_pixels': None, 'file_id': None }) obs = Observation(im, weight=weight, jacobian=gal_jacob, psf=psf_obs, meta={ 'offset_pixels': None, 'file_id': None }) obs.set_noise(noise) obs_list.append(obs) psf_list.append(psf_obs2) return obs_list, psf_list, np.array(w)
def test_observation_get_has(image_data): obs = Observation(image=image_data['image']) assert np.all(obs.image == image_data['image']) assert not obs.has_bmask() assert not obs.has_ormask() assert not obs.has_noise() assert not obs.has_psf() assert not obs.has_psf_gmix() assert not obs.has_gmix() obs = Observation(image=image_data['image'], weight=image_data['weight']) assert np.all(obs.weight == image_data['weight']) obs = Observation(image=image_data['image'], bmask=image_data['bmask']) assert np.all(obs.bmask == image_data['bmask']) assert obs.has_bmask() obs = Observation(image=image_data['image'], ormask=image_data['ormask']) assert np.all(obs.ormask == image_data['ormask']) assert obs.has_ormask() obs = Observation(image=image_data['image'], noise=image_data['noise']) assert np.all(obs.noise == image_data['noise']) assert obs.has_noise() obs = Observation(image=image_data['image'], psf=image_data['psf']) assert np.all(obs.psf.image == image_data['psf'].image) assert obs.has_psf() assert not obs.has_psf_gmix() obs = Observation(image=image_data['image'], gmix=image_data['gmix']) assert np.all( obs.gmix.get_full_pars() == image_data['gmix'].get_full_pars()) assert obs.has_gmix() obs = Observation(image=image_data['image'], psf=image_data['psf_gmix']) assert np.all(obs.psf.image == image_data['psf_gmix'].image) assert obs.has_psf() assert obs.has_psf_gmix() assert np.all( obs.psf.gmix.get_full_pars() == obs.get_psf_gmix().get_full_pars()) obs = Observation(image=image_data['image'], jacobian=image_data['jacobian']) assert (obs.jacobian.get_galsim_wcs() == image_data['jacobian'].get_galsim_wcs()) obs = Observation(image=image_data['image'], meta=image_data['meta']) assert obs.meta == image_data['meta']
def get_psf_obs(self, iobj, icutout): """Get an observation of the PSF for this object. Parameters ---------- iobj : int Index of the object. icutout : int Index of the cutout for this object. Returns ------- psf : ngmix.Observation The PSF `Observation`. """ psf_im = self.get_psf(iobj, icutout) # FIXME: fake the noise noise = psf_im.max() / 1000.0 weight = psf_im * 0 + 1.0 / noise**2 jacobian = self.get_ngmix_jacobian(iobj, icutout) row, col = self._get_psf_cen(iobj, icutout) jacobian.set_cen( row=row, col=col, ) return Observation( psf_im, weight=weight, jacobian=jacobian, )
def make_galaxy_observation(self): """ read the image and weight data """ image = self.meds.get_cutout(self.mindex, 0) calc_weight = self.get('calc_weight', False) if calc_weight: import esutil as eu border = 5 nrow, ncol = image.shape row, col = numpy.mgrid[0:nrow, 0:ncol] w = numpy.where((row < 5) | (row > (nrow - 5 - 1)) | (col < 5) | (col > (ncol - 5 - 1))) mn, skysig_meas = eu.stat.sigma_clip(image[w].ravel()) print(" skysig_meas: %g" % skysig_meas) weight = 0 * image + 1.0 / skysig_meas**2 else: if self['noisefree']: weight = image * 0 + 1.0 / self['skynoise']**2 else: weight = self.meds.get_cutout(self.mindex, 0, type='weight') jacob = self.get_jacobian() self.obs = Observation(image, weight=weight, jacobian=jacob, psf=self.psf_obs)
def _get_observation(self): """ Get the appropriate observation """ im, wt, jacob = self._get_image_data() #print("weight image:",wt) return Observation(im, weight=wt, jacobian=jacob)
def _fit_galaxy_em(self, obs): sigma_guess = (self.res['psf_gmix'].get_T() * 0.5) ngauss = 1 fitter = self._fit_em_ngauss(obs, sigma_guess, ngauss) if fitter is None: self.res['flags'] = EM_FIT_FAILURE print("em utter failure") else: gmix = fitter.get_gmix() #print(" em gmix:",gmix) Tobs = Observation(obs.image, jacobian=obs.get_jacobian(), gmix=gmix) Tfitter = ngmix.fitting.TemplateFluxFitter(Tobs) Tfitter.go() Tres = Tfitter.get_result() self.res['em_gmix'] = gmix self.res['em_flux_flags'] = Tres['flags'] self.res['em_flux'] = Tres['flux'] self.res['em_flux_err'] = Tres['flux_err'] self.res['em_flux_s2n'] = Tres['flux'] / Tres['flux_err'] print(" em flux: %g +/- %g" % (Tres['flux'], Tres['flux_err']))
def _fit_with_em(self, obs_in, sigma_guess, ngauss): """ Fit the image using EM """ im_with_sky, sky = ngmix.em.prep_image(obs_in.image) sky_obs = Observation(im_with_sky, jacobian=obs_in.jacobian) ntry, maxiter, tol = self._get_em_pars() for i in xrange(ntry): guess = self._get_em_guess(sigma_guess, ngauss) try: fitter = ngmix.em.GMixEM(sky_obs) fitter.go(guess, sky, maxiter=maxiter, tol=tol) gm = fitter.get_gmix() # this will raise an exception for crazy values g1, g2, T = gm.get_g1g2T() if T > 0.1 and numpy.isfinite(T): tres = fitter.get_result() print(" em numiter:", tres['numiter']) break except GMixMaxIterEM: fitter = None except GMixRangeError: fitter = None return fitter
def test_observation_s2n(image_data): obs = Observation(image=image_data['image'], weight=image_data['weight']) s2n = obs.get_s2n() s2n_true = (np.sum(image_data['image']) / np.sqrt(np.sum(1.0 / image_data['weight']))) assert np.allclose(s2n, s2n_true)
def test_observation_s2n(image_data): obs = Observation(image=image_data['image'], weight=image_data['weight']) s2n = obs.get_s2n() s2n_true = (np.sum(image_data['image']) / np.sqrt(np.sum(1.0 / image_data['weight']))) assert np.allclose(s2n, s2n_true) # if we are not storing pixels, when we can have an all zero weight map # in this case s2n is -9999 obs = Observation( image=image_data['image'], weight=np.zeros_like(obs.weight), store_pixels=False, ) assert np.allclose(obs.get_s2n(), -9999)
def test_multibandobslist_set(): rng = np.random.RandomState(seed=11) meta = {'duh': 5} mbobs = MultiBandObsList(meta=meta) for _ in range(5): obslist = ObsList() for _ in range(3): obslist.append(Observation(image=rng.normal(size=(13, 15)))) mbobs.append(obslist) assert mbobs.meta == meta new_meta = {'blah': 6} mbobs.meta = new_meta assert mbobs.meta == new_meta mbobs.meta = None assert len(mbobs.meta) == 0 with pytest.raises(TypeError): mbobs.meta = [10] with pytest.raises(TypeError): mbobs.set_meta([10]) new_meta = {'bla': 6} new_meta.update(mbobs.meta) mbobs.update_meta_data({'bla': 6}) assert mbobs.meta == new_meta with pytest.raises(TypeError): mbobs.update_meta_data([10]) rng = np.random.RandomState(seed=12) new_obs = Observation(image=rng.normal(size=(13, 15))) rng = np.random.RandomState(seed=11) for obslist in mbobs: for obs in obslist: assert np.all(obs.image == rng.normal(size=(13, 15))) mbobs[1][2] = new_obs assert np.all(mbobs[1][2].image == new_obs.image) rng = np.random.RandomState(seed=13) obslist = ObsList() for _ in range(4): obslist.append(Observation(image=rng.normal(size=(13, 15)))) mbobs[2] = obslist rng = np.random.RandomState(seed=13) for obs in mbobs[2]: assert np.all(obs.image == rng.normal(size=(13, 15)))
def test_observation_nopixels(image_data): obs = Observation( image=image_data['image'], weight=image_data['weight'], jacobian=image_data['jacobian'], store_pixels=False, ) pixels = obs.pixels assert pixels is None
def test_observation_pixels(image_data): obs = Observation(image=image_data['image'], weight=image_data['weight'], jacobian=image_data['jacobian']) pixels = obs.pixels my_pixels = make_pixels(image_data['image'], image_data['weight'], image_data['jacobian']) assert np.all(pixels == my_pixels)
def get_exp_list(gals_array, psfs_array, offsets, skys_array, gal_true, gal_jacobs, psf2=None): #def get_exp_list(gal, psf, sky_stamp, psf2=None): if psf2 is None: psf2 = psfs_array obs_list=ObsList() psf_list=ObsList() w = [] for i in range(len(gals_array)): im = gals_array[i] im_psf = psfs_array[i] im_psf2 = psf2[i] weight = 1/skys_array[i] jacob = gal_jacobs[i] dx = offsets[i].x dy = offsets[i].y gal_jacob = Jacobian( row=gal_true[i].y+dy, col=gal_true[i].x+dx, dvdrow=jacob.dvdy, dvdcol=jacob.dvdx, dudrow=jacob.dudy, dudcol=jacob.dudx) psf_jacob2 = gal_jacob print(gal_jacob) mask = np.where(weight!=0) w.append(np.mean(weight[mask])) noise = old_div(np.ones_like(weight),w[-1]) psf_obs = Observation(im_psf, jacobian=gal_jacob, meta={'offset_pixels':None,'file_id':None}) psf_obs2 = Observation(im_psf2, jacobian=psf_jacob2, meta={'offset_pixels':None,'file_id':None}) obs = Observation(im, weight=weight, jacobian=gal_jacob, psf=psf_obs, meta={'offset_pixels':None,'file_id':None}) obs.set_noise(noise) obs_list.append(obs) psf_list.append(psf_obs2) return obs_list,psf_list,np.array(w)
def test_observation_pixels_update_jacobian(image_data): obs = Observation(image=image_data['image'], weight=image_data['weight'], jacobian=image_data['jacobian']) new_jac = DiagonalJacobian(x=8, y=13, scale=1.2) my_pixels = make_pixels(image_data['image'], image_data['weight'], new_jac) assert np.all(obs.pixels != my_pixels) obs.jacobian = new_jac assert np.all(obs.pixels == my_pixels)
def test_obslist_smoke(): rng = np.random.RandomState(seed=11) meta = {'duh': 5} obslist = ObsList(meta=meta) for _ in range(3): obslist.append(Observation(image=rng.normal(size=(13, 15)))) assert obslist.meta == meta rng = np.random.RandomState(seed=11) for obs in obslist: assert np.all(obs.image == rng.normal(size=(13, 15)))
def test_obslist_s2n_zeroweight(): rng = np.random.RandomState(seed=11) obslist = ObsList() for _ in range(3): obs = Observation( image=rng.normal(size=(13, 15)), weight=np.zeros((13, 15)), store_pixels=False, ) obslist.append(obs) assert np.allclose(obslist.get_s2n(), -9999)
def image_data(): dims = (13, 15) rng = np.random.RandomState(seed=10) data = {} for key in ['image', 'weight', 'bmask', 'ormask', 'noise']: data[key] = rng.normal(size=dims) if key == 'weight': data[key] = np.exp(data[key]) elif key in ['bmask', 'ormask']: data[key] = np.clip(data[key] * 100, 0, np.inf).astype(np.int32) data['jacobian'] = DiagonalJacobian(x=7, y=6, scale=0.25) data['meta'] = {'pi': 3.14} data['psf'] = Observation(image=rng.normal(size=dims), meta={'ispsf': True}) data['psf_gmix'] = Observation(image=rng.normal(size=dims), meta={'ispsf': True}, gmix=GMix(pars=rng.uniform(size=6))) data['gmix'] = GMix(pars=rng.uniform(size=6)) return data
def test_observation_pixels_update_weight(image_data): rng = np.random.RandomState(seed=11) obs = Observation(image=image_data['image'], weight=image_data['weight'], jacobian=image_data['jacobian']) new_arr = np.exp(rng.normal(size=obs.image.shape)) my_pixels = make_pixels(image_data['image'], new_arr, image_data['jacobian']) assert np.all(obs.pixels != my_pixels) obs.weight = new_arr assert np.all(obs.pixels == my_pixels)
def test_obslist_s2n(): rng = np.random.RandomState(seed=11) obslist = ObsList() numer = 0 denom = 0 for _ in range(3): obs = Observation(image=rng.normal(size=(13, 15))) numer += np.sum(obs.image) denom += np.sum(1.0 / obs.weight) obslist.append(obs) s2n = obslist.get_s2n() assert s2n == numer / np.sqrt(denom)
def test_get_mbobs(): rng = np.random.RandomState(seed=11) obs = Observation(image=rng.normal(size=(11, 13))) mbobs = get_mb_obs(obs) rng = np.random.RandomState(seed=11) assert np.all(mbobs[0][0].image == rng.normal(size=(11, 13))) assert len(mbobs) == 1 assert len(mbobs[0]) == 1 rng = np.random.RandomState(seed=12) obslist = ObsList() for _ in range(3): obslist.append(Observation(image=rng.normal(size=(11, 13)))) mbobs = get_mb_obs(obslist) rng = np.random.RandomState(seed=12) for obs in mbobs[0]: assert np.all(obs.image == rng.normal(size=(11, 13))) assert len(mbobs) == 1 assert len(mbobs[0]) == 3 rng = np.random.RandomState(seed=13) mbobs = MultiBandObsList() for _ in range(5): obslist = ObsList() for _ in range(3): obslist.append(Observation(image=rng.normal(size=(13, 15)))) mbobs.append(obslist) new_mbobs = get_mb_obs(mbobs) rng = np.random.RandomState(seed=13) for obslist in new_mbobs: for obs in obslist: assert np.all(obs.image == rng.normal(size=(13, 15))) with pytest.raises(ValueError): get_mb_obs(None)
def test_multibandobslist_smoke(): rng = np.random.RandomState(seed=11) meta = {'duh': 5} mbobs = MultiBandObsList(meta=meta) for _ in range(5): obslist = ObsList() for _ in range(3): obslist.append(Observation(image=rng.normal(size=(13, 15)))) mbobs.append(obslist) assert mbobs.meta == meta rng = np.random.RandomState(seed=11) for obslist in mbobs: for obs in obslist: assert np.all(obs.image == rng.normal(size=(13, 15)))
def test_multibandobslist_s2n_zeroweight(): rng = np.random.RandomState(seed=11) mbobs = MultiBandObsList() for _ in range(5): obslist = ObsList() for _ in range(3): img = rng.normal(size=(13, 15)) obslist.append( Observation( image=img, weight=np.zeros((13, 15)), store_pixels=False, )) mbobs.append(obslist) assert np.allclose(mbobs.get_s2n(), -9999)
def test_multibandobslist_s2n(): rng = np.random.RandomState(seed=11) mbobs = MultiBandObsList() numer = 0 denom = 0 for _ in range(5): obslist = ObsList() for _ in range(3): img = rng.normal(size=(13, 15)) obslist.append(Observation(image=img)) numer += np.sum(img) denom += np.sum(1.0 / obslist[-1].weight) mbobs.append(obslist) s2n = mbobs.get_s2n() assert s2n == numer / np.sqrt(denom)
def _fit_psf(self): """ Fit a psf to a single gauss and more complex model """ from ngmix import GMixMaxIterEM if 'psf_gmix' in self.res: del self.res['psf_gmix'] del self.res['psf_obs'] self.fitting_galaxy = False jacobian = self._get_jacobian(cen=self.psf_cen_guess_pix) psf_obs = Observation(self.psf_image, jacobian=jacobian) if 'em' in self['psf_model']: fitter = self._fit_em_ngauss(psf_obs, self['psf_sigma_guess'], self['psf_ngauss']) else: fitter = self._fit_psf_max(psf_obs) if fitter is None: self.res['flags'] = PSF_FIT_FAILURE print("psf utter failure") else: pres = fitter.get_result() if pres['flags'] != 0: self.res['flags'] = PSF_FIT_FAILURE print("psf convergence failure") else: psf_gmix = fitter.get_gmix() #print("psf fit:") #print(psf_gmix) print(" psf fwhm:", 2.35 * sqrt(psf_gmix.get_T() / 2.)) self.res['psf_gmix'] = psf_gmix psf_obs.set_gmix(psf_gmix) self.res['psf_obs'] = psf_obs if self['make_plots']: self._compare_psf(fitter)
def test_observation_context(image_data): obs = Observation( image=image_data['image'].copy(), weight=image_data['weight'].copy(), bmask=image_data['bmask'].copy(), ormask=image_data['ormask'].copy(), noise=image_data['noise'].copy(), jacobian=image_data['jacobian'], ) _dotest_readonly_attrs(obs) # should be a no-op outside of a context obs.writeable() _dotest_readonly_attrs(obs) with obs.writeable(): _dotest_writeable_attrs(obs)
def test_observation_pixels_noignore_zero(image_data): weight = image_data['weight'].copy() weight[:, 5] = 0.0 obs = Observation( image=image_data['image'], weight=weight, jacobian=image_data['jacobian'], ignore_zero_weight=False, ) pixels = obs.pixels my_pixels = make_pixels( image_data['image'], weight, image_data['jacobian'], ignore_zero_weight=False, ) assert np.all(pixels == my_pixels)
def make_psf_observation(self): """ read the image and weight data """ ext = self.get_psf_ext() self['psf_id'] = ext self.data['psf_id'][self.dindex] = ext image0 = self.psf_obj[ext][:, :] noise = self['psf_pars']['addnoise'] image = image0 + numpy.random.normal(scale=noise, size=image0.shape) weight = image.copy() weight *= 0 weight += 1.0 / noise**2 jacob = self.get_jacobian(type='psf') row, col = jacob.get_cen() jacob.set_cen(row - 1, col - 1) self.psf_obs = Observation(image, weight=weight, jacobian=jacob)
def multiband_coadd(): local_Hmeds = './fiducial_H158_2285117.fits' local_Jmeds = './fiducial_J129_2285117.fits' local_Fmeds = './fiducial_F184_2285117.fits' truth = fio.FITS( '/hpc/group/cosmology/phy-lsst/my137/roman_H158/g1002/truth/fiducial_lensing_galaxia_g1002_truth_gal.fits' )[-1] m_H158 = meds.MEDS(local_Hmeds) m_J129 = meds.MEDS(local_Jmeds) m_F184 = meds.MEDS(local_Fmeds) indices_H = np.arange(len(m_H158['number'][:])) indices_J = np.arange(len(m_J129['number'][:])) indices_F = np.arange(len(m_F184['number'][:])) roman_H158_psfs = get_psf_SCA('H158') roman_J129_psfs = get_psf_SCA('J129') roman_F184_psfs = get_psf_SCA('F184') oversample = 1 metacal_keys = ['noshear', '1p', '1m', '2p', '2m'] res_noshear = np.zeros(len(m_H158['number'][:]), dtype=[('ind', int), ('ra', float), ('dec', float), ('flags', int), ('coadd_px', float), ('coadd_py', float), ('coadd_flux', float), ('coadd_snr', float), ('coadd_e1', float), ('coadd_e2', float), ('coadd_hlr', float), ('coadd_psf_e1', float), ('coadd_psf_e2', float), ('coadd_psf_T', float)]) res_1p = np.zeros(len(m_H158['number'][:]), dtype=[('ind', int), ('ra', float), ('dec', float), ('flags', int), ('coadd_px', float), ('coadd_py', float), ('coadd_flux', float), ('coadd_snr', float), ('coadd_e1', float), ('coadd_e2', float), ('coadd_hlr', float), ('coadd_psf_e1', float), ('coadd_psf_e2', float), ('coadd_psf_T', float)]) res_1m = np.zeros(len(m_H158['number'][:]), dtype=[('ind', int), ('ra', float), ('dec', float), ('flags', int), ('coadd_px', float), ('coadd_py', float), ('coadd_flux', float), ('coadd_snr', float), ('coadd_e1', float), ('coadd_e2', float), ('coadd_hlr', float), ('coadd_psf_e1', float), ('coadd_psf_e2', float), ('coadd_psf_T', float)]) res_2p = np.zeros(len(m_H158['number'][:]), dtype=[('ind', int), ('ra', float), ('dec', float), ('flags', int), ('coadd_px', float), ('coadd_py', float), ('coadd_flux', float), ('coadd_snr', float), ('coadd_e1', float), ('coadd_e2', float), ('coadd_hlr', float), ('coadd_psf_e1', float), ('coadd_psf_e2', float), ('coadd_psf_T', float)]) res_2m = np.zeros(len(m_H158['number'][:]), dtype=[('ind', int), ('ra', float), ('dec', float), ('flags', int), ('coadd_px', float), ('coadd_py', float), ('coadd_flux', float), ('coadd_snr', float), ('coadd_e1', float), ('coadd_e2', float), ('coadd_hlr', float), ('coadd_psf_e1', float), ('coadd_psf_e2', float), ('coadd_psf_T', float)]) res_tot = [res_noshear, res_1p, res_1m, res_2p, res_2m] for i, ii in enumerate( indices_H): # looping through all the objects in meds file. if i % 100 == 0: print('object number ', i) ind = m_H158['number'][ii] t = truth[ind] sca_Hlist = m_H158[ii][ 'sca'] # List of SCAs for the same object in multiple observations. sca_Jlist = m_J129[ii]['sca'] sca_Flist = m_F184[ii]['sca'] m2_H158_coadd = [ roman_H158_psfs[j - 1] for j in sca_Hlist[:m_H158['ncutout'][i]] ] m2_J129_coadd = [ roman_J129_psfs[j - 1] for j in sca_Jlist[:m_J129['ncutout'][i]] ] m2_F184_coadd = [ roman_F184_psfs[j - 1] for j in sca_Flist[:m_F184['ncutout'][i]] ] obs_Hlist, psf_Hlist, included_H, w_H = get_exp_list_coadd( m_H158, ii, m2=m2_H158_coadd) coadd_H = psc.Coadder(obs_Hlist, flat_wcs=True).coadd_obs coadd_H.psf.image[ coadd_H.psf.image < 0] = 0 # set negative pixels to zero. coadd_H.set_meta({'offset_pixels': None, 'file_id': None}) obs_Jlist, psf_Jlist, included_J, w_J = get_exp_list_coadd( m_J129, ii, m2=m2_J129_coadd) coadd_J = psc.Coadder(obs_Jlist, flat_wcs=True).coadd_obs coadd_J.psf.image[ coadd_J.psf.image < 0] = 0 # set negative pixels to zero. coadd_J.set_meta({'offset_pixels': None, 'file_id': None}) obs_Flist, psf_Flist, included_F, w_F = get_exp_list_coadd( m_F184, ii, m2=m2_F184_coadd) coadd_F = psc.Coadder(obs_Flist, flat_wcs=True).coadd_obs coadd_F.psf.image[ coadd_F.psf.image < 0] = 0 # set negative pixels to zero. coadd_F.set_meta({'offset_pixels': None, 'file_id': None}) coadd = [coadd_H, coadd_J, coadd_F] mb_obs_list = MultiBandObsList() #coadd = [coadd_H] for band in range(3): obs_list = ObsList() new_coadd_psf_block = block_reduce(coadd[band].psf.image, block_size=(4, 4), func=np.sum) new_coadd_psf_jacob = Jacobian( row=15.5, col=15.5, dvdrow=(coadd[band].psf.jacobian.dvdrow * oversample), dvdcol=(coadd[band].psf.jacobian.dvdcol * oversample), dudrow=(coadd[band].psf.jacobian.dudrow * oversample), dudcol=(coadd[band].psf.jacobian.dudcol * oversample)) coadd_psf_obs = Observation(new_coadd_psf_block, jacobian=new_coadd_psf_jacob, meta={ 'offset_pixels': None, 'file_id': None }) coadd[band].psf = coadd_psf_obs obs_list.append(coadd[band]) mb_obs_list.append(obs_list) iteration = 0 for key in metacal_keys: res_tot[iteration]['ind'][i] = ind res_tot[iteration]['ra'][i] = t['ra'] res_tot[iteration]['dec'][i] = t['dec'] iteration += 1 #print(i, t['size'], mb_obs_list[0][0].image.sum(), mb_obs_list[1][0].image.sum(), mb_obs_list[2][0].image.sum()) res_ = measure_shape_metacal_multiband( mb_obs_list, t['size'], method='bootstrap', fracdev=t['bflux'], use_e=[t['int_e1'], t['int_e2']]) iteration = 0 for key in metacal_keys: if res_ == 0: res_tot[iteration]['ind'][i] = 0 elif res_[key]['flags'] == 0: res_tot[iteration]['coadd_px'][i] = res_[key]['pars'][0] res_tot[iteration]['coadd_py'][i] = res_[key]['pars'][1] res_tot[iteration]['coadd_snr'][i] = res_[key]['s2n'] res_tot[iteration]['coadd_e1'][i] = res_[key]['pars'][2] res_tot[iteration]['coadd_e2'][i] = res_[key]['pars'][3] res_tot[iteration]['coadd_hlr'][i] = res_[key]['pars'][4] iteration += 1 mask = res_tot[0]['ind'] != 0 print(len(res_tot[0]), len(res_tot[0][mask])) #print(res_['noshear'].dtype.names) print('done')