Coverage for python/lsst/faro/utils/prefilter.py: 7%
34 statements
« prev ^ index » next coverage.py v6.5.0, created at 2022-10-15 01:35 -0700
« prev ^ index » next coverage.py v6.5.0, created at 2022-10-15 01:35 -0700
1# This file is part of faro.
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/>.
22import numpy as np
24__all__ = ("preFilter",)
27def preFilter(
28 sourceCatalog,
29 snrMin=None,
30 snrMax=None,
31 brightMagCut=None,
32 faintMagCut=None,
33 extended=None,
34 doFlags=None,
35 isPrimary=None,
36 psfStars=None,
37 photoCalibStars=None,
38 astromCalibStars=None,
39):
41 if snrMin is None:
42 snrMin = 50.0
43 if snrMax is None:
44 snrMax = np.Inf
45 if extended is None:
46 extended = False
48 def filtSNR(cat):
49 oksnr = (cat["base_PsfFlux_snr"] > snrMin) & (cat["base_PsfFlux_snr"] < snrMax)
50 return oksnr
52 def filtMag(cat):
53 if (brightMagCut is not None) and (faintMagCut is not None):
54 okmag = (cat["base_PsfFlux_mag"] > brightMagCut) & (cat["base_PsfFlux_mag"] < faintMagCut)
55 else:
56 okmag = (cat["base_PsfFlux_mag"] < 30.0)
57 return okmag
59 def filtExtended(cat):
60 if extended:
61 sourceType = (cat["base_ClassificationExtendedness_value"] > 0.9)
62 else:
63 sourceType = (cat["base_ClassificationExtendedness_value"] < 0.1)
64 return sourceType
66 def filtFlags(cat):
67 flag_sat = ~cat["base_PixelFlags_flag_saturated"]
68 flag_cr = ~cat["base_PixelFlags_flag_cr"]
69 flag_bad = ~cat["base_PixelFlags_flag_bad"]
70 flag_edge = ~cat["base_PixelFlags_flag_edge"]
71 allflags = flag_sat & flag_cr & flag_bad & flag_edge
72 return allflags
74 def filtPrimary(cat):
75 is_primary = cat["detect_isPrimary"]
76 return is_primary
78 allfilt = filtSNR(sourceCatalog) & filtExtended(sourceCatalog) &\
79 filtFlags(sourceCatalog) & filtPrimary(sourceCatalog) &\
80 filtMag(sourceCatalog)
82 return sourceCatalog[allfilt]