Prot

Prot#

This is the API for the Prot module.

Module for calculating stellar rotation periods from photometric data.

class coPsi.Prot.Rotator(file=None, x=array([], dtype=float64), y=array([], dtype=float64), xg=array([], dtype=float64), yg=array([], dtype=float64), dy=None, cadence=None)#

Rotation from light curve

This class inherits from coPsi.Data() and is initialized in the same way.

ACF(lags=array([], dtype=float64), maxT=None, **kwargs)#

Autocorrelation function

Use the ACF to find rotation period as in McQuillan et al. (2013).

Calculated using statsmodels.api.tsa.acf().

Parameters:
  • lags (array) – Lags for which to calculate ACF. Optional, default numpy.array([]).

  • maxT (float) – Maximum length of uninterrupted observations in timeseries. Default None, will use the maximum time in the timeseries.

fitProt(p0=[], noise=0.2, maxT=None, print_pars=True)#

Fit rotation period.

This function will fit a Gaussian to the periodogram to find the rotation period. Good guesses for the location helps.

Parameters:
  • p0 (list) – Starting guesses for amplitude,location, and width ([\(A\), \(\mu\), \(\sigma\)] in gauss). Optional, default []. If empty will try to find where the maximum is.

  • noise (float) – Value in time (days/lags) under which to consider noise. Will search for peaks above noise for p0. Optional, default 0.2. Set to None to not consider noise.

  • maxT – Maximum time (days/lags) to consider. Optional, default None, will use the maximum time in the timeseries.

  • print_pars (bool) – Whether to print the parameters from the fit. Optional, default True.

fromPeaks(peaks=None, prominence=(0.3, 1.1), maxpeaks=10, poly=False, plot=True, print_pars=True, font=12, usetex=False, xmin=None, xmax=None, ymax=0.75, **kwargs)#

Rotation period from ACF peaks

Find peaks in ACF using scipy.signal.find_peaks().

Either following to McQuillan et al. (2013) or Hjorth et al. (2021).

Parameters:
  • peaks (array) – Peaks in the ACF, if already identified (e.g. using pickPeaks()). Optional, default None.

  • prominence (tuple) – The prominence of the peaks. Optional, default (0.3,1.1). See scipy.signal.find_peaks().

  • maxpeaks (int) – Maximum number of peaks to consider. Optional, default 10, see McQuillan et al. (2013).

  • poly (bool) – If True peaks are found from linear fit (Hjorth et al., 2021), else from median of differences (McQuillan et al., 2013). Optional, default False.

  • plot (bool) – Whether to plot ACF with peaks. Optional, default True.

  • print_pars (bool) – Whether to print the parameters from the fit. Optional, default True.

  • font (float) – Fontsize for labels. Optional, default 12.

  • usetex (bool) – Whether to use LaTeX in plots. Optional, default False.

  • xmin (float) – Minimum for x-axis. Optional, default None, will be set to minimum of ACF.

  • xmax (float) – Maximum for x-axis. Optional, default None, will be set to maximum of ACF.

  • ymax (float) – Maximum value for y-axis. Optional, default 0.75.

Params kwargs:

Extra keywords are sent to scipy.signal.find_peaks().

gauss(x, a, x0, sigma)#

Gaussian

\[f (x) = \frac{A}{\sqrt{2 \pi}\sigma} \exp \left (-\frac{(x - \mu)^2}{2 \sigma^2} \right) \, .\]
Parameters:
  • x (float, array) – \(x\).

  • x0 (float) – \(\mu\).

  • sigma (float) – \(\sigma\).

  • a (float) – \(A\).

Returns:

\(f(x)\)

Return type:

float

getProt(prep=True, timeWindow=8001, timePoly=3, gap=0.5, yfill=None, cadence=None, smooth=True, freqWindow=401, freqPoly=3)#

Get rotation period.

Collection of calls to coPsi.Phot.Data.prepData(), ACF(), smoothACF(), periodogram(), and fitProt().

Parameters:
periodogram(samples_per_peak=15, maxT=None, **kwargs)#

Periodogram

Calculated using astropy.timeseries.LombScargle().

Parameters:

samples_per_peak (int) – Number of samples (resolution). Optional, default 15.

pickPeaks(closest='x', font=12, ymax=0.75, xmin=None, xmax=None, usetex=False)#

Pick peaks in ACF

Plot ACF and pick peaks using mouse clicks. Left click to add peak, middle click to clear all peaks, right click to remove erroneous peak.

The selected peaks are stored in peaks.

Parameters:
  • closest (bool) – Whether to pick the closest peak to the click. Optional, default ‘x’. Can be ‘xy’ or ‘x’. If ‘xy’ will pick the peak closest in both x and y relative to the scale, if ‘x’ will pick the peak closest in x. If anything else it will pick the location of the click event.

  • font (float) – Fontsize for labels. Optional, default 12.

  • ymax (float) – Maximum value for y-axis. Optional, default 0.7.

  • xmin (float) – Minimum for x-axis. Optional, default None, will be set to minimum of ACF.

  • xmax (float) – Maximum for x-axis. Optional, default None, will be set to maximum of ACF.

  • usetex (bool) – Whether to use LaTeX in plots. Optional, default False.

plotACF(ax=None, font=12, ymax=0.75, xmin=None, xmax=None, usetex=False, return_ax=0, peaks=array([], dtype=float64))#

Plot the periodogram

Parameters:
  • ax (matplotlib.axes._subplots.AxesSubplot) – Axis in which to plot the KDE. Optional, default None, figure and axis will be created.

  • ymax (float) – Maximum value for y-axis. Optional, default 0.7.

  • xmin (float) – Minimum for x-axis. Optional, default None, will be set to minimum of ACF.

  • xmax (float) – Maximum for x-axis. Optional, default None, will be set to maximum of ACF.

  • font (float) – Fontsize for labels. Optional, default 12.

  • usetex (bool) – Whether to use LaTeX in plots. Optional, default False.

  • return_ax (bool) – Whether to return ax. Optional, default 0.

  • peaks (array) – Peaks in the ACF. Optional, default empty.

plotCycles(cmap='copper', per=None, maxT=None, cadence=0.125, bincadence=0.25)#

Plot cycles

Plot cycles in the light curve.

plotPeriodogram(ax=None, xmin=None, xmax=None, ymin=None, ymax=None, font=12, usetex=False)#

Plot the periodogram

Parameters:
  • ax (matplotlib.axes._subplots.AxesSubplot) – Axis in which to plot the KDE. Optional, default None, figure and axis will be created.

  • xmin (float) – Minimum time for axis. Optional, default None, will be set to minimum time in the timeseries.

  • xmax (float) – Maximum time for axis. Optional, default None, will be set to maximum time in the timeseries.

  • ymin (float) – Minimum value for y-axis. Optional, default None.

  • ymax (float) – Maximum time for y-axis. Optional, default None.

  • font (float) – Fontsize for labels. Optional, default 12.

  • usetex (bool) – Whether to use LaTeX in plots. Optional, default False.

slidePeriod(x, y, per=5.0, maxp=1.0, minp=1.0, sc=True)#

Period slider

Slider to evince the period that minimizes the phase dispersion.

Note

  • It’s a good idea to bin the data before using this function, especially for long/high cadence timeseries.

  • Needs to return the figure according to matplotlib/matplotlib#

Parameters:
  • x (array) – Time.

  • y (array) – Flux.

  • per (float) – Starting period. Optional, default 5.

  • maxp (float) – Maximum period. Optional, default per+1.

  • minp (float) – Minimum period. Optional, default per-1.

  • sc (bool) – Whether to use scatter plot instead of lines. Optional, default True.

smoothACF(window=401, poly=3)#

Smooth ACF

Smoothes the ACF using a Savitsky-Golay filter from scipy.signal.savgol_filter().

Parameters:
  • window (int) – Length of window for filter. Optional, default 401.

  • poly (int) – Degree for polynomial. Optional, default 3.

smoothPeriodogram(width=10, **kwargs)#

Smooth periodogram

Smooths the periodogram using a boxcar filter from astropy.convolution.Box1DKernel().

Parameters:

width (int) – Width of filter. Optional, default 10.