MicroLIA_Sim.variable_stars

Functions

calc_intensity_mean_mag(→ float)

Calculate the intensity-averaged mean magnitude. Input mags must be finite (no NaNs or infs).

load_rr_template_txt(→ Dict[str, Dict[str, numpy.ndarray]])

Load a single multiband RR Lyrae template from a .txt file.

pick_random_template_path(→ pathlib.Path)

Pick a random template file.

_interp_periodic(→ numpy.ndarray)

Linearly interpolate a phased template onto query phases, treating phase as periodic.

simulate_rrlyrae_multiband_from_txt(→ Dict[str, ...)

Simulate multiband RR Lyrae light curves using a single template .txt file.

simulate_rrlyae(times, bailey, period, reference_band, ...)

Generate multiband RR Lyrae (or Cepheid-like) light curves by sampling a

Module Contents

MicroLIA_Sim.variable_stars.calc_intensity_mean_mag(mags: numpy.ndarray) float[source]

Calculate the intensity-averaged mean magnitude. Input mags must be finite (no NaNs or infs).

Parameters:

mags (numpy.ndarray) – 1D array of magnitudes.

Returns:

Intensity-mean magnitude.

Return type:

float

MicroLIA_Sim.variable_stars.load_rr_template_txt(path: str | pathlib.Path) Dict[str, Dict[str, numpy.ndarray]][source]

Load a single multiband RR Lyrae template from a .txt file.

The file is expected to have a header ‘Mag,Phase,Band’ and rows like: Mag,Phase,Band 17.30,0.000,g 17.31,0.001,g 15.24,0.001,r 17.65,0.001,g …

Parameters:

path (str or Path) – Path to the template .txt file.

Returns:

Dictionary with keys: - ‘phase’: mapping band -> phase array (float) - ‘mag’: mapping band -> magnitude array (float) - ‘bands’: list of available band names.

Return type:

dict

MicroLIA_Sim.variable_stars.pick_random_template_path(root_dir: str | pathlib.Path, rr_type: str = 'RRab', rng: numpy.random.Generator | None = None) pathlib.Path[source]

Pick a random template file.

Parameters:
  • root_dir (str or Path) – Root directory where the templates live.

  • rr_type ({'RRab', 'RRc'}) – Type of RR Lyrae to draw.

  • rng (numpy.random.Generator, optional) – RNG instance. If None, a default generator is used.

Returns:

Path to a randomly selected .txt template.

Return type:

Path

MicroLIA_Sim.variable_stars._interp_periodic(phase_templ: numpy.ndarray, mag_templ: numpy.ndarray, phase_query: numpy.ndarray) numpy.ndarray[source]

Linearly interpolate a phased template onto query phases, treating phase as periodic.

Parameters:
  • phase_templ (ndarray) – 1D array of template phases.

  • mag_templ (ndarray) – 1D array of template magnitudes evaluated at phase_templ. Must have the same shape as phase_templ.

  • phase_query (ndarray) – 1D array of phases at which to evaluate the template. Values may be outside [0, 1) as they are wrapped into [0, 1).

Returns:

Interpolated magnitudes evaluated at phase_query (wrapped to [0, 1)). Shape matches phase_query.

Return type:

ndarray

MicroLIA_Sim.variable_stars.simulate_rrlyrae_multiband_from_txt(times_by_band: Mapping[str, numpy.ndarray], period: float, template_path: str | pathlib.Path, reference_band: str = 'r', reference_mean_mag: float | None = None, T0: float | None = None, amplitude_jitter: float = 0.15, rng: numpy.random.Generator | None = None) Dict[str, numpy.ndarray][source]

Simulate multiband RR Lyrae light curves using a single template .txt file.

Parameters:
  • times_by_band (mapping) – Mapping from band name to 1D array of observation times (e.g.,{‘g’: mjd_g, ‘r’: mjd_r, ‘i’: mjd_i}

  • period (float) – RR Lyrae period in days.

  • template_path (str or Path) – Path to the chosen template .txt file.

  • reference_band (str, optional) – Band used to anchor the baseline magnitude.

  • reference_mean_mag (float, optional) – Desired mean magnitude in the reference band. If None, the template’s native magnitudes are used.

  • T0 (float, optional) – Epoch corresponding to phase = 0 (in same units as times_by_band). If None, a random T0 is drawn uniformly in [0, period).

  • amplitude_jitter (float, optional) – Fractional scale to randomly stretch/compress the amplitude. Defaults to 0.15 (+/- 15%). Set to 0.0 for no jitter.

  • rng (numpy.random.Generator, optional) – RNG used when drawing random T0 and jitter. Ignored if T0 is provided.

Returns:

Dictionary mapping band -> simulated magnitudes array. Keys match those in the times_by_band argument.

Return type:

dict

MicroLIA_Sim.variable_stars.simulate_rrlyae(times, bailey, period, reference_band, reference_mean_mag, amplitude_jitter=0.15, rng=None)[source]

Generate multiband RR Lyrae (or Cepheid-like) light curves by sampling a template and phase-folding it onto the provided cadence. RRLyrae templates are from Baeza-Villagra et al. (2025). It randomly selects a template file from the package data directory and interpolates the template magnitudes at the phase-folded observation times. It then applies a single magnitude offset so the reference band has the desired mean magnitude.

If period is None, it draws a period from a simple distribution based on the Bailey type (bailey):
  • 1 -> RRab : Normal(0.6, 0.15) days

  • 2 -> RRc : Normal(0.33, 0.10) days

  • 3 -> Cepheid-like : 10**LogNormal(0.0, 0.2) days

Parameters:
  • times (Mapping[str, array_like]) – Mapping from band name to 1D array of observation times, e.g. {‘g’: t_g, ‘r’: t_r, ‘i’: t_i}. Times must be in days.

  • bailey (int) – Variability class selector. Expected values: 1 (RRab), 2 (RRc), 3 (Cepheid-like).

  • period (float or None) – Period in days. If None, a period is drawn based on bailey.

  • reference_band (str) – Band used to anchor the mean magnitude (passed through to the underlying simulator).

  • reference_mean_mag (float) – Desired mean magnitude in reference_band (passed through to the underlying simulator).

  • amplitude_jitter (float, optional) – Fractional scale to randomly stretch/compress the amplitude. Defaults to 0.15 (+/- 15%). Set to 0.0 for no jitter.

  • rng (numpy.random.Generator, optional) – RNG used when drawing random T0. Ignored if T0 is provided.

Returns:

Dictionary mapping each input band name to an array of simulated magnitudes evaluated at times[band].

Return type:

dict