aztools

Top level methods and modules

Submodules

Classes

LCurve

Light curve class

SimLC

Class for simulating light curves

Package Contents

class LCurve(tarr: numpy.ndarray, rarr: numpy.ndarray, rerr: numpy.ndarray = None, **kwargs)[source]

Light curve class

time
rate
rerr
fexp
deltat
iseven
npoints
__repr__()[source]

LCurve as a str

make_even(fill: float = np.nan)[source]

Make the light curve even in time, filling gaps with fill

Parameters:

fill (float) – The value to use in gaps.

Return type:

a new LCurve object

rebin(factor: int, error: str = 'norm', min_exp: float = 0.0)[source]

Rebin the light curve to so new_deltat = deltat*factor

Parameters:
  • factor (int) – Rebinning factor. deltat_new = factor * deltat

  • error (str) – Error type (poiss|norm). If poiss: rerr = sqrt(rate*dt)/dt, otherwise, errors are summed quadratically

  • min_exp (float) – Minimum fractional exposure to leave [0-1]

  • Return – new binned LCurve

interp_small_gaps(maxgap: int = None, noise: str = 'poiss', seed: int = None)[source]
Interpolate small gaps in the lightcurve if the gap

is <maxgap; applying noise if requested

Parameters:
  • maxgap (int) – The maximum length of a gap to be interpolated.

  • noise (str:) – poiss|norm|None

  • seed (int) – Random seed if noise is requested

static calculate_psd(rate: list | numpy.ndarray, deltat: float, norm: str = 'var', **kwargs)[source]

Calculate raw psd from a list of light curves.

Parameters:
  • rate (np.ndarray or a list of np.ndarray) – An array or a list of arrays of lcurve rates

  • deltat (float) – Time bin width of the light curve(s).

  • norm (str) – Psd normalization: var|rms|leahy

  • Keywords

  • --------

  • rerr (np.ndarray or a list of np.ndarray) – The measurement error arrays that corresponds to rate. If not given, assume, poisson noise.

  • bgd (np.ndarray or a list of np.ndarray.) – The background rate arrays that corresponds to source rate. In this case, rate above is assumed background subtracted.

  • taper (bool) – Apply Hanning tapering before calculating the psd see p388 Bendat & Piersol; the psd needs to be multiplied by 8/3 to componsate for the reduced variance.

Return type:

freq, rpsd, nois.

static bin_psd(freq: numpy.ndarray, rpsd: numpy.ndarray, fqbin: dict, noise: bool = None, logavg: bool = True)[source]

Bin power spectrum.

Parameters:
  • freq (np.ndarray) – Array of raw frequencies.

  • rpsd (np.ndarray) – Array of raw powers.

  • fqbin (dict) – Binning dict to be passed to @misc.group_array to bin the frequency axis.

  • noise (bool) – Array of noise values or None.

  • logavg (bool) – Do averaging in log-space, and correct for bias. Otherwise it is linear averaging.

Return type:

freq, psd, psde, desc::dict having some useful info

static calculate_lag(xarr: numpy.ndarray | list, yarr: numpy.ndarray | list, deltat: float, fqbin: dict = None, **kwargs)[source]

Calculate and bin lags from two lists of light curves.

Parameters:
  • xarr (np.ndarray or list) – Array or list of arrays of light curve rates.

  • yarr (np.ndarray or list) – Array or list of arrays of reference light curve rates.

  • deltat (float) – Time bin width of the light curve.

  • fqbin (dict) – Binning dict to be passed to @misc.group_array to bin the frequency axis. If None, return raw lag

  • Keywords

  • --------

  • xerr (np.ndarray or a list of np.ndarray) – The measurement error arrays that corresponds to rate. If not given, assume, poisson noise.

  • xbgd (np.ndarray or a list of np.ndarray.) – The background rate arrays that corresponds to source rate. In this case, rate above is assumed background subtracted.

  • yerr (np.ndarray or a list of np.ndarray) – The measurement error arrays that corresponds to yarr. If not given, assume, poisson noise.

  • ybgd (np.ndarray or a list of np.ndarray.) – The background rate arrays that corresponds to ref_rate. In this case, yarr above is assumed background subtracted.

  • phase (bool) – return phase lag instead of time lag

  • taper (bool) – Apply Hanning tapering before calculating the fft see p388 Bendat & Piersol; the fft need to be multiplied by sqrt(8/3) to componsate for the reduced variance. Default: False

  • norm (str) – How to normalize the fft during the calculations. None|rms|leahy|var. Default is None, so the calculations is done with raw numpy fft

Returns:

  • freq, lag, lage, extra

  • extra = {‘fqm’, ‘fql’, ‘xlimit’, ‘ylimit’ ..}

static read_pn_lcurve(fits_file, **kwargs)[source]
Read pn lcurve fits file.

This sets values relevant to PN and calls @misc.read_fits_lcurve

Parameters:
  • fits_file (str) – The name of the files file

  • Keywords

  • --------

  • @misc.read_fits_lcurve (See)

Return type:

LCurve object

static read_pca_lcurve(fits_file, **kwargs)[source]
Read pca lcurve fits file.

This sets values relevant to PCA and calls @misc.read_fits_lcurve

Parameters:
  • fits_file (str) – The name of the files file

  • Keywords

  • --------

  • @misc.read_fits_lcurve (See)

Return type:

LCurve object

static read_nu_lcurve(fits_file, **kwargs)[source]
Read nustar lcurve fits file.

This sets values relevant to NUSTAR and calls @misc.read_fits_lcurve

Parameters:
  • fits_file (str) – The name of the files file.

  • Keywords

  • --------

  • @misc.read_fits_lcurve (See)

Return type:

LCurve object

static read_xis_lcurve(fits_file, **kwargs)[source]
Read suzaku xis lcurve fits file.

This sets values relevant to Suzaku XIS and calls @misc.read_fits_lcurve

Parameters:
  • fits_file (str) – The name of the files file.

  • Keywords

  • --------

  • @misc.read_fits_lcurve (See)

Return type:

LCurve object

static read_ni_lcurve(fits_file, **kwargs)[source]
Read nicer lcurve fits file.

This sets values relevant to NICER and calls @misc.read_fits_lcurve

Parameters:
  • fits_file (str) – The name of the files file.

  • Keywords

  • @misc.read_fits_lcurve (See)

Returns:

LCurve object

class SimLC(seed=None)[source]

Class for simulating light curves

builtin_models
psd_models = []
lag_models = []
normalized_psd = None
normalized_lag = None
lcurve = None
rng
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