-
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 in length. Update unit test
- Loading branch information
1 parent
e97dcde
commit 8052e0c
Showing
6 changed files
with
223 additions
and
16 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,116 @@ | ||
# 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/>. | ||
|
||
"""A simple implementation of source association task for ap_verify. | ||
""" | ||
|
||
__all__ = ["TrailedSourceFilterTask", "TrailedSourceFilterConfig"] | ||
|
||
import lsst.pex.config as pexConfig | ||
import lsst.pipe.base as pipeBase | ||
from lsst.utils.timer import timeMethod | ||
|
||
# import numpy as np | ||
import pandas as pd | ||
|
||
# Enforce an error for unsafe column/array value setting in pandas. | ||
pd.options.mode.chained_assignment = 'raise' | ||
|
||
|
||
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.0416 arcseconds per second.As trail length is measured in ' | ||
'arcseconds, it is dependant on the length of the exposure.', | ||
default=0.416, # HSC Default. Should Decam and LSST defaults be passed? Does it change possibly? | ||
) | ||
|
||
|
||
class TrailedSourceFilterTask(pipeBase.Task): | ||
"""Find trailed sources in DIAObjects. | ||
""" | ||
|
||
ConfigClass = TrailedSourceFilterConfig | ||
_DefaultName = "trailedAssociation" | ||
|
||
@timeMethod | ||
def run(self, | ||
dia_sources, exposure): | ||
"""Find trailed sources which have not been filtered out and will | ||
not be included in the diaSource catalog. | ||
Parameters | ||
---------- | ||
diaSources : `pandas.DataFrame` | ||
New DIASources to be checked for trailed sources. | ||
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 | ||
65 pixels in length (`pandas.DataFrame`) | ||
""" | ||
trail_mask = self.check_dia_source_trail(dia_sources, exposure) | ||
|
||
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, exposure): | ||
"""Check that all DiaSources have trails. | ||
If one or more DiaSources are found to have trails with lengths greater than 65 pixels (roughly 10.4 | ||
arcseconds), throw a warning to the log with the ids of the offending sources. Add to separate table | ||
and remove from DiaSource Table. | ||
Parameters | ||
---------- | ||
dia_sources : `pandas.DataFrame` | ||
Input DiaSources to check for trail lengths. | ||
Returns | ||
------- | ||
trimmed_sources : `pandas.DataFrame` | ||
DataFrame of DiaSources trimmed of all entries with tail values greater than 65 arcseconds. | ||
""" | ||
exposure_time = exposure.getInfo().getVisitInfo().getExposureTime() | ||
print(" Exposure time ", exposure_time) | ||
trail_mask = (dia_sources.loc[:, "trailLength"].values[:] >= self.config.maxTrailLength*exposure_time) | ||
print("Max length in arcseconds ", self.config.maxTrailLength*exposure_time) | ||
# trail_idxs = np.argwhere(trail_mask.to_numpy()).flatten() | ||
# for trail_idx in trail_idxs: | ||
# self.log.warning( | ||
# "DiaSource %i has a tail greater than 5 arcseconds, " | ||
# "dropping from association." % | ||
# dia_sources.loc[trail_idx, "diaSourceId"]) | ||
# dia_sources = dia_sources[~trail_mask] | ||
# trailed_dia_sources = dia_sources[trail_mask] | ||
|
||
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