Skip to content

Commit

Permalink
Fixed a bug in gsparams type-checking.
Browse files Browse the repository at this point in the history
  • Loading branch information
sweverett committed Jan 2, 2019
1 parent 0273ae9 commit 4da8d5b
Showing 1 changed file with 23 additions and 41 deletions.
64 changes: 23 additions & 41 deletions balrog/ngmix_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def makeGalaxies(self, index=None, n_random=None, rng=None, gsparams=None):
galaxies = []

for index in indices:
gal = self.ngmix2gs(index,gsparams)
gal = self.ngmix2gs(index, gsparams)
galaxies.append(gal)

# Store the orig_index as gal.index
Expand All @@ -351,7 +351,7 @@ def makeGalaxies(self, index=None, n_random=None, rng=None, gsparams=None):

#------------------------------------------------------------------------------------------------

def ngmix2gs(self, index, gsparams):
def ngmix2gs(self, index, gsparams=None):
"""
This function handles the conversion of a ngmix galaxy to a GS object. The required conversion is
different for each ngmix catalog type.
Expand All @@ -374,54 +374,34 @@ def ngmix2gs(self, index, gsparams):
gsobjects = []

# Convert from dict to actual GsParams object
# TODO: Currently fails if gsparams isn't passed!
if gsparams: gsp = galsim.GSParams(**gsparams)
else: gsp = None
# galsim.GSParams(**gsparams)

# Only here for testing purposes
# print('\nOBJ ID: {}\n'.format(self.catalog['id'][index]))
# print('\nOBJ (RA,DEC): ({},{})\n'.format(self.catalog['ra'][index],self.catalog['dec'][index]))
if gsparams is not None:
gsp = galsim.GSParams(**gsparams)
else:
gsp = None

# Iterate over all desired bands
for band in self.bands:
# Grab current band flux
flux = self.catalog[cp+'_flux'][index][self._band_index[band]]

if ct == 'gauss':
# Mimicking implementation in Erin's ngmix/gmix.py function `make_galsim_object()`
# This avoids using the whole ngmix machinery for the simple Gaussian case, in which
# the conversion is more straightforward.
T_round = ngmix.moments.get_Tround(T, g1, g2)
sigma_round = np.sqrt(T_round/2.0)
gal = galsim.Gaussian(flux=flux, sigma=sigma_round, gsparams=gsp)
gal = gal.shear(g1=g1, g2=g2)

elif ct == 'cm' or ct == 'mof':
# The majority of the conversion will be handled by `ngmix/gmix.py`
# The majority of the conversion will be handled by `ngmix/gmix.py`

# Gaussian-Mixture parameters are in the format of:
# gm_pars = [centroid1, centroid2, g1, g2, T, flux]
# (this is identical to ngmix catalogs, except that flux is a vector
# of fluxes in all color bands)
gm_pars = [0.0, 0.0, g1, g2, T, flux]
# Gaussian-Mixture parameters are in the format of:
# gm_pars = [centroid1, centroid2, g1, g2, T, flux]
# (this is identical to ngmix catalogs, except that flux is a vector
# of fluxes in all color bands)
gm_pars = [0.0, 0.0, g1, g2, T, flux]

# Build the appropriate Gaussian mixture for a cm-model
fracdev = self.catalog[cp+'_fracdev'][index]
TdByTe = self.catalog[cp+'_TdByTe'][index]
gm = ngmix.gmix.GMixCM(fracdev, TdByTe, gm_pars)
# Build the appropriate Gaussian mixture for a cm-model
fracdev = self.catalog[cp+'_fracdev'][index]
TdByTe = self.catalog[cp+'_TdByTe'][index]
gm = ngmix.gmix.GMixCM(fracdev, TdByTe, gm_pars)

# pudb.set_trace()
gal = gm.make_galsim_object(gsparams=gsp) # Uses customized ngmix code
gal = gm.make_galsim_object(gsparams=gsp) # Uses customized ngmix code

if ct == 'mof':
# TODO: Add any extra processing for mof catalogs, if needed
pass

else:
# TODO: While this check has already been made, it is possible that a new valid catalog type
# is added but whose GSObject conversion isn't implemented. Should come up with a more robust check!
raise ValueError('The ngmix catalog type {} is not yet supported!'.format(ct))
if ct == 'mof':
# TODO: Add any extra processing for mof catalogs, if needed
pass

# Add galaxy in given band to list
gsobjects.append(gal)
Expand Down Expand Up @@ -517,6 +497,8 @@ def getBands(self):

#####------------------------------------------------------------------------------------------------

# TODO: Remove once properly tested on Fermi Machines

# 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.
Expand Down Expand Up @@ -544,7 +526,7 @@ def getBands(self):
# ' for gsparams; input has type of {}.'
# .format(type(gsparams)))

# data = self._get_gmix_data()
# data = self.get_data()

# row, col = self.get_cen()

Expand Down

0 comments on commit 4da8d5b

Please sign in to comment.