1from __future__
import annotations
3__all__ = (
"SingleColumnAction",
"MultiColumnAction",
"CoordColumn",
"MagColumnDN",
"SumColumns",
"AddColumn",
4 "DivideColumns",
"SubtractColumns",
"MultiplyColumns",
"FractionalDifferenceColumns",
5 "MagColumnNanoJansky",
"DiffOfDividedColumns",
"PercentDiffOfDividedColumns",)
7from typing
import Iterable
11from astropy
import units
13from ..configurableActions
import ConfigurableActionStructField, ConfigurableActionField
14from ._baseDataFrameActions
import DataFrameAction
15from ._evalColumnExpression
import makeColumnExpressionAction
21 column = Field(doc=
"Column to load for this action", dtype=str, optional=
False)
27 def __call__(self, df, **kwargs):
32 actions = ConfigurableActionStructField(doc=
"Configurable actions to use in a joint action")
36 yield from (column
for action
in self.
actions for column
in action.columns)
40 inRadians = Field(doc=
"Return the column in radians if true", default=
True, dtype=bool)
42 def __call__(self, df):
43 col = super().__call__(df)
44 return col * 180 / np.pi
if self.
inRadians else col
48 coadd_zeropoint = Field(doc=
"Magnitude zero point", dtype=float, default=27)
50 def __call__(self, df: pd.DataFrame, **kwargs):
51 if not (fluxMag0 := kwargs.get(
'fluxMag0')):
54 with np.warnings.catch_warnings():
55 np.warnings.filterwarnings(
'ignore',
r'invalid value encountered')
56 np.warnings.filterwarnings(
'ignore',
r'divide by zero')
57 return -2.5 * np.log10(df[self.
column] / fluxMag0)
62 def __call__(self, df: pd.DataFrame, **kwargs):
64 with np.warnings.catch_warnings():
65 np.warnings.filterwarnings(
'ignore',
r'invalid value encountered')
66 np.warnings.filterwarnings(
'ignore',
r'divide by zero')
67 return -2.5 * np.log10((df[self.
column] * 1e-9) / 3631.0)
71 ab_flux_scale = Field(doc=
"Scaling of ab flux", dtype=float, default=(0*units.ABmag).to_value(units.nJy))
72 coadd_zeropoint = Field(doc=
"Magnitude zero point", dtype=float, default=27)
74 def __call__(self, df, **kwargs):
75 dataNumber = super().__call__(df, **kwargs)
76 if not (fluxMag0 := kwargs.get(
'fluxMag0')):
86 flux_mag_err = Field(doc=
"Error in the magnitude zeropoint", dtype=float, default=0)
87 flux_action = ConfigurableActionField(doc=
"Action to use if flux is not provided to the call method",
88 default=NanoJansky, dtype=DataFrameAction)
94 def __call__(self, df, flux_column=None, flux_mag_err=None, **kwargs):
95 if flux_column
is None:
97 if flux_mag_err
is None:
101_docs =
"""This is a `DataFrameAction` that is designed to add two columns
102together and return the result.
104SumColumns = makeColumnExpressionAction(
"SumColumns",
"colA+colB",
105 exprDefaults={
"colA": SingleColumnAction,
106 "colB": SingleColumnAction},
109_docs =
"""This is a `MultiColumnAction` that is designed to subtract two columns
110together and return the result.
112SubtractColumns = makeColumnExpressionAction(
"SubtractColumns",
"colA-colB",
113 exprDefaults={
"colA": SingleColumnAction,
114 "colB": SingleColumnAction},
117_docs =
"""This is a `MultiColumnAction` that is designed to multiply two columns
118together and return the result.
120MultiplyColumns = makeColumnExpressionAction(
"MultiplyColumns",
"colA*colB",
121 exprDefaults={
"colA": SingleColumnAction,
122 "colB": SingleColumnAction},
125_docs =
"""This is a `MultiColumnAction` that is designed to divide two columns
126together and return the result.
128DivideColumns = makeColumnExpressionAction(
"DivideColumns",
"colA/colB",
129 exprDefaults={
"colA": SingleColumnAction,
130 "colB": SingleColumnAction},
133_docs =
"""This is a `MultiColumnAction` that is designed to divide two columns
134together, subtract one and return the result.
136FractionalDifferenceColumns = makeColumnExpressionAction(
"FractionalDifferenceColumns",
"(colA-colB)/colB",
137 exprDefaults={
"colA": SingleColumnAction,
138 "colB": SingleColumnAction},
141_docs =
"""This is a `MultiColumnAction` that is designed to subtract the division of two columns
142from the division of two other columns and return the result (i.e. colA1/colB1 - colA2/colB2).
144DiffOfDividedColumns = makeColumnExpressionAction(
"DiffOfDividedColumns",
"(colA1/colB1)-(colA2/colB2)",
145 exprDefaults={
"colA1": SingleColumnAction,
146 "colB1": SingleColumnAction,
147 "colA2": SingleColumnAction,
148 "colB2": SingleColumnAction},
150_docs =
"""This is a `MultiColumnAction` that is designed to compute the percent difference
151between the division of two columns and the division of two other columns and return the result
152(i.e. 100*((colA1/colB1 - colA2/colB2)/(colA1/colB1))).
154PercentDiffOfDividedColumns = makeColumnExpressionAction(
"PercentDiffOfDividedColumns",
155 "100*(((colA1/colB1)-(colA2/colB2))/(colA1/colB1))",
156 exprDefaults={
"colA1": SingleColumnAction,
157 "colB1": SingleColumnAction,
158 "colA2": SingleColumnAction,
159 "colB2": SingleColumnAction},
164 aggregator = ConfigurableActionField(doc=
"This is an instance of a Dataframe action that will be used "
165 "to create a new column", dtype=DataFrameAction)
166 newColumn = Field(doc=
"Name of the new column to add", dtype=str)
172 def __call__(self, df, **kwargs) -> pd.DataFrame:
Iterable[str] columns(self)
Iterable[str] columns(self)
Iterable[str] columns(self)