MicroLIA_Sim.variable_stars =========================== .. py:module:: MicroLIA_Sim.variable_stars Functions --------- .. autoapisummary:: MicroLIA_Sim.variable_stars.calc_intensity_mean_mag MicroLIA_Sim.variable_stars.load_rr_template_txt MicroLIA_Sim.variable_stars.pick_random_template_path MicroLIA_Sim.variable_stars._interp_periodic MicroLIA_Sim.variable_stars.simulate_rrlyrae_multiband_from_txt MicroLIA_Sim.variable_stars.simulate_rrlyae Module Contents --------------- .. py:function:: calc_intensity_mean_mag(mags: numpy.ndarray) -> float Calculate the intensity-averaged mean magnitude. Input mags must be finite (no NaNs or infs). :param mags: 1D array of magnitudes. :type mags: numpy.ndarray :returns: Intensity-mean magnitude. :rtype: float .. py:function:: load_rr_template_txt(path: str | pathlib.Path) -> Dict[str, Dict[str, numpy.ndarray]] 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 ... :param path: Path to the template .txt file. :type path: str or Path :returns: Dictionary with keys: - 'phase': mapping band -> phase array (float) - 'mag': mapping band -> magnitude array (float) - 'bands': list of available band names. :rtype: dict .. py:function:: pick_random_template_path(root_dir: str | pathlib.Path, rr_type: str = 'RRab', rng: Optional[numpy.random.Generator] = None) -> pathlib.Path Pick a random template file. :param root_dir: Root directory where the templates live. :type root_dir: str or Path :param rr_type: Type of RR Lyrae to draw. :type rr_type: {'RRab', 'RRc'} :param rng: RNG instance. If None, a default generator is used. :type rng: numpy.random.Generator, optional :returns: Path to a randomly selected .txt template. :rtype: Path .. py:function:: _interp_periodic(phase_templ: numpy.ndarray, mag_templ: numpy.ndarray, phase_query: numpy.ndarray) -> numpy.ndarray Linearly interpolate a phased template onto query phases, treating phase as periodic. :param phase_templ: 1D array of template phases. :type phase_templ: ndarray :param mag_templ: 1D array of template magnitudes evaluated at `phase_templ`. Must have the same shape as `phase_templ`. :type mag_templ: ndarray :param phase_query: 1D array of phases at which to evaluate the template. Values may be outside [0, 1) as they are wrapped into [0, 1). :type phase_query: ndarray :returns: Interpolated magnitudes evaluated at `phase_query` (wrapped to [0, 1)). Shape matches `phase_query`. :rtype: ndarray .. py:function:: 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: Optional[float] = None, T0: Optional[float] = None, amplitude_jitter: float = 0.15, rng: Optional[numpy.random.Generator] = None) -> Dict[str, numpy.ndarray] Simulate multiband RR Lyrae light curves using a single template .txt file. :param times_by_band: Mapping from band name to 1D array of observation times (e.g.,{'g': mjd_g, 'r': mjd_r, 'i': mjd_i} :type times_by_band: mapping :param period: RR Lyrae period in days. :type period: float :param template_path: Path to the chosen template .txt file. :type template_path: str or Path :param reference_band: Band used to anchor the baseline magnitude. :type reference_band: str, optional :param reference_mean_mag: Desired mean magnitude in the reference band. If None, the template's native magnitudes are used. :type reference_mean_mag: float, optional :param T0: Epoch corresponding to phase = 0 (in same units as `times_by_band`). If None, a random T0 is drawn uniformly in [0, period). :type T0: float, optional :param amplitude_jitter: Fractional scale to randomly stretch/compress the amplitude. Defaults to 0.15 (+/- 15%). Set to 0.0 for no jitter. :type amplitude_jitter: float, optional :param rng: RNG used when drawing random T0 and jitter. Ignored if T0 is provided. :type rng: numpy.random.Generator, optional :returns: Dictionary mapping band -> simulated magnitudes array. Keys match those in the `times_by_band` argument. :rtype: dict .. py:function:: simulate_rrlyae(times, bailey, period, reference_band, reference_mean_mag, amplitude_jitter=0.15, rng=None) 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 :param times: 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. :type times: Mapping[str, array_like] :param bailey: Variability class selector. Expected values: 1 (RRab), 2 (RRc), 3 (Cepheid-like). :type bailey: int :param period: Period in days. If None, a period is drawn based on `bailey`. :type period: float or None :param reference_band: Band used to anchor the mean magnitude (passed through to the underlying simulator). :type reference_band: str :param reference_mean_mag: Desired mean magnitude in `reference_band` (passed through to the underlying simulator). :type reference_mean_mag: float :param amplitude_jitter: Fractional scale to randomly stretch/compress the amplitude. Defaults to 0.15 (+/- 15%). Set to 0.0 for no jitter. :type amplitude_jitter: float, optional :param rng: RNG used when drawing random T0. Ignored if T0 is provided. :type rng: numpy.random.Generator, optional :returns: Dictionary mapping each input band name to an array of simulated magnitudes evaluated at `times[band]`. :rtype: dict