1 from __future__
import annotations
3 __all__ = (
"SingleColumnAction",
"MultiColumnAction",
"CoordColumn",
"MagColumnDN",
"SumColumns",
"AddColumn",
4 "DivideColumns",
"SubtractColumns",
"MultiplyColumns",
"MagColumnNanoJansky",)
6 from typing
import Iterable
10 from astropy
import units
12 from ..configurableActions
import ConfigurableActionStructField, ConfigurableActionField
13 from ._baseDataFrameActions
import DataFrameAction
14 from ._evalColumnExpression
import makeColumnExpressionAction
20 column = Field(doc=
"Column to load for this action", dtype=str, optional=
False)
24 return (self.
columncolumn, )
26 def __call__(self, df, **kwargs):
27 return df[self.
columncolumn]
35 yield from (column
for action
in self.
actionsactions
for column
in action.columns)
39 inRadians = Field(doc=
"Return the column in radians if true", default=
True, dtype=bool)
41 def __call__(self, df):
42 col = super().__call__(df)
43 return col * 180 / np.pi
if self.
inRadiansinRadians
else col
47 coadd_zeropoint = Field(doc=
"Magnitude zero point", dtype=float, default=27)
49 def __call__(self, df: pd.DataFrame, **kwargs):
50 if not (fluxMag0 := kwargs.get(
'fluxMag0')):
53 with np.warnings.catch_warnings():
54 np.warnings.filterwarnings(
'ignore',
r'invalid value encountered')
55 np.warnings.filterwarnings(
'ignore',
r'divide by zero')
56 return -2.5 * np.log10(df[self.
columncolumn] / fluxMag0)
61 def __call__(self, df: pd.DataFrame, **kwargs):
63 with np.warnings.catch_warnings():
64 np.warnings.filterwarnings(
'ignore',
r'invalid value encountered')
65 np.warnings.filterwarnings(
'ignore',
r'divide by zero')
66 return -2.5 * np.log10((df[self.
columncolumn] * 1e-9) / 3631.0)
70 ab_flux_scale = Field(doc=
"Scaling of ab flux", dtype=float, default=(0*units.ABmag).to_value(units.nJy))
71 coadd_zeropoint = Field(doc=
"Magnitude zero point", dtype=float, default=27)
73 def __call__(self, df, **kwargs):
74 dataNumber = super().__call__(df, **kwargs)
75 if not (fluxMag0 := kwargs.get(
'fluxMag0')):
77 return self.
ab_flux_scaleab_flux_scale * dataNumber / fluxMag0
85 flux_mag_err = Field(doc=
"Error in the magnitude zeropoint", dtype=float, default=0)
87 default=NanoJansky, dtype=DataFrameAction)
93 def __call__(self, df, flux_column=None, flux_mag_err=None, **kwargs):
94 if flux_column
is None:
95 flux_column = self.
flux_actionflux_action(df, **kwargs)
96 if flux_mag_err
is None:
100 _docs =
"""This is a `DataFrameAction` that is designed to add two columns
101 together and return the result.
104 exprDefaults={
"colA": SingleColumnAction,
105 "colB": SingleColumnAction},
108 _docs =
"""This is a `MultiColumnAction` that is designed to subtract two columns
109 together and return the result.
112 exprDefaults={
"colA": SingleColumnAction,
113 "colB": SingleColumnAction},
116 _docs =
"""This is a `MultiColumnAction` that is designed to multiply two columns
117 together and return the result.
120 exprDefaults={
"colA": SingleColumnAction,
121 "colB": SingleColumnAction},
124 _docs =
"""This is a `MultiColumnAction` that is designed to multiply two columns
125 together and return the result.
128 exprDefaults={
"colA": SingleColumnAction,
129 "colB": SingleColumnAction},
135 "to create a new column", dtype=DataFrameAction)
136 newColumn = Field(doc=
"Name of the new column to add", dtype=str)
142 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)