lightcurvelynx.noise_models.pzflow_noise_model
A wrapper that trains and queries pzflow for sampling noise.
We strongly recommend using the learn_pzflow_noise_model function to train
a flow and create a PZFlowNoiseModel.
For the full pzflow package see: https://github.com/jfcrenshaw/pzflow
Classes
A noise model that uses pzflow to sample noise parameters (standard |
Functions
|
Train a pzflow model to predict noise parameters (standard deviation of the noise) for |
Module Contents
- class PZFlowNoiseModel(flow_obj, *, input_col_map=None, normalizer_data=None)[source]
Bases:
lightcurvelynx.noise_models.base_noise_models.FluxNoiseModel,citation_compass.CiteClassA noise model that uses pzflow to sample noise parameters (standard deviation of the noise) for bandflux measurements.
The names of the pzflow input parameters should either match the column names or be mapped to column names in the ObsTable using the input_col_map when creating the PZFlowNoiseModel. The exception to this is bandflux input, which would be passed directly as an argument to the apply_noise method.
We strongly recommend using the
learn_pzflow_noise_modelfunction to train a flow and create a PZFlowNoiseModel as this will correctly handle potentially error-prone aspects like normalization.References
Paper: Crenshaw et. al. 2024 - https://ui.adsabs.harvard.edu/abs/2024AJ….168…80C
Zenodo: Crenshaw et. al. 2024 - https://doi.org/10.5281/zenodo.10710271
- Parameters:
flow_obj (pzflow.flow.Flow or pzflow.flowEnsemble.FlowEnsemble) – The object from which to sample.
input_col_map (dict, optional) – A dictionary where the keys are the input parameter names for the pzflow model and the values are the names of the columns in the ObsTable that should be used for those parameters.
normalizer_data (dict, optional) – A dictionary where the keys are the column names of the data used for training the flow and the values are _ColumnNormalizationData objects that contain the information needed to normalize and denormalize the data for prediction.
- add_column_mapping(flow_input_name, obs_table_col_name)[source]
Add a mapping from a pzflow input parameter name to an ObsTable column name.
This function is used when the model is created with on data with different column names than the ObsTable on which it will be applied.
- Parameters:
flow_input_name (str) – The name of the input parameter for the pzflow model.
obs_table_col_name (str) – The name of the column in the ObsTable that should be used for this parameter.
- classmethod from_file(filename, *, input_col_map=None)[source]
Create a PZFlowNoiseModel from a saved file.
- Parameters:
filename (str or Path) – The location of the saved flow.
input_col_map (dict, optional) – A dictionary where the keys are the input parameter names for the pzflow model and the values are the names of the columns in the ObsTable that should be used for those parameters. If provided this overrides the input_col_map that was saved with the model.
- apply_noise(bandflux, *, obs_table=None, indices=None, rng=None, **kwargs)[source]
Compute the noise parameters for given observations in an ObsTable and apply noise to the input bandflux.
- Parameters:
bandflux (array_like of float) – Source bandflux in energy units, e.g. nJy.
obs_table (ObsTable, optional) – Table containing the observation parameters, including all parameters needed to compute the noise.
indices (array_like of int, optional) – Indices of the observations in the ObsTable to which noise should be applied.
rng (np.random.Generator, optional) – The random number generator to use for applying noise. If None, a default generator will be used.
**kwargs – Additional parameters for the noise model.
- Returns:
flux (array_like) – The updated flux measurements after applying noise, in the same units as the input bandflux.
flux_err (array_like) – The bandflux measurement error used for applying noise, in the same units as the input bandflux.
- learn_pzflow_noise_model(data, *, noise_column=None, normalize=True, **kwargs)[source]
Train a pzflow model to predict noise parameters (standard deviation of the noise) for bandflux measurements.
- Parameters:
data (dict or pd.DataFrame) – The data to be used for training the flow. This should include all conditional parameters listed in the
conditional_columnsparameter as well as thenoise_columnparameter.noise_column (str or array_like, optional) – The name of the column in
datathat contains the noise values to predict. All other columns are treated as input.normalize (bool, optional) – Whether to normalize the data for training the flow. This can help the flow learn the distribution more effectively, especially if the data has a large dynamic range or is highly skewed.
**kwargs – Additional parameters for training the flow.
References
Paper: Crenshaw et. al. 2024 - https://ui.adsabs.harvard.edu/abs/2024AJ….168…80C
Zenodo: Crenshaw et. al. 2024 - https://doi.org/10.5281/zenodo.10710271