Skip to content

Commit

Permalink
Make object_is_valid check optional
Browse files Browse the repository at this point in the history
  • Loading branch information
rmjarvis committed Nov 5, 2021
1 parent 135063e commit cb0493d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
34 changes: 18 additions & 16 deletions imsim/instcat.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class InstCatalog(object):
_rubin_area = 0.25 * np.pi * 649**2 # cm^2

def __init__(self, file_name, wcs, sed_dir=None, edge_pix=100, sort_mag=True, flip_g2=True,
min_source=None, logger=None):
min_source=None, skip_invalid=True, logger=None):
logger = galsim.config.LoggerWrapper(logger)
self.file_name = file_name
self.flip_g2 = flip_g2
Expand Down Expand Up @@ -169,21 +169,22 @@ def __init__(self, file_name, wcs, sed_dir=None, edge_pix=100, sort_mag=True, fl
objinfo = tokens[12:dust_index]
dust = tokens[dust_index:]

# Check for some reasons to skip this object.
# XXX: Is this right? We require dust?
# The previous code had that galactic_av = galactic_rv = 0 is invalid.
# That doesn't seem right to me...
object_is_valid = (magnorm < 50.0 and
dust[-1] != 'none' and
(float(dust[-1]) != 0 or float(dust[-2]) != 0) and
not (objinfo[0] == 'sersic2d' and
float(objinfo[1]) < float(objinfo[2])) and
not (objinfo[0] == 'knots' and
(float(objinfo[1]) < float(objinfo[2]) or
int(objinfo[4]) <= 0)))
if not object_is_valid:
logger.debug("Skipping object %s since not valid.", tokens[1])
continue
if skip_invalid:
# Check for some reasons to skip this object.
# XXX: Is this right? We require dust?
# The previous code had that galactic_av = galactic_rv = 0 is invalid.
# That doesn't seem right to me...
object_is_valid = (magnorm < 50.0 and
dust[-1] != 'none' and
(float(dust[-1]) != 0 or float(dust[-2]) != 0) and
not (objinfo[0] == 'sersic2d' and
float(objinfo[1]) < float(objinfo[2])) and
not (objinfo[0] == 'knots' and
(float(objinfo[1]) < float(objinfo[2]) or
int(objinfo[4]) <= 0)))
if not object_is_valid:
logger.debug("Skipping object %s since not valid.", tokens[1])
continue

# Object is ok. Add it to lists.
nuse += 1
Expand Down Expand Up @@ -770,6 +771,7 @@ def getKwargs(self, config, base, logger):
'sort_mag' : bool,
'flip_g2' : bool,
'min_source' : int,
'skip_invalid' : bool,
}
kwargs, safe = galsim.config.GetAllParams(config, base, req=req, opt=opt)
wcs = galsim.config.BuildWCS(base['image'], 'wcs', base, logger=logger)
Expand Down
16 changes: 10 additions & 6 deletions tests/test_trimmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,29 @@ def test_InstCatTrimmer(self):

# Note: some objects in instcat are up to ~600 pixels off the image.
# So need to use a largish edge_pix to keep them all.
instcat = imsim.InstCatalog(instcat_file, wcs, edge_pix=1000)
instcat = imsim.InstCatalog(instcat_file, wcs, edge_pix=1000, skip_invalid=False)
self.assertEqual(instcat.nobjects, 24)

# With the default edge_pix=100, only 17 make the cut.
instcat = imsim.InstCatalog(instcat_file, wcs)
instcat = imsim.InstCatalog(instcat_file, wcs, skip_invalid=False)
self.assertEqual(instcat.nobjects, 17)

# Check the application of min_source.
instcat = imsim.InstCatalog(instcat_file, wcs, edge_pix=1000, min_source=10)
instcat = imsim.InstCatalog(instcat_file, wcs, edge_pix=1000, min_source=10,
skip_invalid=False)
self.assertEqual(instcat.nobjects, 24)

instcat = imsim.InstCatalog(instcat_file, wcs, edge_pix=1000, min_source=12)
instcat = imsim.InstCatalog(instcat_file, wcs, edge_pix=1000, min_source=12,
skip_invalid=False)
self.assertEqual(instcat.nobjects, 0)

# Check various values of chunk_size.
# XXX: We don't use chunking anymore. If we revisit this and put it back in,
# then we can re-enable this test.
if 0:
for chunk_size in (5, 10, 100):
instcat = imsim.InstCatalog(instcat_file, wcs, edge_pix=1000, chunk_size=chunk_size)
instcat = imsim.InstCatalog(instcat_file, wcs, edge_pix=1000,
chunk_size=chunk_size, skip_invalid=False)
self.assertEqual(instcat.nobjects, 24)

def test_inf_filter(self):
Expand All @@ -70,7 +73,8 @@ def test_inf_filter(self):
sensor = 'R22_S11'
wcs = self.make_wcs(instcat_file, sensor)

instcat = imsim.InstCatalog(instcat_file, wcs, edge_pix=1000, min_source=10)
instcat = imsim.InstCatalog(instcat_file, wcs, edge_pix=1000, min_source=10,
skip_invalid=False)
self.assertEqual(instcat.nobjects, 26)


Expand Down

0 comments on commit cb0493d

Please sign in to comment.