Skip to content

Commit

Permalink
Use mmag units for photometric repeatability
Browse files Browse the repository at this point in the history
  • Loading branch information
bechtol committed Aug 2, 2022
1 parent bec1a03 commit 7792b13
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 29 deletions.
42 changes: 21 additions & 21 deletions python/lsst/analysis/tools/actions/vector/selectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"GalaxySelector",
"UnknownSelector",
"VectorSelector",
"AndSelector",
# "AndSelector",
"ThresholdSelector",
"BandSelector",
)
Expand Down Expand Up @@ -332,26 +332,26 @@ def __call__(self, data: KeyedData, **kwargs) -> Vector:
return cast(Vector, data[self.vectorKey.format(**kwargs)])


class AndSelector(VectorAction):
"""Apply multiple selection criteria with logical AND."""

selectors = ConfigurableActionStructField[VectorAction](
doc="Selectors for selecting rows, will be AND together",
)

def getInputSchema(self) -> KeyedDataSchema:
for action in self.selectors:
yield from action.getInputSchema()

def __call__(self, data: KeyedData, **kwargs) -> KeyedData:
mask: Optional[Vector] = None
for selector in self.selectors:
subMask = selector(data, **kwargs)
if mask is None:
mask = subMask
else:
mask *= subMask # type: ignore
return cast(Vector, mask)
# class AndSelector(VectorAction):
# """Apply multiple selection criteria with logical AND."""
#
# selectors = ConfigurableActionStructField[VectorAction](
# doc="Selectors for selecting rows, will be AND together",
# )
#
# def getInputSchema(self) -> KeyedDataSchema:
# for action in self.selectors:
# yield from action.getInputSchema()
#
# def __call__(self, data: KeyedData, **kwargs) -> KeyedData:
# mask: Optional[Vector] = None
# for selector in self.selectors:
# subMask = selector(data, **kwargs)
# if mask is None:
# mask = subMask
# else:
# mask *= subMask # type: ignore
# return cast(Vector, mask)


class ThresholdSelector(VectorAction):
Expand Down
16 changes: 11 additions & 5 deletions python/lsst/analysis/tools/actions/vector/vectorActions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from __future__ import annotations

import logging
from typing import cast
from typing import Optional, cast

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -82,6 +82,7 @@ def __call__(self, data: KeyedData, **kwargs) -> Vector:

class MagColumnNanoJansky(VectorAction):
vectorKey = Field[str](doc="column key to use for this transformation")
returnMillimags = Field[bool](doc="Use millimags or not?", default=False)

def getInputSchema(self) -> KeyedDataSchema:
return ((self.vectorKey, Vector),)
Expand All @@ -91,7 +92,11 @@ def __call__(self, data: KeyedData, **kwargs) -> Vector:
np.warnings.filterwarnings("ignore", r"invalid value encountered") # type: ignore
np.warnings.filterwarnings("ignore", r"divide by zero") # type: ignore
vec = cast(Vector, data[self.vectorKey.format(**kwargs)])
return np.array(-2.5 * np.log10((vec * 1e-9) / 3631.0)) # type: ignore
mag = np.array(-2.5 * np.log10((vec * 1e-9) / 3631.0)) # type: ignore
if self.returnMillimags:
return mag * u.mag.to(u.mmag)
else:
return mag


class FractionalDifference(VectorAction):
Expand Down Expand Up @@ -281,9 +286,10 @@ def __call__(self, data: KeyedData, **kwargs) -> Vector:


class PerGroupStatistic(VectorAction):
"""Compute per-group statistic values and return result as a vector with one element per group. The
computed statistic can be any function accepted by pandas DataFrameGroupBy.aggregate passed in as a string
function name."""
"""Compute per-group statistic values and return result as a vector with
one element per group. The computed statistic can be any function accepted
by pandas DataFrameGroupBy.aggregate passed in as a string function name.
"""

groupKey = Field[str](doc="Column key to use for forming groups", default="obj_index")
buildAction = ConfigurableActionField(doc="Action to build vector", default=LoadVector)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

__all__ = ("StellarPhotometricRepeatabilityMetric",)

from astropy import units as u

from ..actions.scalar.scalarActions import FracThreshold, MedianAction
from ..actions.vector import (
BandSelector,
Expand Down Expand Up @@ -62,9 +64,11 @@ def setDefaults(self):
self.process.buildActions.perGroupCount = PerGroupStatistic()
self.process.buildActions.perGroupCount.buildAction.vectorKey = f"{self.fluxType}"
self.process.buildActions.perGroupCount.func = "count"
# Use mmag units
self.process.buildActions.perGroupStdev = PerGroupStatistic()
self.process.buildActions.perGroupStdev.buildAction = MagColumnNanoJansky(
vectorKey=f"{self.fluxType}"
vectorKey=f"{self.fluxType}",
returnMillimags=True,
)
self.process.buildActions.perGroupStdev.func = "std"

Expand Down Expand Up @@ -93,12 +97,12 @@ def setDefaults(self):
self.process.calculateActions.photRepeatOutlier = FracThreshold(
vectorKey="perGroupStdevFiltered",
op="ge",
threshold=0.015,
threshold=15.0,
percent=True,
)

self.produce.units = { # type: ignore
"photRepeatStdev": "mag",
"photRepeatStdev": "mmag",
"photRepeatOutlier": "percent",
}
self.produce.newNames = {
Expand Down

0 comments on commit 7792b13

Please sign in to comment.