panoptes.pipeline.lightcurve.masks¶
panoptes.pipeline.lightcurve.masks ¶
Bayer CFA masks and apertures for postage stamp cubes (PSCs).
Conventions used throughout this package¶
A selection mask is a boolean array where True means "this pixel belongs
to the thing being selected" (a color channel, an aperture). This is the
opposite of the numpy.ma convention, where True means "masked out".
The legacy notebook code mixed the two conventions silently. Every function
here takes and returns selection masks; convert at the numpy.ma boundary
with ~mask and nowhere else.
Bayer phase¶
The color of a pixel depends on its absolute position in the sensor, not its
position within a stamp. A stamp only has a well-defined color layout if its
origin is superpixel-aligned (both coordinates even). bayer_color_index
takes an explicit origin so this is never assumed.
bayer_color_index ¶
bayer_color_index(shape: tuple[int, int], origin: tuple[int, int] = (0, 0), pattern: str = 'RGGB') -> np.ndarray
Return an int array giving the Bayer color (RED/GREEN/BLUE) of each pixel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
tuple[int, int]
|
|
required |
origin
|
tuple[int, int]
|
|
(0, 0)
|
pattern
|
str
|
Bayer pattern of the sensor at absolute |
'RGGB'
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Array of shape |
Source code in src/panoptes/pipeline/lightcurve/masks.py
rgb_masks ¶
rgb_masks(shape: tuple[int, int], origin: tuple[int, int] = (0, 0), pattern: str = 'RGGB') -> dict[str, np.ndarray]
Return per-color boolean selection masks for a stamp.
True means the pixel belongs to that color channel. Green selects two
pixels per superpixel; red and blue select one each.
Source code in src/panoptes/pipeline/lightcurve/masks.py
is_superpixel_aligned ¶
True if a stamp has an even origin and an even size in both axes.
A stamp that fails this test cannot be compared pixel-for-pixel against another stamp, because the two carry different Bayer phases. See conformance audit 4.3.
Source code in src/panoptes/pipeline/lightcurve/masks.py
infer_green_offsets ¶
Find which two of the four quad positions are green, from the data.
The two green pixels of a Bayer quad sit behind the same filter, so their sky levels match each other and differ from red and blue. That identifies the pattern family without trusting any convention -- which matters, because getting it wrong silently mixes red and blue into one "green" channel and every per-channel result is then mislabeled.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sky_stamps
|
ndarray
|
|
required |
stamp_shape
|
tuple[int, int]
|
|
required |
Returns:
| Type | Description |
|---|---|
set[tuple[int, int]]
|
The two |
Source code in src/panoptes/pipeline/lightcurve/masks.py
infer_pattern ¶
infer_pattern(sky_stamps: ndarray, stamp_shape: tuple[int, int], red_offset: tuple[int, int] | None = None) -> str
Infer the Bayer pattern of stored data.
Green positions are recoverable from sky levels alone (see
:func:infer_green_offsets). Telling red from blue is not, reliably, so
pass red_offset -- the FITS header's MEASRGGB white-balance values,
which extract_metadata already parses, settle it.
Raises:
| Type | Description |
|---|---|
ValueError
|
if red and blue cannot be distinguished and no
|
Source code in src/panoptes/pipeline/lightcurve/masks.py
circular_aperture ¶
Boolean selection mask for pixels whose centers lie within radius.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
tuple[int, int]
|
|
required |
center
|
tuple[float, float]
|
|
required |
radius
|
float
|
Radius in pixels. |
required |
Source code in src/panoptes/pipeline/lightcurve/masks.py
grow_to_superpixels ¶
Expand a selection mask so every touched 2x2 superpixel is fully included.
Apertures that clip a superpixel change the R:G:B pixel ratio inside the aperture, which biases the per-color fluxes. Growing to whole superpixels keeps the ratio fixed at 1:2:1 regardless of where the aperture lands.
Source code in src/panoptes/pipeline/lightcurve/masks.py
weighted_aperture ¶
Optimal (inverse-variance) photometric weights for a known PSF profile.
Returns weights normalized so that sum(w * profile) == 1, i.e. applying
them to a frame recovers total flux rather than a weighted average. This is
the standard optimal-extraction weighting and is the drop-in replacement for
a hard-edged aperture in improvement plan 3.6.