Coverage for src/galsbi/ucat/plugins/galaxy_mag_noise.py: 95%
21 statements
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-13 03:24 +0000
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-13 03:24 +0000
1# Copyright (C) 2019 ETH Zurich, Institute for Particle Physics and Astrophysics
3"""
4Created on Aug 2021
5author: Tomasz Kacprzak
6"""
8import numpy as np
9from cosmic_toolbox import logger
10from ivy.plugin.base_plugin import BasePlugin
12LOGGER = logger.get_logger(__file__)
13SEED_OFFSET_MAG_NOISE = 14301
16def mag_to_flux(mag):
17 return 10 ** ((mag + 48.6) / (-2.5))
20def flux_to_mag(flux):
21 return -2.5 * np.log10(flux) - 48.6
24class Plugin(BasePlugin):
25 def __call__(self):
26 par = self.ctx.parameters
28 np.random.seed(SEED_OFFSET_MAG_NOISE + par.seed)
30 if "galaxies" in self.ctx and par.noise_const_abs_mag is not None:
31 for band, mag in self.ctx.galaxies.abs_magnitude_dict.items():
32 flux_noisy = np.random.normal(
33 loc=mag_to_flux(mag),
34 scale=par.noise_const_abs_mag,
35 size=len(mag),
36 )
37 mag_noisy = flux_to_mag(flux_noisy)
38 mag_noisy[np.isnan(mag_noisy)] = np.inf
39 self.ctx.galaxies.abs_magnitude_dict[band] = mag_noisy
41 def __str__(self):
42 return "add noise to app_mags"