-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make trailedAssociatorTask which filters out trails whose lengths are above 0.416 arcseconds/second times the exposure time in length.
- Loading branch information
1 parent
6758148
commit 2c8f5ae
Showing
7 changed files
with
265 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
# This file is part of ap_association. | ||
# | ||
# Developed for the LSST Data Management System. | ||
# This product includes software developed by the LSST Project | ||
# (https://www.lsst.org). | ||
# See the COPYRIGHT file at the top-level directory of this distribution | ||
# for details of code ownership. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
__all__ = ("TrailedSourceFilterTask", "TrailedSourceFilterConfig") | ||
|
||
import lsst.pex.config as pexConfig | ||
import lsst.pipe.base as pipeBase | ||
from lsst.utils.timer import timeMethod | ||
|
||
|
||
class TrailedSourceFilterConfig(pexConfig.Config): | ||
"""Config class for TrailedSourceFilterTask. | ||
""" | ||
maxTrailLength = pexConfig.Field( | ||
dtype=float, | ||
doc='Maximum trail length permitted is less than 10 degrees/day. ' | ||
'This is a rate of 0.416 arcseconds per second. As trail length' | ||
' is measured in arcseconds, it is dependant on the length of ' | ||
'the exposure.', | ||
default=0.416, | ||
) | ||
|
||
|
||
class TrailedSourceFilterTask(pipeBase.Task): | ||
"""Find trailed sources in DIASources. This task checks the length of | ||
trailLength in the DIASource catalog against using a given | ||
arcsecond/second rate from maxTrailLength and the exposure time | ||
to calculate the maximum allowed length before filtering. | ||
""" | ||
|
||
ConfigClass = TrailedSourceFilterConfig | ||
_DefaultName = "trailedSourceFilter" | ||
|
||
@timeMethod | ||
def run(self, dia_sources, diffIm): | ||
"""Find trailed sources which do not meet requirements and | ||
will not be included in the diaSource catalog. | ||
Parameters | ||
---------- | ||
dia_sources : `pandas.DataFrame` | ||
New DIASources to be checked for trailed sources. | ||
diffIm : `lsst.afw.image.ExposureF` | ||
Difference image on which the DIASources were detected. | ||
Returns | ||
------- | ||
result : `lsst.pipe.base.Struct` | ||
Results struct with components. | ||
- ``dia_sources`` : DIASource table that is free from unwanted | ||
trailed sources. (`pandas.DataFrame`) | ||
- ``trailed_dia_sources`` : DIASources that have trailed more | ||
than 0.416 arcseconds/second*exposure_time. (`pandas.DataFrame`) | ||
""" | ||
|
||
trail_mask = self.check_dia_source_trail(dia_sources, diffIm) | ||
|
||
return pipeBase.Struct( | ||
diaSources=dia_sources[~trail_mask].reset_index(drop=True), | ||
trailedDiaSources=dia_sources[trail_mask].reset_index(drop=True)) | ||
|
||
def check_dia_source_trail(self, dia_sources, diffIm): | ||
"""Find DiaSources that have trails. | ||
Creates a mask for sources with lengths greater than 0.416 | ||
arcseconds/second multiplied by the exposure time. | ||
Parameters | ||
---------- | ||
dia_sources : `pandas.DataFrame` | ||
Input DIASources to check for trail lengths. | ||
diffIm : `pandas.DataFrame` | ||
Difference image on which the DIASources were detected. | ||
Returns | ||
------- | ||
trail_mask : `pandas.DataFrame` | ||
Boolean mask for DIASources which are greater than the | ||
cutoff length. | ||
""" | ||
diffIm_time = diffIm.getInfo().getVisitInfo().getExposureTime() | ||
trail_mask = (dia_sources.loc[:, "trailLength"].values[:] >= self.config.maxTrailLength*diffIm_time) | ||
|
||
return trail_mask |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import unittest | ||
from lsst.ap.association import TrailedSourceFilterTask | ||
import numpy as np | ||
import pandas as pd | ||
import lsst.afw.image as afwImage | ||
import lsst.utils.tests | ||
|
||
|
||
class TestTrailedSourceFilterTask(unittest.TestCase): | ||
|
||
def setUp(self): | ||
"""Create sets of diaSources and diaObjects. | ||
""" | ||
rng = np.random.default_rng(1234) | ||
scatter = 0.1 / 3600 | ||
self.nSources = 5 | ||
self.diaSources = pd.DataFrame(data=[ | ||
{"ra": 0.04*idx + scatter*rng.uniform(-1, 1), | ||
"dec": 0.04*idx + scatter*rng.uniform(-1, 1), | ||
"diaSourceId": idx, "diaObjectId": 0, "trailLength": 5.5*idx} | ||
for idx in range(self.nSources)]) | ||
visitInfo = afwImage.VisitInfo(exposureTime=30.0, | ||
) | ||
exposureInfo = afwImage.ExposureInfo() | ||
exposureInfo.setVisitInfo(visitInfo) | ||
maskedImage = afwImage.MaskedImageF(lsst.geom.Extent2I(64, 64)) | ||
self.exposure = afwImage.ExposureF(maskedImage, exposureInfo) | ||
|
||
def test_run(self): | ||
# Run with default trail length | ||
|
||
trailedSourceFilterTask = TrailedSourceFilterTask() | ||
|
||
results = trailedSourceFilterTask.run(self.diaSources, self.exposure) | ||
|
||
self.assertEqual(len(results.diaSources), | ||
3) | ||
|
||
def test_run_short_max_trail(self): | ||
# Run with low trail rate cutoff to test config settings. | ||
|
||
config = TrailedSourceFilterTask.ConfigClass() | ||
config.maxTrailLength = 0.01 | ||
trailedSourceFilterTask = TrailedSourceFilterTask(config=config) | ||
|
||
results = trailedSourceFilterTask.run(self.diaSources, self.exposure) | ||
|
||
self.assertEqual(len(results.diaSources), | ||
1) | ||
|
||
def test_run_no_trails(self): | ||
# Run with long trail length rate so that no sources are filtered. | ||
|
||
config = TrailedSourceFilterTask.ConfigClass() | ||
config.maxTrailLength = 10.00 | ||
trailedSourceFilterTask = TrailedSourceFilterTask(config=config) | ||
|
||
results = trailedSourceFilterTask.run(self.diaSources, self.exposure) | ||
|
||
self.assertEqual(len(results.diaSources), | ||
5) | ||
self.assertEqual(len(results.trailedDiaSources), | ||
0) | ||
|
||
def test_check_dia_source_trail(self): | ||
# Check that the task outputs the correct masks. | ||
|
||
trailedSourceFilterTask = TrailedSourceFilterTask() | ||
mask = trailedSourceFilterTask.check_dia_source_trail(self.diaSources, self.exposure) | ||
|
||
comparison = mask == [False, False, False, True, True] | ||
self.assertTrue(comparison.all()) | ||
|
||
|
||
class MemoryTester(lsst.utils.tests.MemoryTestCase): | ||
pass | ||
|
||
|
||
def setup_module(module): | ||
lsst.utils.tests.init() | ||
|
||
|
||
if __name__ == "__main__": | ||
lsst.utils.tests.init() | ||
unittest.main() |