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-23104: Enable per-band flags in transform object #351

Merged
merged 2 commits into from
Feb 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 8 additions & 5 deletions python/lsst/pipe/tasks/functors.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,13 @@ def from_yaml(cls, translationDefinition, **kwargs):
else:
renameRules = None

if 'refFlags' in translationDefinition:
for flag in translationDefinition['refFlags']:
funcs[cls.renameCol(flag, renameRules)] = Column(flag, dataset='ref')

if 'flags' in translationDefinition:
for flag in translationDefinition['flags']:
funcs[cls.renameCol(flag, renameRules)] = Column(flag, dataset='ref')
funcs[cls.renameCol(flag, renameRules)] = Column(flag, dataset='meas')

return cls(funcs, **kwargs)

Expand Down Expand Up @@ -445,12 +449,9 @@ class FootprintNPix(Column):
class CoordColumn(Column):
"""Base class for coordinate column, in degrees
"""
_allow_difference = False
_radians = True
_defaultNoDup = True

def __init__(self, col, calculate=False, **kwargs):
self.calculate = calculate
def __init__(self, col, **kwargs):
super().__init__(col, **kwargs)

def _func(self, df):
Expand All @@ -464,6 +465,7 @@ class RAColumn(CoordColumn):
"""Right Ascension, in degrees
"""
name = 'RA'
_defaultNoDup = True

def __init__(self, **kwargs):
super().__init__('coord_ra', **kwargs)
Expand All @@ -476,6 +478,7 @@ class DecColumn(CoordColumn):
"""Declination, in degrees
"""
name = 'Dec'
_defaultNoDup = True

def __init__(self, **kwargs):
super().__init__('coord_dec', **kwargs)
Expand Down
31 changes: 20 additions & 11 deletions python/lsst/pipe/tasks/postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ class PostprocessAnalysis(object):
functor collection, since the `filt` keyword argument of this object triggers an
overwrite of the `filt` property for all functors in the collection.

This object also allows a list of flags to be passed, and defines a set of default
flags that are always included even if not requested.
This object also allows a list of refFlags to be passed, and defines a set of default
refFlags that are always included even if not requested.

If a list of `ParquetTable` object is passed, rather than a single one, then the
calculations will be mapped over all the input catalogs. In principle, it should
Expand All @@ -247,20 +247,26 @@ class PostprocessAnalysis(object):
of the provided functors.

flags : `list` (optional)
List of flags to include in output table.
List of flags (per-band) to include in output table.

refFlags : `list` (optional)
List of refFlags (only reference band) to include in output table.


"""
_defaultFlags = ('calib_psf_used', 'detect_isPrimary')
_defaultRefFlags = ('calib_psf_used', 'detect_isPrimary')
_defaultFuncs = (('coord_ra', RAColumn()),
('coord_dec', DecColumn()))

def __init__(self, parq, functors, filt=None, flags=None):
def __init__(self, parq, functors, filt=None, flags=None, refFlags=None):
self.parq = parq
self.functors = functors

self.filt = filt
self.flags = list(self._defaultFlags)
if flags is not None:
self.flags += list(flags)
self.flags = list(flags) if flags is not None else []
self.refFlags = list(self._defaultRefFlags)
if refFlags is not None:
self.refFlags += list(refFlags)

self._df = None

Expand All @@ -272,7 +278,8 @@ def defaultFuncs(self):
@property
def func(self):
additionalFuncs = self.defaultFuncs
additionalFuncs.update({flag: Column(flag) for flag in self.flags})
additionalFuncs.update({flag: Column(flag, dataset='ref') for flag in self.refFlags})
additionalFuncs.update({flag: Column(flag, dataset='meas') for flag in self.flags})

if isinstance(self.functors, CompositeFunctor):
func = self.functors
Expand Down Expand Up @@ -364,7 +371,7 @@ class TransformCatalogBaseTask(CmdLineTask):
functor: DeconvolvedMoments
filt: HSC-G
dataset: forced_src
flags:
refFlags:
- calib_psfUsed
- merge_measurement_i
- merge_measurement_r
Expand All @@ -380,9 +387,11 @@ class TransformCatalogBaseTask(CmdLineTask):
and any additional entries for each column other than "functor" or "args" (e.g., `'filt'`,
`'dataset'`) are treated as keyword arguments to be passed to the functor initialization.

The "flags" entry is shortcut for a bunch of `Column` functors with the original column and
The "refFlags" entry is shortcut for a bunch of `Column` functors with the original column and
taken from the `'ref'` dataset.

The "flags" entry will be expanded out per band.

Note, if `'filter'` is provided as part of the `dataId` when running this task (even though
`deepCoadd_obj` does not use `'filter'`), then this will override the `filt` kwargs
provided in the YAML file, and the calculations will be done in that filter.
Expand Down