Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-27045: Add normalize_on_init to readText and readFits #212

Merged
merged 2 commits into from
Oct 3, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 22 additions & 7 deletions python/lsst/meas/algorithms/defects.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,14 +530,19 @@ def _get_values(values, n=1):
return values[:n]

@classmethod
def fromTable(cls, table):
def fromTable(cls, table, normalize_on_init=True):
"""Construct a `Defects` from the contents of a
`~lsst.afw.table.BaseCatalog`.

Parameters
----------
table : `lsst.afw.table.BaseCatalog`
Table with one row per defect.
normalize_on_init : `bool`, optional
If `True`, normalization is applied to the defects listed in the
table to remove duplicates, eliminate overlaps, etc. Otherwise
the defects in the returned object exactly match those in the
table.

Returns
-------
Expand Down Expand Up @@ -633,7 +638,7 @@ def fromTable(cls, table):

defectList.append(box)

defects = cls(defectList)
defects = cls(defectList, normalize_on_init=normalize_on_init)
defects.setMetadata(table.getMetadata())

# Once read, the schema headers are irrelevant
Expand All @@ -645,31 +650,41 @@ def fromTable(cls, table):
return defects

@classmethod
def readFits(cls, *args):
def readFits(cls, *args, normalize_on_init=False):
"""Read defect list from FITS table.

Parameters
----------
*args
Arguments to be forwarded to
`lsst.afw.table.BaseCatalog.writeFits`.
`lsst.afw.table.BaseCatalog.readFits`.
normalize_on_init : `bool`, optional
If `True`, normalization is applied to the defects read fom the
file to remove duplicates, eliminate overlaps, etc. Otherwise
the defects in the returned object exactly match those in the
file.

Returns
-------
defects : `Defects`
Defects read from a FITS table.
"""
table = lsst.afw.table.BaseCatalog.readFits(*args)
return cls.fromTable(table)
return cls.fromTable(table, normalize_on_init=normalize_on_init)

@classmethod
def readText(cls, filename):
def readText(cls, filename, normalize_on_init=False):
"""Read defect list from standard format text table file.

Parameters
----------
filename : `str`
Name of the file containing the defects definitions.
normalize_on_init : `bool`, optional
If `True`, normalization is applied to the defects read fom the
file to remove duplicates, eliminate overlaps, etc. Otherwise
the defects in the returned object exactly match those in the
file.

Returns
-------
Expand Down Expand Up @@ -704,7 +719,7 @@ def readText(cls, filename):
afwTable.setMetadata(metadata)

# Extract defect information from the table itself
return cls.fromTable(afwTable)
return cls.fromTable(afwTable, normalize_on_init=normalize_on_init)

@classmethod
def readLsstDefectsFile(cls, filename):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_interp.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ def testAstropyRegion(self):
# The two coincident points are combined on read, so we end up with two defects.

with self.assertLogs():
defects = algorithms.Defects.readFits(os.path.join(TESTDIR, "data", "fits_region.fits"))
defects = algorithms.Defects.readFits(os.path.join(TESTDIR, "data", "fits_region.fits"),
normalize_on_init=True)

self.assertEqual(len(defects), 2)

Expand Down