synference.noise_models

Noise models for simulating photometric fluxes and uncertainties.

This module provides a robust and serializable framework for creating and applying various photometric noise models.

Functions

synference.noise_models.create_uncertainty_models_from_EPOCHS_cat(file, bands, new_band_names=None, plot=False, old=False, hdu=0, save=False, save_path=None, model_class='general', **kwargs)[source]

Create uncertainty models from an EPOCHS catalog file.

Parameters:
  • file (str) – Path to the EPOCHS catalog file.

  • bands (str or list of str) – Band(s) to create uncertainty models for. If a string is provided, it will be converted to a list.

  • new_band_names (list of str, optional) – New names for the bands in the uncertainty models. If not provided, the original band names will be used.

  • plot (bool, optional) – Whether to plot the uncertainty models. Default is False.

  • old (bool, optional) – If True, assumes the catalog is in the old format (without aperture corrections). Default is False.

  • hdu (int, optional) – The HDU number to read from the FITS file. Default is 0.

  • save_path (str, optional) – Path to save the plots if plot is True. If None, plots are not saved.

  • **kwargs (dict, optional) – Additional keyword arguments to pass to the EmpiricalUncertaintyModel.

  • Returns

  • -------

  • dict – A dictionary of EmpiricalUncertaintyModel objects for each band.

synference.noise_models.load_unc_model_from_hdf5(filepath, group_name='all')[source]

Factory function to load any supported model from an HDF5 file.

Return type:

UncertaintyModel

synference.noise_models.save_unc_model_to_hdf5(model, filepath, group_name, overwrite=False)[source]

Saves a supported uncertainty model to an HDF5 file.

Classes

class synference.noise_models.AsinhEmpiricalUncertaintyModel(observed_phot_jy=None, observed_phot_errors_jy=None, asinh_b_factor=5.0, error_type='empirical', min_flux_error=None, max_flux_error=None, interpolation_flux_unit='asinh', **kwargs)[source]

An empirical model for uncertainties in asinh magnitude space.

apply_noise(flux, true_flux_units=None, **kwargs)[source]

Applies noise to a flux, which is assumed to be in Jy or convertible.

Return type:

Union[ndarray, Tuple[ndarray, ndarray]]

apply_scalings(flux, error, **kwargs)[source]

Converts flux and error from Jy to asinh magnitudes.

Return type:

Tuple[ndarray, ndarray]

serialize_to_hdf5(hdf5_group)[source]

Saves the asinh model, including its unique attributes.

class synference.noise_models.DepthUncertaintyModel(depth_ab, depth_sigma_level=5.0, min_flux_error=None, max_flux_error=None, **kwargs)[source]

Applies Gaussian noise based on a fixed survey depth.

apply_noise(flux, true_flux_units=None, out_units=None, **kwargs)[source]

Applies Gaussian noise to the input flux.

Return type:

Union[unyt_array, Tuple[unyt_array, unyt_array]]

apply_scalings(flux, error, flux_units, out_units)[source]

Applies only unit conversions, as this model has no other scalings.

Return type:

Tuple[ndarray, ndarray]

serialize_to_hdf5(hdf5_group)[source]

Serializes the model to an HDF5 group.

class synference.noise_models.EmpiricalUncertaintyModel(extrapolate=False, min_samples_per_bin=10, num_bins=20, log_bins=True, **kwargs)[source]

Abstract base for empirical uncertainty models from observed data.

plot(ax=None)[source]

Plots the binned median error and standard deviation.

sample_uncertainty(flux_values)[source]

Samples an uncertainty from the learned distribution p(sigma|f).

Return type:

ndarray

serialize_to_hdf5(hdf5_group)[source]

Serializes the common state of an empirical model.

class synference.noise_models.GeneralEmpiricalUncertaintyModel(observed_fluxes, observed_errors, flux_unit='AB', interpolation_flux_unit=None, already_binned=False, bin_median_errors=None, bin_std_errors=None, flux_bins=None, min_flux_for_binning=None, sigma_clip=None, min_flux_error=0.0, max_flux_error=inf, error_type='empirical', upper_limits=False, treat_as_upper_limits_below=None, upper_limit_flux_behaviour='scatter_limit', upper_limit_flux_err_behaviour='flux', **kwargs)[source]

General empirical uncertainty model for photometric fluxes.

apply_noise(flux, true_flux_units=None, out_units=None)[source]

Applies configured noise and upper limit rules to true flux values.

Return type:

Tuple[ndarray, ndarray]

apply_scalings(flux, error, flux_units, out_units)[source]

Applies deterministic model transformations (units, SNR cuts).

Return type:

Tuple[ndarray, ndarray]

serialize_to_hdf5(hdf5_group)[source]

Serializes the model’s state into the given HDF5 group.

class synference.noise_models.SpectralUncertaintyModel(error_kernel, **kwargs)[source]

Applies uncertanties to a spectrum based on a fixed error kernel or a provided table.

apply_noise(flux, **kwargs)[source]

Applies Gaussian noise to the input flux based on the error kernel.

Return type:

Union[ndarray, Tuple[ndarray, ndarray]]

serialize_to_hdf5(hdf5_group)[source]

Serializes the model to an HDF5 group.

class synference.noise_models.UncertaintyModel(return_noise=False, **kwargs)[source]

Abstract base class for photometric noise models.

This class defines the common interface and provides static helper methods for photometric unit conversions. It is not meant to be instantiated directly.

static ab_err_to_jy(magnitude_err, flux_jy)[source]

Converts AB magnitude uncertainty to flux uncertainty in Janskys.

Return type:

unyt_array

static ab_to_jy(magnitude)[source]

Converts AB magnitude to flux density in Janskys.

Return type:

unyt_array

abstract apply_noise(flux)[source]

Applies noise to the input flux.

Return type:

Union[ndarray, unyt_array, Tuple[ndarray | unyt_array, ndarray | unyt_array]]

static jy_err_to_ab(flux_err_jy, flux_jy)[source]

Converts flux uncertainty in Janskys to AB magnitude uncertainty.

Return type:

ndarray

static jy_to_ab(flux)[source]

Converts flux density in Janskys to AB magnitude.

Return type:

ndarray

abstract serialize_to_hdf5(hdf5_group)[source]

Serializes the model’s state into the given HDF5 group.