| 
 | 1 | +# This file is part of ap_association.  | 
 | 2 | +#  | 
 | 3 | +# Developed for the LSST Data Management System.  | 
 | 4 | +# This product includes software developed by the LSST Project  | 
 | 5 | +# (https://www.lsst.org).  | 
 | 6 | +# See the COPYRIGHT file at the top-level directory of this distribution  | 
 | 7 | +# for details of code ownership.  | 
 | 8 | +#  | 
 | 9 | +# This program is free software: you can redistribute it and/or modify  | 
 | 10 | +# it under the terms of the GNU General Public License as published by  | 
 | 11 | +# the Free Software Foundation, either version 3 of the License, or  | 
 | 12 | +# (at your option) any later version.  | 
 | 13 | +#  | 
 | 14 | +# This program is distributed in the hope that it will be useful,  | 
 | 15 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of  | 
 | 16 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  | 
 | 17 | +# GNU General Public License for more details.  | 
 | 18 | +#  | 
 | 19 | +# You should have received a copy of the GNU General Public License  | 
 | 20 | +# along with this program.  If not, see <https://www.gnu.org/licenses/>.  | 
 | 21 | + | 
 | 22 | +__all__ = ("TrailedSourceFilterTask", "TrailedSourceFilterConfig")  | 
 | 23 | + | 
 | 24 | +import lsst.pex.config as pexConfig  | 
 | 25 | +import lsst.pipe.base as pipeBase  | 
 | 26 | +from lsst.utils.timer import timeMethod  | 
 | 27 | + | 
 | 28 | + | 
 | 29 | +class TrailedSourceFilterConfig(pexConfig.Config):  | 
 | 30 | +    """Config class for TrailedSourceFilterTask.  | 
 | 31 | +    """  | 
 | 32 | + | 
 | 33 | +    maxTrailLength = pexConfig.Field(  | 
 | 34 | +        dtype=float,  | 
 | 35 | +        doc="Length of long trailed sources to remove from the input catalog, "  | 
 | 36 | +            "in arcseconds per second. Default comes from DMTN-199, which "  | 
 | 37 | +            "requires removal of sources with trails longer than 10 "  | 
 | 38 | +            "degrees/day, which is 36000/3600/24arcsec/second, or roughly"  | 
 | 39 | +            "0.416 arcseconds per second.",  | 
 | 40 | +        default=36000/3600.0/24.0,  | 
 | 41 | +    )  | 
 | 42 | + | 
 | 43 | + | 
 | 44 | +class TrailedSourceFilterTask(pipeBase.Task):  | 
 | 45 | +    """Find trailed sources in DIASources and filter them as per DMTN-199  | 
 | 46 | +    guidelines.  | 
 | 47 | +
  | 
 | 48 | +    This task checks the length of trailLength in the DIASource catalog using  | 
 | 49 | +    a given arcsecond/second rate from maxTrailLength and the exposure time.  | 
 | 50 | +    The two values are used to calculate the maximum allowed trail length and  | 
 | 51 | +    filters out any trail longer than the maximum. The maxTrailLength is  | 
 | 52 | +    outlined in DMTN-199 and determines the default value.  | 
 | 53 | +    """  | 
 | 54 | + | 
 | 55 | +    ConfigClass = TrailedSourceFilterConfig  | 
 | 56 | +    _DefaultName = "trailedSourceFilter"  | 
 | 57 | + | 
 | 58 | +    @timeMethod  | 
 | 59 | +    def run(self, dia_sources, exposure_time):  | 
 | 60 | +        """Remove trailed sources longer than ``config.maxTrailLength`` from  | 
 | 61 | +        the input catalog.  | 
 | 62 | +
  | 
 | 63 | +        Parameters  | 
 | 64 | +        ----------  | 
 | 65 | +        dia_sources : `pandas.DataFrame`  | 
 | 66 | +            New DIASources to be checked for trailed sources.  | 
 | 67 | +        exposure_time : `float`  | 
 | 68 | +            Exposure time from difference image.  | 
 | 69 | +
  | 
 | 70 | +        Returns  | 
 | 71 | +        -------  | 
 | 72 | +        result : `lsst.pipe.base.Struct`  | 
 | 73 | +            Results struct with components.  | 
 | 74 | +
  | 
 | 75 | +            - ``dia_sources`` : DIASource table that is free from unwanted  | 
 | 76 | +             trailed sources. (`pandas.DataFrame`)  | 
 | 77 | +
  | 
 | 78 | +            - ``trailed_dia_sources`` : DIASources that have trails which  | 
 | 79 | +            exceed maxTrailLength/second*exposure_time.  | 
 | 80 | +            (`pandas.DataFrame`)  | 
 | 81 | +        """  | 
 | 82 | + | 
 | 83 | +        trail_mask = self._check_dia_source_trail(dia_sources, exposure_time)  | 
 | 84 | + | 
 | 85 | +        return pipeBase.Struct(  | 
 | 86 | +            diaSources=dia_sources[~trail_mask].reset_index(drop=True),  | 
 | 87 | +            trailedDiaSources=dia_sources[trail_mask].reset_index(drop=True))  | 
 | 88 | + | 
 | 89 | +    def _check_dia_source_trail(self, dia_sources, exposure_time):  | 
 | 90 | +        """Find DiaSources that have long trails.  | 
 | 91 | +
  | 
 | 92 | +        Creates a mask for sources with lengths greater than 0.416  | 
 | 93 | +        arcseconds/second multiplied by the exposure time.  | 
 | 94 | +
  | 
 | 95 | +        Parameters  | 
 | 96 | +        ----------  | 
 | 97 | +        dia_sources : `pandas.DataFrame`  | 
 | 98 | +            Input DIASources to check for trail lengths.  | 
 | 99 | +        exposure_time : `float`  | 
 | 100 | +            Exposure time from difference image.  | 
 | 101 | +
  | 
 | 102 | +        Returns  | 
 | 103 | +        -------  | 
 | 104 | +        trail_mask : `pandas.DataFrame`  | 
 | 105 | +            Boolean mask for DIASources which are greater than the  | 
 | 106 | +            cutoff length.  | 
 | 107 | +        """  | 
 | 108 | + | 
 | 109 | +        trail_mask = (dia_sources.loc[:, "trailLength"].values[:]  | 
 | 110 | +                      >= (self.config.maxTrailLength*exposure_time))  | 
 | 111 | + | 
 | 112 | +        return trail_mask  | 
0 commit comments