Skip to content

Commit d8904fc

Browse files
committed
Update guiding flag enums - tickets/INSTRM-2799
* `AutoGuiderStarMask` changed to `SourceCatalogFlags`. * `SourceDetectionFlag` changed to `SourceDetectionFlags` (singular to plural). * Add deprecation warning for above. * Added `SourceMatchingFlags`. * Added `SourceDetectionFlags.BAD_SIZE`. * Updated docstrings. * Added bitmask of zero entries for the enums. * Added better `__str__` functions for the enums.
1 parent 259b144 commit d8904fc

File tree

1 file changed

+100
-4
lines changed
  • python/pfs/utils/datamodel

1 file changed

+100
-4
lines changed

python/pfs/utils/datamodel/ag.py

Lines changed: 100 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1+
import warnings
12
from enum import IntFlag
23

34

4-
class AutoGuiderStarMask(IntFlag):
5+
class SourceCatalogFlags(IntFlag):
56
"""
6-
Represents a bitmask for guide star properties.
7+
Represents a bitmask for catalog guide star properties.
8+
9+
This was formerly named AutoGuiderStarMask.
10+
11+
See:
12+
13+
https://irsa.ipac.caltech.edu/data/Gaia/dr3/gaia_dr3_source_colDescriptions.html
14+
https://gea.esac.esa.int/archive/documentation/GDR3/Gaia_archive/chap_datamodel/sec_dm_main_source_catalogue/ssec_dm_gaia_source.html
715
816
Attributes:
17+
NONE: No properties. There shouldn't be any of these as everything is
18+
either GAIA or HSC.
919
GAIA: Gaia DR3 catalog.
1020
HSC: HSC PDR3 catalog.
1121
PMRA: Proper motion RA is measured.
@@ -20,6 +30,8 @@ class AutoGuiderStarMask(IntFlag):
2030
PHOTO_SIG: Photometric measurement is significant (SNR>5).
2131
GALAXY: Is a galaxy candidate.
2232
"""
33+
34+
NONE = 0x00000
2335
GAIA = 0x00001
2436
HSC = 0x00002
2537
PMRA = 0x00004
@@ -34,22 +46,106 @@ class AutoGuiderStarMask(IntFlag):
3446
PHOTO_SIG = 0x00800
3547
GALAXY = 0x01000
3648

49+
PROPER_MOTION_FLAGS = PMRA | PMRA_SIG | PMDEC | PMDEC_SIG
50+
PARALLAX_FLAGS = PARA | PARA_SIG
51+
ASTROMETRIC_FLAGS = ASTROMETRIC | ASTROMETRIC_SIG | NON_BINARY
52+
PHOTOMETRIC_FLAGS = PHOTO_SIG
53+
54+
ACQUISITION_FLAGS = GAIA
55+
GUIDING_FLAGS = GAIA | HSC | PROPER_MOTION_FLAGS | PARALLAX_FLAGS | ASTROMETRIC_FLAGS | PHOTOMETRIC_FLAGS
56+
57+
def __str__(self):
58+
if self == SourceCatalogFlags.NONE:
59+
return "NONE"
60+
flags = [flag.name for flag in SourceCatalogFlags if flag in self and flag != SourceCatalogFlags.NONE]
61+
return "|".join(flags)
62+
3763

38-
class SourceDetectionFlag(IntFlag):
64+
class SourceDetectionFlags(IntFlag):
3965
"""
4066
Represents a bitmask for detection properties.
4167
68+
This was formerly named SourceDetectionFlag (singular).
69+
4270
Attributes:
43-
RIGHT: Source is detected on the right side of the image.
71+
NONE: No issues detected.
72+
RIGHT: Source is detected on the right side of the image, which has
73+
a piece of glass in front of the sensor.
4474
EDGE: Source is detected at the edge of the image.
4575
SATURATED: Source is saturated.
4676
BAD_SHAPE: Source has a bad shape.
4777
BAD_ELLIP: Source has a bad ellipticity.
4878
FLAT_TOP: Source has a flat top profile.
79+
BAD_SIZE: Source has a bad size.
4980
"""
81+
82+
NONE = 0x0000
5083
RIGHT = 0x0001
5184
EDGE = 0x0002
5285
SATURATED = 0x0004
5386
BAD_SHAPE = 0x0008
5487
BAD_ELLIP = 0x0010
5588
FLAT_TOP = 0x0020
89+
BAD_SIZE = 0x0040
90+
91+
GOOD_DETECTION = NONE | RIGHT
92+
BAD_DETECTION_FLAGS = EDGE | SATURATED | BAD_SHAPE | BAD_ELLIP | FLAT_TOP | BAD_SIZE
93+
94+
def __str__(self):
95+
if self == SourceDetectionFlags.NONE:
96+
return "NONE"
97+
flags = [flag.name for flag in SourceDetectionFlags if flag in self and flag != SourceDetectionFlags.NONE]
98+
return "|".join(flags)
99+
100+
101+
class SourceMatchingFlags(IntFlag):
102+
"""
103+
Represents a bitmask for matching properties between detected and catalog sources.
104+
105+
Attributes:
106+
GOOD_MATCH: Source successfully matched with exactly one catalog entry
107+
within tolerance.
108+
NO_MATCH: Source has no matching catalog entry within tolerance.
109+
BAD_RESIDUAL: Source matched but has residual position difference
110+
larger than allowed threshold.
111+
UNUSED_MULTI_MATCH: Source was matched to a catalog entry, but wasn't the
112+
closest source so is unused.
113+
"""
114+
115+
GOOD_MATCH = 0x0000
116+
NO_MATCH = 0x0001
117+
BAD_RESIDUAL = 0x0002
118+
UNUSED_MULTI_MATCH = 0x0004
119+
120+
def __str__(self):
121+
if self == SourceMatchingFlags.GOOD_MATCH:
122+
return "GOOD_MATCH"
123+
flags = [flag.name for flag in SourceMatchingFlags if flag in self and flag != SourceMatchingFlags.GOOD_MATCH]
124+
return "|".join(flags)
125+
126+
127+
def __getattr__(name):
128+
if name == "AutoGuiderStarMask":
129+
warnings.warn(
130+
"AutoGuiderStarMask is deprecated and will be removed in a future version. "
131+
"Please use SourceCatalogFlags instead.",
132+
DeprecationWarning,
133+
stacklevel=2,
134+
)
135+
return SourceCatalogFlags
136+
137+
if name == "SourceDetectionFlag":
138+
warnings.warn(
139+
"SourceDetectionFlag is deprecated and will be removed in a future version. "
140+
"Please use SourceDetectionFlags (plural) instead.",
141+
DeprecationWarning,
142+
stacklevel=2,
143+
)
144+
return SourceCatalogFlags
145+
146+
msg = f"module {__name__!r} has no attribute {name!r}"
147+
raise AttributeError(msg)
148+
149+
150+
def __dir__():
151+
return sorted([*list(globals().keys()), "AutoGuiderStarMask", "SourceDetectionFlag"])

0 commit comments

Comments
 (0)