Coverage for python/lsst/ap/association/trailedSourceFilter.py: 78%
16 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-10-19 11:23 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2023-10-19 11:23 +0000
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/>.
22__all__ = ("TrailedSourceFilterTask", "TrailedSourceFilterConfig")
24import lsst.pex.config as pexConfig
25import lsst.pipe.base as pipeBase
26from lsst.utils.timer import timeMethod
29class TrailedSourceFilterConfig(pexConfig.Config):
30 """Config class for TrailedSourceFilterTask.
31 """
33 max_trail_length = 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/24 arcsec/second, or roughly"
39 "0.416 arcseconds per second.",
40 default=36000/3600.0/24.0,
41 )
44class TrailedSourceFilterTask(pipeBase.Task):
45 """Find trailed sources in DIASources and filter them as per DMTN-199
46 guidelines.
48 This task checks the length of trailLength in the DIASource catalog using
49 a given arcsecond/second rate from max_trail_length 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 max_trail_length is
52 outlined in DMTN-199 and determines the default value.
53 """
55 ConfigClass = TrailedSourceFilterConfig
56 _DefaultName = "trailedSourceFilter"
58 @timeMethod
59 def run(self, dia_sources, exposure_time):
60 """Remove trailed sources longer than ``config.max_trail_length`` from
61 the input catalog.
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.
70 Returns
71 -------
72 result : `lsst.pipe.base.Struct`
73 Results struct with components.
75 - ``dia_sources`` : DIASource table that is free from unwanted
76 trailed sources. (`pandas.DataFrame`)
78 - ``trailed_dia_sources`` : DIASources that have trails which
79 exceed max_trail_length/second*exposure_time.
80 (`pandas.DataFrame`)
81 """
82 trail_mask = self._check_dia_source_trail(dia_sources, exposure_time)
84 return pipeBase.Struct(
85 diaSources=dia_sources[~trail_mask].reset_index(drop=True),
86 trailedDiaSources=dia_sources[trail_mask].reset_index(drop=True))
88 def _check_dia_source_trail(self, dia_sources, exposure_time):
89 """Find DiaSources that have long trails.
91 Return a mask of sources with lengths greater than
92 ``config.max_trail_length`` multiplied by the exposure time.
94 Parameters
95 ----------
96 dia_sources : `pandas.DataFrame`
97 Input DIASources to check for trail lengths.
98 exposure_time : `float`
99 Exposure time from difference image.
101 Returns
102 -------
103 trail_mask : `pandas.DataFrame`
104 Boolean mask for DIASources which are greater than the
105 cutoff length.
106 """
107 trail_mask = (dia_sources.loc[:, "trailLength"].values[:]
108 >= (self.config.max_trail_length*exposure_time))
110 return trail_mask