diff --git a/balrog/ngmix_catalog.py b/balrog/ngmix_catalog.py index 350cd43..3f8827a 100644 --- a/balrog/ngmix_catalog.py +++ b/balrog/ngmix_catalog.py @@ -254,9 +254,10 @@ def makeMask(self): if self.cat_type == 'mof': mask[self.mof_flags != 0] = False - # Remove any object with `T/T_err` < t_frac + # Remove any object with `|T/T_err|` < t_frac + # (have to do absolute value as T can be negative) T_fraction = self.catalog[cp+'_T'] / self.catalog[cp+'_T_err'] - mask[T_fraction < self.t_frac ] = False + mask[abs(T_fraction) < self.t_frac ] = False # Remove objects with snr_min < S/N < snr_max mask[self.catalog[cp+'_s2n_r'] < self.snr_min] = False @@ -406,21 +407,12 @@ def ngmix2gs(self, index, gsparams): gm_pars = [0.0, 0.0, g1, g2, T, flux] # Build the appropriate Gaussian mixture for a cm-model - # NOTE: we use a slightly modified version of the GMixCM class. fracdev = self.catalog[cp+'_fracdev'][index] TdByTe = self.catalog[cp+'_TdByTe'][index] - # print('\nfracdev, TdByTe = {}, {}\n'.format(fracdev, TdByTe)) - gm = BalGMixCM(fracdev, TdByTe, gm_pars) + gm = ngmix.gmix.GMixCM(fracdev, TdByTe, gm_pars) # pudb.set_trace() - - # Convert to a GSObject - - gal = gm.make_galsim_object(gsp) # Uses customized ngmix code - # gal = gm.make_galsim_object() # Uses native ngmix - - # print('gal._gsparams = {}'.format(gal._gsparams)) - # print('_gsparams.__dict__ = {}'.format(gal._gsparams.__dict__)) + gal = gm.make_galsim_object(gsparams=gsp) # Uses customized ngmix code if ct == 'mof': # TODO: Add any extra processing for mof catalogs, if needed @@ -525,62 +517,64 @@ def getBands(self): #####------------------------------------------------------------------------------------------------ -class BalGMixCM(ngmix.gmix.GMixCM): - ''' - This is a slightly modified version of Erin Sheldon's GmixCM class from ngmix.gmix. Rather than - updating his repo for a few small changes, we overwrite the desired methods here. - ''' - - def make_galsim_object(self, gsparams=None): - ''' - Make a galsim representation for the gaussian mixture. - NOTE: The only difference from Erin's original code is the type checking and passing - of gsparams. This is especially useful for increasing fft sizes. - ''' - - # Accept optional gsparams for GSObject construction - if gsparams and ( type(gsparams) is not galsim._galsim.GSParams ): - if type(gsparams) is dict: - # Convert to actual gsparams object - gsparams = galsim.GSParams(**gsparams) - else: - raise TypeError('Only `dict` and `galsim.GSParam` types allowed for' - 'gsparams; input has {} type.'.format(type(gsparams))) +# NOTE: The following was used as a stand-in for esheldon's GMixCM ngmix code when it didn't have +# features that we want. It has now been updated (https://github.com/esheldon/ngmix/pull/51) and +# the following will be removed once the new ngmix version has been fully tested. - data = self._get_gmix_data() +# class BalGMixCM(ngmix.gmix.GMixCM): +# ''' +# This is a slightly modified version of Erin Sheldon's GmixCM class from ngmix.gmix. Rather than +# updating his repo for a few small changes, we overwrite the desired methods here. +# ''' - row, col = self.get_cen() +# def make_galsim_object(self, Tmin=1e-6, gsparams=None): +# ''' +# Make a galsim representation for the gaussian mixture. +# NOTE: The only difference from Erin's original code is the type checking and passing +# of gsparams. This is especially useful for increasing fft sizes. +# ''' - gsobjects = [] - for i in xrange(len(self)): - flux = data['p'][i] - T = data['irr'][i] + data['icc'][i] - # assert(T!=0.0) - if T==0: - # TODO: Explore this issue more! T is being stored as nonzero - - # what is causing this? - continue - e1 = (data['icc'][i] - data['irr'][i])/T - e2 = 2.0*data['irc'][i]/T +# # Accept optional gsparams for GSObject construction +# if (gsparams is not None) and (not isinstance(gsparams, galsim.GSParams)): +# if isinstance(gsparams, dict): +# # Convert to actual gsparams object +# gsparams = galsim.GSParams(**gsparams) +# else: +# raise TypeError('Only `dict` and `galsim.GSParam` types allowed' +# ' for gsparams; input has type of {}.' +# .format(type(gsparams))) + +# data = self._get_gmix_data() + +# row, col = self.get_cen() + +# gsobjects = [] +# for i in xrange(len(self)): +# flux = data['p'][i] +# T = data['irr'][i] + data['icc'][i] +# if T == 0: +# T = Tmin +# e1 = (data['icc'][i] - data['irr'][i])/T +# e2 = 2.0*data['irc'][i]/T - rowshift = data['row'][i]-row - colshift = data['col'][i]-col +# rowshift = data['row'][i]-row +# colshift = data['col'][i]-col - g1,g2 = ngmix.shape.e1e2_to_g1g2(e1,e2) +# g1,g2 = ngmix.shape.e1e2_to_g1g2(e1,e2) - Tround = ngmix.moments.get_Tround(T, g1, g2) - sigma_round = np.sqrt(Tround/2.0) +# Tround = ngmix.moments.get_Tround(T, g1, g2) +# sigma_round = np.sqrt(Tround/2.0) - gsobj = galsim.Gaussian(flux=flux, sigma=sigma_round,gsparams=gsparams) +# gsobj = galsim.Gaussian(flux=flux, sigma=sigma_round,gsparams=gsparams) - gsobj = gsobj.shear(g1=g1, g2=g2) - gsobj = gsobj.shift(colshift, rowshift) +# gsobj = gsobj.shear(g1=g1, g2=g2) +# gsobj = gsobj.shift(colshift, rowshift) - gsobjects.append( gsobj ) +# gsobjects.append( gsobj ) - gs_obj = galsim.Add(gsobjects) +# gs_obj = galsim.Add(gsobjects) - return gs_obj +# return gs_obj #####------------------------------------------------------------------------------------------------