aztools.simlc

A module for simulating light curves.

Classes

SimLC

Class for simulating light curves

Module Contents

class SimLC(seed=None)[source]

Class for simulating light curves

builtin_models[source]
psd_models = [][source]
lag_models = [][source]
normalized_psd = None[source]
normalized_lag = None[source]
lcurve = None[source]
rng[source]
add_model(model: str | Callable, params: list | numpy.ndarray, clear: bool = True, lag: bool = False)[source]

Add a model to be used for generating the psd or lag.

This adds the model to self.psd_models or self.lag_models (if lag=True)

Parameters:

model: str or Callable

a callable method with model(freq, params), or a string from the builtin models

params: list or np.ndarray

model parameters

clear: bool

If True, clear all previously defined models

lag: bool

if True, this is a lag model, else it is a psd

calculate_model(freq: list | numpy.ndarray, lag: bool = False) numpy.ndarray[source]
Calculate the psd/lag model using the models

added with @add_model.

Parameters:
  • freq (np.ndarray) – frequency array.

  • lag (bool) – if True, calculate the lag model, else do the psd

Returns:

  • model (np.ndarray) – array of the same length as freq, containing the model

  • Note – the normalization of the returned psd/lag is taken from the input model parameters without any renormalization

simulate(npoints: int, deltat: float, lcmean: float, **kwargs)[source]
Simulate a light curve using the psd model stored in

self.psd_models

The normalized psd is stored in self.normalized_psd

Parameters:
  • npoints (int) – number of points in the light curve

  • deltat (float) – time sampling

  • lcmean (float) – the light curve mean

  • Keywords

  • --------

  • norm (str) – on of var|rms|leahy

simulate_pdf(npoints: int, deltat: float, lcmean: float, **kwargs)[source]

Simulate a light curve using the psd model enforcing some probability distribution

This uses the algorithm of Emmanoulopoulos+ (2013) MNRAS 433, 907–927

The normalized psd is stored in self.normalized_psd

Parameters:
  • npoints (int) – number of points in the light curve

  • deltat (float) – time sampling

  • lcmean (float) – the light curve mean

  • Keywords

  • --------

  • norm (str) – on of var|rms|leahy

  • pdf (scipy.stats._distn_infrastructure.rv_frozen) – The probability distribution object from scipy.stats that defines the desired pdf. e.g. scipy.stats.lognorm(s=0.5)

apply_lag(phase: bool = False)[source]

Apply lag in self.lag_models to the simulated light curve

  • This assumes self.simulate has been run.

  • Lag models are added by add_model(…, lag=True)

  • The resulting lag model is stored in self.normalized_lag

  • The generated lagged light curve is added self.lcurve

Parameters:

phase (bool) – If Trye, the lags in self.lag_models are in radians, otherwise they are in seconds.

static lag_array(xarr: numpy.ndarray, lag: numpy.ndarray | float, phase: bool = False, freq: numpy.ndarray | None = None) numpy.ndarray[source]

Shift the array xarr by a lag

Parameters:
  • xarr (np.ndarray) – light curve array to be shifted

  • lag (np.ndarray or float) – If array, it has length len(xarr)/2+1. If float, the lag is assumed constant with frequency

  • phase (bool) – if True, lag is in radians. Otherwise in seconds

  • freq (np.ndarray or None) – The frequency axis (used to convert lag to radians when phase is False)

Return type:

An array containing the shifted light curve.

static add_noise(xarr: numpy.ndarray, norm: float | None = None, seed: int | None = None, deltat: float = 1.0)[source]

Add noise to a lcurve xarr

Parameters:
  • xarray (np.ndarray) – Input light curve array

  • norm (float or None) – if None, add Poisson noise, else gaussian noise with std=norm.

  • seed (int or None) – Random seed

  • deltat (float) – used when norm is None. It gives the time samling of the light curve. Poisson noise is applied to the counts per bin. xarr in this case is the count rate. Counts/bin = Rate/sec * dt

Return type:

An array similar to xarr with noise added

static user_array(freq: numpy.ndarray, params: numpy.ndarray) numpy.ndarray[source]

Generate a model to be used as psd or lag.

The model is given by the user directly as an array params

Parameters:
  • freq (np.ndarray) – The frequency array

  • params (np.ndarray) – The model values

Return type:

An array of the model values at freq, containing the psd/lag model

static powerlaw(freq: numpy.ndarray, params: numpy.ndarray | list) numpy.ndarray[source]

Generate a powerlaw model to be used as psd or lag.

Parameters:
  • freq (np.ndarray) – The frequency array

  • params (np.ndarray or list) – Parameters of the model as: [norm, indx]

Return type:

An array of the model values at freq, containing the psd/lag model

static broken_powerlaw(freq: numpy.ndarray, params: numpy.ndarray | list) numpy.ndarray[source]

Generate a broken powerlaw model to be used as psd or lag.

Parameters:
  • freq (np.ndarray) – The frequency array

  • params (np.ndarray or list) – Parameters of the model as: [norm, indx1, indx2, break]

Return type:

An array of the model values at freq, containing the psd/lag model

static bending_powerlaw(freq: numpy.ndarray, params: numpy.ndarray | list) numpy.ndarray[source]

Generate a bending powerlaw model to be used as psd or lag.

Parameters:
  • freq (np.ndarray) – The frequency array

  • params (np.ndarray or list) – Parameters of the model as: [norm, index, break]). The index below the break is always 0.

Return type:

An array of the model values at freq, containing the psd/lag model

static lorentz(freq: numpy.ndarray, params: numpy.ndarray | list) numpy.ndarray[source]

Generate a lorentz model to be used as psd or lag.

Parameters:
  • freq (np.ndarray) – The frequency array

  • params (np.ndarray or list) – Parameters of the model as: [norm, fq_center, fq_sigma]

Return type:

An array of the model values at freq, containing the psd/lag model

static constant(freq: numpy.ndarray, params: numpy.ndarray | list) numpy.ndarray[source]

Generate a constant model to be used as psd or lag.

Parameters:
  • freq (np.ndarray) – The frequency array

  • params (np.ndarray or list) – Parameters of the model as [value]

Return type:

An array of the model values at freq, containing the psd/lag model