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
12from astropy
import units
15from ._baseDataFrameActions
import DataFrameAction
16from ._evalColumnExpression
import makeColumnExpressionAction
22 column = Field(doc=
"Column to load for this action", dtype=str, optional=
False)
28 def __call__(self, df, **kwargs):
33 actions = ConfigurableActionStructField(doc=
"Configurable actions to use in a joint action")
37 yield from (column
for action
in self.
actions for column
in action.columns)
41 inRadians = Field(doc=
"Return the column in radians if true", default=
True, dtype=bool)
43 def __call__(self, df):
44 col = super().__call__(df)
45 return col * 180 / np.pi
if self.
inRadians else col
49 coadd_zeropoint = Field(doc=
"Magnitude zero point", dtype=float, default=27)
51 def __call__(self, df: pd.DataFrame, **kwargs):
52 if not (fluxMag0 := kwargs.get(
'fluxMag0')):
55 with warnings.catch_warnings():
56 warnings.filterwarnings(
'ignore',
r'invalid value encountered')
57 warnings.filterwarnings(
'ignore',
r'divide by zero')
58 return -2.5 * np.log10(df[self.
column] / fluxMag0)
63 def __call__(self, df: pd.DataFrame, **kwargs):
65 with warnings.catch_warnings():
66 warnings.filterwarnings(
'ignore',
r'invalid value encountered')
67 warnings.filterwarnings(
'ignore',
r'divide by zero')
68 return -2.5 * np.log10((df[self.
column] * 1e-9) / 3631.0)
72 ab_flux_scale = Field(doc=
"Scaling of ab flux", dtype=float, default=(0*units.ABmag).to_value(units.nJy))
73 coadd_zeropoint = Field(doc=
"Magnitude zero point", dtype=float, default=27)
75 def __call__(self, df, **kwargs):
76 dataNumber = super().__call__(df, **kwargs)
77 if not (fluxMag0 := kwargs.get(
'fluxMag0')):
87 flux_mag_err = Field(doc=
"Error in the magnitude zeropoint", dtype=float, default=0)
88 flux_action = ConfigurableActionField(doc=
"Action to use if flux is not provided to the call method",
89 default=NanoJansky, dtype=DataFrameAction)
95 def __call__(self, df, flux_column=None, flux_mag_err=None, **kwargs):
96 if flux_column
is None:
98 if flux_mag_err
is None:
102_docs =
"""This is a `DataFrameAction` that is designed to add two columns
103together and return the result.
105SumColumns = makeColumnExpressionAction(
"SumColumns",
"colA+colB",
106 exprDefaults={
"colA": SingleColumnAction,
107 "colB": SingleColumnAction},
110_docs =
"""This is a `MultiColumnAction` that is designed to subtract two columns
111together and return the result.
113SubtractColumns = makeColumnExpressionAction(
"SubtractColumns",
"colA-colB",
114 exprDefaults={
"colA": SingleColumnAction,
115 "colB": SingleColumnAction},
118_docs =
"""This is a `MultiColumnAction` that is designed to multiply two columns
119together and return the result.
121MultiplyColumns = makeColumnExpressionAction(
"MultiplyColumns",
"colA*colB",
122 exprDefaults={
"colA": SingleColumnAction,
123 "colB": SingleColumnAction},
126_docs =
"""This is a `MultiColumnAction` that is designed to divide two columns
127together and return the result.
129DivideColumns = makeColumnExpressionAction(
"DivideColumns",
"colA/colB",
130 exprDefaults={
"colA": SingleColumnAction,
131 "colB": SingleColumnAction},
134_docs =
"""This is a `MultiColumnAction` that is designed to divide two columns
135together, subtract one and return the result.
137FractionalDifferenceColumns = makeColumnExpressionAction(
"FractionalDifferenceColumns",
"(colA-colB)/colB",
138 exprDefaults={
"colA": SingleColumnAction,
139 "colB": SingleColumnAction},
142_docs =
"""This is a `MultiColumnAction` that is designed to subtract the division of two columns
143from the division of two other columns and return the result (i.e. colA1/colB1 - colA2/colB2).
145DiffOfDividedColumns = makeColumnExpressionAction(
"DiffOfDividedColumns",
"(colA1/colB1)-(colA2/colB2)",
146 exprDefaults={
"colA1": SingleColumnAction,
147 "colB1": SingleColumnAction,
148 "colA2": SingleColumnAction,
149 "colB2": SingleColumnAction},
151_docs =
"""This is a `MultiColumnAction` that is designed to compute the percent difference
152between the division of two columns and the division of two other columns and return the result
153(i.e. 100*((colA1/colB1 - colA2/colB2)/(colA1/colB1))).
155PercentDiffOfDividedColumns = makeColumnExpressionAction(
"PercentDiffOfDividedColumns",
156 "100*(((colA1/colB1)-(colA2/colB2))/(colA1/colB1))",
157 exprDefaults={
"colA1": SingleColumnAction,
158 "colB1": SingleColumnAction,
159 "colA2": SingleColumnAction,
160 "colB2": SingleColumnAction},
165 aggregator = ConfigurableActionField(doc=
"This is an instance of a Dataframe action that will be used "
166 "to create a new column", dtype=DataFrameAction)
167 newColumn = Field(doc=
"Name of the new column to add", dtype=str)
173 def __call__(self, df, **kwargs) -> pd.DataFrame:
Iterable[str] columns(self)
Iterable[str] columns(self)
Iterable[str] columns(self)