1from __future__
import annotations
3__all__ = (
"SingleColumnAction",
"MultiColumnAction",
"CoordColumn",
"MagColumnDN",
"SumColumns",
"AddColumn",
4 "DivideColumns",
"SubtractColumns",
"MultiplyColumns",
"FractionalResidualColumns",
5 "MagColumnNanoJansky",)
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)
25 return (self.
columncolumn, )
27 def __call__(self, df, **kwargs):
28 return df[self.
columncolumn]
36 yield from (column
for action
in self.
actionsactions
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.
inRadiansinRadians
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.
columncolumn] / 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.
columncolumn] * 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')):
78 return self.
ab_flux_scaleab_flux_scale * dataNumber / fluxMag0
86 flux_mag_err = Field(doc=
"Error in the magnitude zeropoint", dtype=float, default=0)
88 default=NanoJansky, dtype=DataFrameAction)
94 def __call__(self, df, flux_column=None, flux_mag_err=None, **kwargs):
95 if flux_column
is None:
96 flux_column = self.
flux_actionflux_action(df, **kwargs)
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.
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.
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.
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.
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.
137 exprDefaults={
"colA": SingleColumnAction,
138 "colB": SingleColumnAction},
144 "to create a new column", dtype=DataFrameAction)
145 newColumn = Field(doc=
"Name of the new column to add", dtype=str)
151 def __call__(self, df, **kwargs) -> pd.DataFrame:
Iterable[str] columns(self)
Iterable[str] columns(self)
Iterable[str] columns(self)
Type[DataFrameAction] makeColumnExpressionAction(str className, str expr, Optional[Mapping[str, Union[DataFrameAction, Type[DataFrameAction]]]] exprDefaults=None, str docstring=None)