leavitt package¶
Submodules¶
leavitt.psearch_py3 module¶
- leavitt.psearch_py3.ctheta_slave_py(parray, mag, tobs, version=2)¶
- NAME:
ctheta_slave_py
- INPUTS:
parray mag tobs (version)
- OUTPUTS:
theta
- DESCRIPTION:
Computes theta for a pre-specified array of test periods.
- ORIGINAL IDL DEFINITION:
pro Ctheta_slave, parray, mag, tobs, theta
- leavitt.psearch_py3.ctheta_slave_v3_py(parray, mag, tobs)¶
- NAME:
ctheta_slave_v3_py
- INPUTS:
parray mag tobs
- OUTPUTS:
theta
- DESCRIPTION:
Computes theta for a pre-specified array of test periods.
- ORIGINAL IDL DEFINITION:
pro Ctheta_slave, parray, mag, tobs, theta
- leavitt.psearch_py3.ctheta_slave_v3_pyjit(parray, mag, tobs)¶
- NAME:
ctheta_slave_v3_py
- INPUTS:
parray mag tobs
- OUTPUTS:
theta
- DESCRIPTION:
Computes theta for a pre-specified array of test periods.
- ORIGINAL IDL DEFINITION:
pro Ctheta_slave, parray, mag, tobs, theta
- leavitt.psearch_py3.do_stats(x, tag=None)¶
- leavitt.psearch_py3.fig_obs_kjm_py(hjd=None, mag=None, filts=None, filtnams=None, tag=None, plotfile=None, xlim=None)¶
- NAME:
fig_obs_kjm_py
- INPUTS:
hjd: time (Heliocentric Julian Day) input data array mag: magnitude input data array (co-alligned with hjd) filts: filter input data array (co-aligned with hjd) with
integer identifier indicating passband
- filtnams = string array containing character names corresponding to
coded filts values. E.g., if you have 5 bands labeled u,g,r,i,z with filts values 0,1,2,3,4 respectively, filtnams would be set by: filtnams = [‘u’, ‘g’, ‘r’, ‘i’, ‘z’]
tag: String written in the bottom-left corner (if any) plotfile: filename of the output plot (if any) xlim: user-defined limits of the x-axis (if any)
- leavitt.psearch_py3.fig_phi_kjm_py(hjd=None, mag=None, magerr=None, filts=None, filtnams=None, period=None, tag=None, plotfile=None)¶
- NAME:
fig_phi_kjm_py
- INPUTS:
hjd: time (Heliocentric Julian Day) input data array mag: magnitude input data array (co-alligned with hjd) magerr: magnitude error input data array (co-alligned with hjd) filts: filter input data array (co-aligned with hjd) with
integer identifier indicating passband
- filtnams = string array containing character names corresponding to
coded filts values. E.g., if you have 5 bands labeled u,g,r,i,z with filts values 0,1,2,3,4 respectively, filtnams would be set by: filtnams = [‘u’, ‘g’, ‘r’, ‘i’, ‘z’]
period: period to be used to phase up the data [days] tag: String written in the bottom-left corner (if any) plotfile: filename of the output plot (if any)
- leavitt.psearch_py3.fig_psi_kjm_py(freq=None, psi_m=None, thresh_m=None, filtnams=None, tag=None, plotfile=None, ylim=None, verbose=False)¶
- NAME:
fig_psi_kjm_py
- INPUTS:
- freq: 1-D array (length of N) frequencies for which the periodograms are
computed. It is the same for ALL bands/channels.
- psi_m: M x N array of the Psi periodogram, where M is the number of
bands/channels in the input array filtnams
- thresh_m: M x N array containing threshold values of Psi at each period
and band for assessing significance for psi_m
- filtnams = string array (length of M) containing character names
corresponding to coded filts values. E.g., 5 bands labeled u,g,r,i,z with filts values: filtnams = [‘u’, ‘g’, ‘r’, ‘i’, ‘z’]
tag: String written in the bottom-left corner (if any) plotfile: filename of the output plot (if any) ylim: user-defined limits of the y-axis (if any) verbose: show frequency/period table (default=False)
- leavitt.psearch_py3.main()¶
- leavitt.psearch_py3.periodpsi2_py(hjd, mag, magerr, filts, minper, dphi, fwant, n_thresh=1, maxper=None, periods=None, verbose=False)¶
- NAME:
periodpsi2_py
- INPUTS:
hjd: time (Heliocentric Julian Day) input data array mag: magnitude input data array (co-alligned with hjd) magerr: magnitude error input data array (co-alligned with hjd) filts: filter input data array (co-aligned with hjd) with
integer identifier indicating passband
minper: minimum period to explore dphi: maximum phase change between any two data points resulting from
one step in frequency or period
- fwant: integer value corresponding to desired passband from among values
in filts array.
n_thresh: Number of simulated error runs (default=1,min=0) maxper: maximum period to explore (default=None) periods: array of periods to explore (default=None) verbose: want verbose information? (default=False)
- OUTPUTS:
x: period array for which periodograms are computed fy: Lomb-Scargle periodogram (co-aligned with x) theta: Lafler-Kinman periodogram (co-aligned with x) psi: psi periodogram (co-aligned with x) conf: simulated PSI periodogram for a non-periodic variable with
amplitude and noise mimicking real source PLUS of an unvarying object with noise mimicking
- ORIGINAL IDL DEFINITION:
- pro periodpsi2, HJD, MAG, MAGERR, FILTS, minper, dphi, fwant, x, fy, $
theta, psi, conf
- leavitt.psearch_py3.plot_absdiff_py(fy0_p, fy1_p, title_p)¶
- leavitt.psearch_py3.psearch_py(hjd, mag, magerr, filts, filtnams, pmin, dphi, n_thresh=1, pmax=None, periods=None, verbose=False)¶
- NAME:
psearch_py
- INPUTS:
hjd: time (Heliocentric Julian Day) input data array mag: magnitude input data array (co-alligned with hjd) magerr: magnitude error input data array (co-alligned with hjd) filts: filter input data array (co-aligned with hjd) with
integer identifier indicating passband
- filtnams = string array containing character names corresponding to
coded filts values. E.g., if you have 5 bands labeled u,g,r,i,z with filts values 0,1,2,3,4 respectively, filtnams would be set by: filtnams = [‘u’, ‘g’, ‘r’, ‘i’, ‘z’]
- pmin: Minimum value of period to be tested.
E.g., pmin = 0.2
- dphi: Maximum change in relative phase between first and last epoch to
be permitted when stepping to next test period. E.g., dphi = 0.02
n_thresh: Number of simulated error runs (default=1,min=0) pmax: maximum period to explore (default=None) periods: array of periods to explore (default=None) verbose: want verbose information? (default=False)
- OUTPUTS:
- ptest: 1-D array with N dimensions of periods for which the periodograms
are computed. It is the same for ALL bands/channels.
- psi_m: M x N array of the Psi periodogram, where M is the number of
bands/channels in the input array filtnams N.B. if only one filter is used,
psi_m is a 1d array (vector) of N elements
- thresh_m: M x N array containing threshold values of Psi at each period
- and band for assessing significance for psi_m
- N.B. if only one filter is used,
thresh_m is a 1d array (vector) of N elements
- ORIGINAL IDL DEFINITION:
- pro Psearch, hjd, mag, magerr, filts, filtnams, pmin, dphi, ptest, $
psi_m, thresh_m
- leavitt.psearch_py3.reference()¶
- leavitt.psearch_py3.scargle_fast_py(t, c, omega, nfreq)¶
- NAME:
scargle_fast_py
- PURPOSE:
Compute the Lomb-Scargle periodogram of an unevenly sampled lightcurve
- CATEGORY:
time series analysis
- INPUTS:
t: The times at which the time series was measured (e.g. HJD) c: counts (corresponding count rates) omega: angular frequencies for which the PSD values are desired
[PSD: Fourier Power Spectral Density]
nfreq: number of independent frequencies
- OUTPUTS:
px: the psd-values corresponding to omega
- DESCRIPTION:
The Lomb Scargle PSD is computed according to the definitions given by Scargle, 1982, ApJ, 263, 835, and Horne and Baliunas, 1986, MNRAS, 302, 757. Beware of patterns and clustered data points as the Horne results break down in this case! Read and understand the papers and this code before using it! For the fast algorithm read W.H. Press and G.B. Rybicki 1989, ApJ 338, 277.
The code is still stupid in the sense that it wants normal frequencies, but returns angular frequency…
- MODIFICATION HISTORY OF IDL VERSION:
Version 1.0, 1997, Joern Wilms IAAT Version 1.1, 1998.09.23, JW: Do not normalize if variance is 0
(for computation of LSP of window function…)
Version 1.2, 1999.01.07, JW: force nfreq to be int Version 1.3, 1999.08.05, JW: added omega keyword Version 1.4, 1999.08
KP: significance levels JW: pmin,pmax keywords
- Version 1.5, 1999.08.27, JW: compute the significance levels
from the horne number of independent frequencies, and not from nfreq
- Version 1.6, 2000.07.27, SS and SB: added fast algorithm and FAP
according to white noise lc simulations.
- Version 1.7, 2000.07.28 JW: added debug keyword, sped up
simulations by factor of four (use /slow to get old behavior of the simulations)
- WEBSITE FOR THE IDL VERSION (Version 1.7, 2000.07.28):
http://astro.uni-tuebingen.de/software/idl/aitlib/timing/scargle.pro
- ORIGINAL IDL DEFINITION:
- PRO scargle,t,c,om,px,fmin=fmin,fmax=fmax,nfreq=nfreq, $
nu=nu,period=period,omega=omega, $ fap=fap,signi=signi,simsigni=simsigni, $ pmin=pmin,pmax=pmax,old=old, $ psdpeaksort=psdpeaksort,multiple=multiple,noise=noise, $ debug=debug,slow=slow
- leavitt.psearch_py3.scargle_py(t, c, fmin=None, fmax=None, pmin=None, pmax=None, omega=None, fap=None, noise=None, multiple=None, nfreq=None, old=None, debug=False, slow=None)¶
- NAME:
scargle_py
- PURPOSE:
Compute the Lomb-Scargle periodogram of an unevenly sampled lightcurve
- CATEGORY:
time series analysis
- INPUTS:
t: The times at which the time series was measured (e.g. HJD) c: counts (corresponding count rates)
- OPTIONAL INPUTS:
- fmin: minimum frequency (NOT ANGULAR FREQ!) to be used
(has precedence over pmin)
- fmax: maximum frequency (NOT ANGULAR FREQ!) to be used
(has precedence over pmax)
pmin: minimum PERIOD to be used pmax: maximum PERIOD to be used omega: angular frequencies for which the PSD values are desired
[PSD: Fourier Power Spectral Density]
- fap: false alarm probability desired
(see Scargle et al., p. 840,a and signi keyword). Default equal to 0.01 (99% significance)
- noise: for the normalization of the periodogram and the
compute (sp?) of the white noise simulations. If not set, equal to the variance of the original lc.
- multiple: number of white noise simulations for the FAP
power level. Default equal to 0 (i.e., no simulations).
nfreq: number of independent frequencies
- OPTIONAL BOOLEAN INPUTS (IDL: KEYWORD PARAMETERS):
- old: if set computing the periodogram according to
Scargle, J.D. 1982, ApJ 263, 835. If not set, compute the periodogram with the fast algorithm of Press, W.H., & G.B. Rybicki, G.B. 1989, ApJ 338, 277.
debug: print out debugging information if set slow: if set, a much slower but less memory intensive way to
perform the white noise simulations is used.
- OUTPUTS:
om: angular frequency of PSD [PSD: Fourier Power Spectral Density] px: the psd-values corresponding to omega
[KJM: original IDL documentation refers to psd — which did not exist]
nu: normal frequency [nu = om/(2.*np.pi)] period: period corresponding to each omega [period = 1./nu] signi: power threshold corresponding to the given false alarm
probabilities fap and according to the desired number of independent frequencies
- simsigni: power threshold corresponding to the given false alarm
probabilities fap according to white noise simulations
psdpeaksort: array with the maximum peak pro (sp?) each simulation
- DESCRIPTION:
The Lomb Scargle PSD is computed according to the definitions given by Scargle, 1982, ApJ, 263, 835, and Horne and Baliunas, 1986, MNRAS, 302, 757. Beware of patterns and clustered data points as the Horne results break down in this case! Read and understand the papers and this code before using it! For the fast algorithm read W.H. Press and G.B. Rybicki 1989, ApJ 338, 277.
The code is still stupid in the sense that it wants normal frequencies, but returns angular frequency…
- MODIFICATION HISTORY OF IDL VERSION:
Version 1.0, 1997, Joern Wilms IAAT Version 1.1, 1998.09.23, JW: Do not normalize if variance is 0
(for computation of LSP of window function…)
Version 1.2, 1999.01.07, JW: force nfreq to be int Version 1.3, 1999.08.05, JW: added omega keyword Version 1.4, 1999.08
KP: significance levels JW: pmin,pmax keywords
- Version 1.5, 1999.08.27, JW: compute the significance levels
from the horne number of independent frequencies, and not from nfreq
- Version 1.6, 2000.07.27, SS and SB: added fast algorithm and FAP
according to white noise lc simulations.
- Version 1.7, 2000.07.28 JW: added debug keyword, sped up
simulations by factor of four (use /slow to get old behavior of the simulations)
- WEBSITE FOR THE IDL VERSION (Version 1.7, 2000.07.28):
http://astro.uni-tuebingen.de/software/idl/aitlib/timing/scargle.pro
- ORIGINAL IDL DEFINITION:
- PRO scargle,t,c,om,px,fmin=fmin,fmax=fmax,nfreq=nfreq, $
nu=nu,period=period,omega=omega, $ fap=fap,signi=signi,simsigni=simsigni, $ pmin=pmin,pmax=pmax,old=old, $ psdpeaksort=psdpeaksort,multiple=multiple,noise=noise, $ debug=debug,slow=slow
- leavitt.psearch_py3.scramble_py(inarr)¶
- NAME:
scramble_py
- INPUTS:
inarr
- OUTPUTS:
scrambarr pickarr
- ORIGINAL IDL DEFINITION:
pro scramble, inarr, scrambarr, pickarr
- leavitt.psearch_py3.show_plot_on_mac(plotfile=None)¶
- leavitt.psearch_py3.table_psi_kjm_py(xx=None, yy=None, ee=None, n=None)¶
- NAME:
table_psi_kjm_py
- INPUTS:
xx: periods (e.g., x) yy: power (e.g., psi) ee: thresh (e.g., conf) n: number of ranked periods to show (e.g., 10)
leavitt.rrlfit module¶
- class leavitt.rrlfit.RRLfitter(tmps, fltnames=['u', 'g', 'r', 'i', 'z', 'Y', 'VR'], ampratio=[1.81480451, 1.4610491, 1.0, 0.79662171, 0.74671563, 0.718746, 1.050782])[source]¶
Bases:
objectObject used to fit templates to data. Initialize with the templates you plan to compare against and lists of the bands and amplitude ratios for those bands Templates should be in an Astropy table with columns for the phase and each unique template. Column names are assumed to be template names.
- leavitt.rrlfit.fit_plot(fitter, objname, cat=None, plist=None, N=10, verbose=False, dirpath='')[source]¶
- leavitt.rrlfit.gaussAveSlow(t, y, std=0.01)[source]¶
Does an average in y with weights based on distances to all other points in t.
- leavitt.rrlfit.get_data(nms, bands=['u', 'g', 'r', 'i', 'z', 'Y', 'VR'])[source]¶
Query list of objects by name, extract light curves, error, filters and top N estimated periods.
- leavitt.rrlfit.get_periods(mjd, mag, err, fltr, objname='', outdir='results/plots', N=10, pmin=0.2, bands=['u', 'g', 'r', 'i', 'z', 'Y', 'VR'], verbose=False)[source]¶
leavitt.sampler module¶
SAMPLER.PY - Variable star sampler
- class leavitt.sampler.Sampler(log_probability, args=None, kwargs=None)[source]¶
Bases:
objectGeneric sampler.
- log_probabilityfunction
- Function that calculates the ln probability given (theta, x, y, err). It must also
perform the marginalization over the non-linear parameters.
- argstuple
- Must at least contain (x, y, err). It can additional contain other positional
arguments to be passed to log_probability().
- kwargsdict, optional
Dictionary of keyword arguments to pass to log_probability() function.
- class leavitt.sampler.VariableSampler(catalog, template, ampratios=None, minerror=0.02)[source]¶
Bases:
objectClass for doing sampling of variable star lightcurve ddata.
- Parameters:
- catalogtable
Catalog of data points, just have mag, err, jd, band
- templatetable
Template information.
- ampratiosdict, optional
- Amplitude ratios. Keys should be the unique band names
and values should be the amplitue ratios. If this is not input, then a ratio of 1.0 is used.
- minerrorfloat, optional
Minimum error to use. Default is 0.02.
- run(pmin=0.1, pmax=None, minsample=128, npoints=200000)[source]¶
Run the sampler.
- Parameters:
- pminfloat, optional
Minimum period to search in days. Default is 0.1 days.
- pmaxfloat, optional
Maximum period to search in days. Default is 2 x time baseline.
- minsampleint, optional
Mininum number of samples to return. Default is 128.
- npointsint, optional
Number of points to use per loop. Default is 200,000.
- leavitt.sampler.log_likelihood_variable(theta, x, y, err, data=None, template=None, ampratios=None, bandindex=None, totwtdict=None, totwtydict=None, **kwargs)[source]¶
- leavitt.sampler.model_variable(phase, **kwargs)[source]¶
Generate variable star template model using phase.
- leavitt.sampler.sampler(catalog, template, pmin=0.1, pmax=None, ampratios=None, minerror=0.02, minsample=128, npoints=200000, plotbase='sampler')[source]¶
- catalogtable
Catalog of data points, just have mag, err, jd, band
- templatetable
Template information.
- pminfloat, optional
Minimum period to search in days. Default is 0.1 days.
- pmaxfloat, optional
Maximum period to search in days. Default is 2 x time baseline.
- ampratiosdict, optional
- Amplitude ratios. Keys should be the unique band names
and values should be the amplitue ratios. If this is not input, then a ratio of 1.0 is used.
- minerrorfloat, optional
Minimum error to use. Default is 0.02.
- minsampleint, optional
Mininum number of samples to return. Default is 128.
- npointsint, optional
Number of points to use per loop. Default is 200,000.
- plotbasestr, optional
Base name for output plots. Default is “sampler”.
leavitt.selftemplate module¶
- class leavitt.selftemplate.RRLfitter(tmps, fltnames=['u', 'g', 'r', 'i', 'z', 'Y', 'VR'], ampratio=[1.81480451, 1.4610491, 1.0, 0.79662171, 0.74671563, 0.718746, 1.050782])[source]¶
Bases:
object
- leavitt.selftemplate.get_data(objname, bands=['u', 'g', 'r', 'i', 'z', 'Y', 'VR'])[source]¶
Query the object by name, extract light curves, error, filters and top N estimated periods.
- leavitt.selftemplate.get_periods(mjd, mag, err, fltr, objname='', N=5, pmin=0.2, bands=['u', 'g', 'r', 'i', 'z', 'Y', 'VR'])[source]¶
- leavitt.selftemplate.model(cat, template, pars)[source]¶
Return the template model for data points.
- Parameters:
- catastropy table or numpy structured array
Input catalog of measurement data with “mjd”, “mag”, “err” and “fltr” columns.
- templatenumpy structured array
Template information with columns “phase” and “flux”.
- parsnumpy array
Array of parameters: [period, t0, amplitudes, mean magnitudes]
- Returns:
- modelmagnumpy array
Model magnitudes contructed from the template.
- leavitt.selftemplate.scaledmags(cat, template, pars)[source]¶
Return the scaled observed magnitudes so they can be easily compared to the template.
- Parameters:
- catastropy table or numpy structured array
Input catalog of measurement data with “mjd”, “mag”, “err” and “fltr” columns.
- templatenumpy structured array
Template information with columns “phase” and “flux”.
- parsnumpy array
Array of parameters: [period, t0, amplitudes, mean magnitudes]
- Returns:
- phnumpy array
Array of phases.
- sclmagnumpy array
Scaled observed magnitudes.
- leavitt.selftemplate.selftemplate(cat, period, maxiter=5, minrmsdiff=0.02, verbose=False)[source]¶
Generate template from data itself.
- Parameters:
- catastropy table or numpy structured array
Input catalog of measurement data with “mjd”, “mag”, “err” and “fltr” columns.
- periodfloat
Period to use in days.
- maxiterint, optional
Maximum iterations to try. Default is 5.
- minrmsdifffloat, optional
- Maximum RMS difference of the template between iterations before the
iteration loop is halted. Default is 0.02.
- verbosebool, optional
Verbose output. Default is False.
- Returns:
- bandsnumpy array
Array of unique band names.
- parsnumpy array
Array of parameters: [period, t0, amplitudes, mean magnitudes]
- templatenumpy structured array
Template information with columns “phase” and “flux”.
- chisqfloat
Chi-squared of template, amplitudes and mean magnitudes.
leavitt.templates module¶
- class leavitt.templates.Cepheid[source]¶
Bases:
objectCepheid object to model and fit cepheid light curves.
Initialize the Cepheid object.
- fit(data)[source]¶
Fit Cepheid model to the data.
- Parameters:
- datanumpy array, list or tuple
The data to fit. This should be time, magnitude, filter, and uncertainties.
- Returns:
- parsnumpy array
Best-fitting parameters.
- pcovnumpy array
Covariance matrix.
Examples
pars,pcov = ceph.fit(data)
- jac(xdata, *pars, retmodel=False)[source]¶
Return Jacobian matrix, the derivatives for each data point.
- Parameters:
- xdatanumpy array, list or tuple
This should contain the time and filter information.
- parsargs
The parameters. period, phase, magnitude offsets.
- retmodelboolean, optional
Return the model as well. Default is retmodel=False.
- Returns:
- jacnumpy array
Jacobian matrix of partial derivatives [N,Npars].
- modelnumpy array
The model magnitudes (if retmodel=True).
Examples
jac = ceph.jac(xdata,*pars)
- model(xdata, *pars, doderiv=False)[source]¶
Generate a model for a given input parameters. This is used with fit() and or curve_fit().
- Parameters:
- xdatanumpy array, list or tuple
This should contain the time and filter information.
- parsargs
The parameters. period, phase, magnitude offsets.
- doderivbool, optional
Return the derivative as well. Default is False.
- Returns:
- resultnumpy array
The model magnitudes.
- phderivnumpy array
The phase derivative. Only if doderiv=True.
Examples
result = ceph.model(xdata,*pars)
- leavitt.templates.lightcurve(t, filts, pars, tempdict, doderiv=False)[source]¶
Create Cepheid lightcurve.
- Parameters:
- tnumpy array
Time array in days.
- filtsnumpy array
Filters IDs. 1: I-band, 2: V-band, 3: B-band
- parsnumpy array
- Parameters.
Period (days) phase shift (unitless, 0-1) mag0_i – average I-band magnitude mag0_v – average V-band magnitude mag0_b – average B-band magnitude
- tempdictdictionary
Dictionary with template information.
- doderivbool, optional
Return phase derivative as well. Default is False.
- Returns:
- resultnumpy array
The model magnitudes.
- parsnumpy array
Examples
result = lightcurve(t,filts,pars,tempdict)
leavitt.timeseries module¶
- class leavitt.timeseries.Variable(objid, period=None, variclass=None, timeseries=None, datarelease='dr2')[source]¶
Bases:
objectThis class gives the core functionality to look for and analyse variability inside of the NSC. It operates on the basis of stars being objects.
- Parameters:
- objid: str
Unique object ID inside of the NSC catalog.
- period: float, optional
Period of the variable star, if known.
- variclass: str, optional
Variability class (e.g. RRLab, Classical Cepheid, etc.). No functionality implemented for it at the moment.
- timeseries: TimeSeries object, optional
Object with data including times and magnitudes. Additional data is also possible using the Astropy TimeSeries functionality. If not given, the data will be retrieved automatically based on the given Object ID and data release.
- datarelease: str, optional
Data release from which the data comes from, or where it should be taken from. Default is DR2.
Initialize the Star object. If data for the time series is not given, then get it from Datalab.
- franges()[source]¶
Function to determine frequency ranges if they are not provided.
- Returns:
- min_frequency: Time
Minimum frequency, in 1/days (default).
- max_frequency: Time
Maximum frequency, in 1/days (default).
- frequency_array(nbins=100, minimum_frequency=None, maximum_frequency=None)[source]¶
Function to define the frequency array used for calculating the different periodograms. It looks for information on whether the suspected variable has a long or short period to define the frequency ranges.
- get_folded_ts(period=None)[source]¶
Folds time series data according to the period of the star.
- Returns:
- phasendarray
- get_period(frequency, power)[source]¶
Returns the most likely period for the given periodogram. Looks for the absolute maximum in the periodogram. It also sets the period attribute for the Class.
- Parameters:
- frequency: array-like
Frequencies evaluated in the periodogram.
- power: array-like
Power at each frequency. Must have the same shape.
- Returns:
- period: float
Most likely period.
- error: float
Error based on the precision in the given frequencies.
- get_timeseries_data(datarelease=None, datalab_token=None)[source]¶
For a given Object ID, return time series data.
- Parameters:
- objidstr, optional
ID of the star. Keep in mind it does not carry over different data releases.
- datarelease: str, optional
Data release from which to get the data from. Default is the class default, currently “dr2”.
- issp()[source]¶
Function to determine whether a variable has or could have a short or long period. Mostly for internal use, to establish period search ranges.
It will use the actual period value if available, if not the variability class is used. If nothing is available, a short period is assumed.
- Returns:
- shortperiod: bool
True if the variable has a short period, False if not.
- lk_periodogram(minimum_frequency=None, maximum_frequency=None)[source]¶
Calculates a Lafler-Kinman periodogram for a single band, based on the data stored in timeseries.
- Returns:
- frequencyndarray
Frequencies for the periodogram.
- powerndarray
Power for the corresponding frequencies.
- ls_mb_periodogram(method='flexible', normalization='standard', minimum_frequency=None, maximum_frequency=None)[source]¶
Calculates a multi-band Lomb-Scargle periodogram based on the data stored in timeseries.
- Returns:
- frequencyndarray
Frequencies for the periodogram.
- powerndarray
Power for the corresponding frequencies.
- ls_periodogram(band=None, method='flexible', normalization='standard', minimum_frequency=None, maximum_frequency=None)[source]¶
Calculates a Lomb-Scargle periodogram for a single band, based on the data stored in timeseries.
- Returns:
- frequencyndarray
Frequencies for the periodogram.
- powerndarray
Power for the corresponding frequencies.
leavitt.tmpfit module¶
- leavitt.tmpfit.get_data(objname, bands=['u', 'g', 'r', 'i', 'z', 'Y', 'VR'])[source]¶
Query the object by name, extract light curves, error, filters and top N estimated periods.
- leavitt.tmpfit.get_periods(mjd, mag, err, fltr, objname='', outdir='results/plots', N=10, pmin=0.2, bands=['u', 'g', 'r', 'i', 'z', 'Y', 'VR'], verbose=False)[source]¶
- class leavitt.tmpfit.tmpfitter(tmps, fltnames=['u', 'g', 'r', 'i', 'z', 'Y', 'VR'])[source]¶
Bases:
objectObject used to fit templates to data. Initialize with the templates you plan to compare against and lists of the bands and amplitude ratios for those bands Templates should be in an Astropy table with columns for the phase and each unique template. Column names are assumed to be template names.
leavitt.utils module¶
- leavitt.utils.addcatcols(cat, dt)[source]¶
Add new columns to an existing numpty structured array catalog.
- leavitt.utils.basiclogger(name=None)[source]¶
This sets up a basic logger that writes just to the screen.
- leavitt.utils.blocks(files, size=65536)[source]¶
This is a small utility function used by numlines()
- leavitt.utils.create_index(arr)[source]¶
Create an index of array values like reverse indices. arr[index[‘index’][index[‘lo’][2]:index[‘hi’][2]+1]]
- leavitt.utils.gaussbin(x, amp, cen, sig, const=0, slp=0.0, dx=1.0)[source]¶
1-D gaussian with pixel binning
This function returns a binned Gaussian par = [height, center, sigma]
- Parameters:
- xarray
The array of X-values.
- ampfloat
The Gaussian height/amplitude.
- cenfloat
The central position of the Gaussian.
- sigfloat
The Gaussian sigma.
- constfloat, optional, default=0.0
A constant offset.
- slpfloat, optional, default=0.0
A linear slope around cen.
- dxfloat, optional, default=1.0
The width of each “pixel” (scalar).
- Returns:
- gevalarray
The binned Gaussian in the pixel
- leavitt.utils.gaussfit(x, y, initpar, sigma=None, bounds=None, binned=False)[source]¶
Fit 1-D Gaussian to X/Y data
- leavitt.utils.gaussian(x, amp, cen, sig, const=0.0, slp=0.0)[source]¶
1-D gaussian: gaussian(x, amp, cen, sig)
- leavitt.utils.grep(lines=None, expr=None, index=False)[source]¶
Similar to the standard unit “grep” but run on a list of strings. Returns a list of the matching lines unless index=True is set, then it returns the indices. Parameters ———- lines : list
The list of string lines to check.
- exprstr
Scalar string expression to search for.
- indexbool, optional
If this is
Truethen the indices of matching lines will be returned instead of the actual lines. index isFalseby default.
- Returns:
- outlist
The list of matching lines or indices.
Examples
Search for a string and return the matching lines: .. code-block:: python
mlines = grep(lines,”hello”)
Search for a string and return the indices of the matching lines: .. code-block:: python
index = grep(lines,”hello”,index=True)
- leavitt.utils.gsmooth(data, fwhm, mask=None, boundary='extend', fill=0.0, truncate=4.0, squared=False)[source]¶
- leavitt.utils.interp(x, y, xout, kind='cubic', bounds_error=False, assume_sorted=True, extrapolate=True, exporder=2, fill_value=nan)[source]¶
- leavitt.utils.mad(data, axis=None, func=None, ignore_nan=True)[source]¶
Calculate the median absolute deviation.
- leavitt.utils.match(a, b, epsilon=0)[source]¶
Routine to match values in two vectors.
- CALLING SEQUENCE:
match, a, b, suba, subb, [ COUNT =, /SORT, EPSILON = ]
- INPUTS:
a,b - two vectors to match elements, numeric or string data types
- OUTPUTS:
- suba - subscripts of elements in vector a with a match
in vector b
- subb - subscripts of the positions of the elements in
vector b with matchs in vector a.
suba and subb are ordered such that a[suba] equals b[subb] suba and subb are set to !NULL if there are no matches (or set to -1
if prior to IDL Version 8.0)
- OPTIONAL INPUT KEYWORD:
- /SORT - By default, MATCH uses two different algorithm: (1) the
/REVERSE_INDICES keyword to HISTOGRAM is used for integer data, while (2) a sorting algorithm is used for non-integer data. The histogram algorithm is usually faster, except when the input vectors are sparse and contain very large numbers, possibly causing memory problems. Use the /SORT keyword to always use the sort algorithm.
- epsilon - if values are within epsilon, they are considered equal. Used only
only for non-integer matching. Note that input vectors should be unique to within epsilon to provide one-to-one mapping. Default=0.
- OPTIONAL KEYWORD OUTPUT:
COUNT - set to the number of matches, integer scalar
- SIDE EFFECTS:
The obsolete system variable !ERR is set to the number of matches; however, the use !ERR is deprecated in favor of the COUNT keyword
- RESTRICTIONS:
The vectors a and b should not have duplicate values within them. You can use rem_dup function to remove duplicate values in a vector
- EXAMPLE:
If a = [3,5,7,9,11] & b = [5,6,7,8,9,10] then
IDL> match, a, b, suba, subb, COUNT = count
will give suba = [1,2,3], subb = [0,2,4], COUNT = 3 and a[suba] = b[subb] = [5,7,9]
- METHOD:
For non-integer data types, the two input vectors are combined and sorted and the consecutive equal elements are identified. For integer data types, the /REVERSE_INDICES keyword to HISTOGRAM of each array is used to identify where the two arrays have elements in common.
- HISTORY:
D. Lindler Mar. 1986. Fixed “indgen” call for very large arrays W. Landsman Sep 1991 Added COUNT keyword W. Landsman Sep. 1992 Fixed case where single element array supplied W. Landsman Aug 95 Use a HISTOGRAM algorithm for integer vector inputs for improved
performance W. Landsman March 2000
Work again for strings W. Landsman April 2000 Use size(/type) W. Landsman December 2002 Work for scalar integer input W. Landsman June 2003 Assume since V5.4, use COMPLEMENT to WHERE() W. Landsman Apr 2006 Added epsilon keyword Kim Tolbert March 14, 2008 Fix bug with Histogram method with all negative values W. Landsman/ R. Gutermuth, return !NULL for no matches November 2017 Added epsilon test in na=1||nb=1 section (missed that when added
epsilon in 2008) Kim Tolbert July 10, 2018
- leavitt.utils.most_frequent(array, return_counts=False)[source]¶
Returns the most frequent element in an array.
- Parameters:
- array: array-like
Input array.
- return_counts: bool, optional
Whether to return the number of counts of the most frequent element. Default is false.
- Returns:
- most_frequent
Most frequent element in array.
- counts: float
- leavitt.utils.numlines(fil=None)[source]¶
This function quickly counts the number of lines in a file. Parameters ———- fil : str
The filename to check the number of lines.
Returns¶
- nlinesint
The number of lines in
fil.
Examples
- leavitt.utils.pathjoin(indir=None, name=None)[source]¶
Join two or more pathname components, inserting ‘/’ as needed Same as os.path.join but also works on arrays/lists.
- leavitt.utils.phase_fold(mjd, period, mjd0=None, centeredzero=False)[source]¶
Given a series of dates and a period, it phase folds them into a number of cycles.
- Parameters:
- mjd: array-like
Array of dates to phase fold in Mean Julian Date (MJD).
- period: Quantity
Period to use for the phase fold, in days.
- mjd0: float, optional
Initial day to use for the phase fold. Default is the earliest date in mjd.
- centeredzero: boolean, optional
Whether the phase goes from 0 to 1 or -0.5 to 0.5. Default is False (0 to 1).
- Returns:
- phase: array-like
Converted mjd to phase values.
- leavitt.utils.plot_periodogram(frequency, power, filename='periodogram.png', units='days')[source]¶
Plots a periodogram based on the power and frequency given.
- Parameters:
- frequency: array-like
Frequency as 1/period, where the period is measured in days.
- power: array-like
Corresponding power for each frequency. Must be the same shape as frequency.
- filename: str, optional
Name of the file where to store the plot.
- units: str, optional
Units used for the periodogram plot. Default is days.
- Returns:
- Saves a file to disk.
- leavitt.utils.plot_phased_lightcurve(phase, mags, mags_errs=None, filters=None, filename='timecurve.png')[source]¶
Plot a phase folded light curve. If multiple filters are present, plots them with different colors.
- Parameters:
- phase: array-like
Phases for each exposures.
- mags: array-like
Magnitude of object in each exposure. Must have same shape as phase.
- mags_errs: array-like
Associated errors for magnitudes. Must have the same shape as phase and mags.
- filters: string, array-like, optional
Unique filters present in the data. If not given, all will be assumed to be the same.
- filename: string
Path to save the plot.
- leavitt.utils.poly_fit(x, y, nord, robust=False, sigma=None, initpar=None, bounds=(-inf, inf), error=False, max_nfev=None)[source]¶
- leavitt.utils.quadratic_bisector(x, y)[source]¶
Calculate the axis of symmetric or bisector of parabola
- leavitt.utils.readlines(fil=None, raw=False)[source]¶
Read in all lines of a file.
- Parameters:
- filestr
The name of the file to load.
- rawbool, optional, default is false
Do not trim
- off the ends of the lines.
- Returns:
- lineslist
The list of lines from the file
Examples
- leavitt.utils.remove_indices(lst=None, index=None)[source]¶
This will remove elements from a list given their indices. Use numpy.delete() for numpy arrays instead. Parameters ———- lst : list
The list from which to remove elements.
- indexlist or array
The list or array of indices to remove.
- Returns:
- newlstlist
The new list with indices removed.
Examples
Remove indices 1 and 5 from array
arr. .. code-block:: pythonindex = [1,5] arr = range(10) arr2 = remove_indices(arr,index) print(arr)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
- leavitt.utils.robust_slope(x, y, sigma, limits=None, npt=15, reweight=False)[source]¶
Calculate robust weighted slope
- leavitt.utils.roi_cut(xcut, ycut, x, y)[source]¶
Use cuts in a 2D plane to select points from arrays. Parameters ———- xcut : numpy array
Array of x-values for the cut
- ycutnumpy array
Array of y-values for the cut
- xnumpy array or list
Array of x-values that should be cut
- ynumpy array or list
Array of y-values that should be cut
Returns¶
- indnumpy array
The indices of values OUTSIDE the cut
- cutind
The indices of values INSIDE the cut
Example¶
- leavitt.utils.scale(arr, oldrange, newrange)[source]¶
This function maps an array or image onto a new scale given two points on the old scale and the corresponding points on the new scale. The array is converted to double type. It’s similar to BYTSCL.PRO except that you can set the bottom value as well. The ranges can be increasing or decreasing. INPUTS: arr The array of values to be scaled oldrange Two-element array specifiying The original range which
will be scaled to newrange.
- newrange Two-element array specifiying The new range which
the oldrange will be scaled to.
OUTPUTS: narr The new scaled array USAGE: arr2 = scale(arr,[0,1],[150,2000]) By D.Nidever March 2007
- leavitt.utils.scale_vector(vector, minrange, maxrange)[source]¶
Scale a vector to minrange and maxrange.
- leavitt.utils.strjoin(a=None, b=None, c=None, sep=None)[source]¶
Join two string lists/arrays or scalars
- leavitt.utils.voigt(x, height, cen, sigma, gamma, const=0.0, slp=0.0)[source]¶
Return the Voigt line shape at x with Lorentzian component HWHM gamma and Gaussian sigma.
- leavitt.utils.voigtfit(x, y, initpar=None, sigma=None, bounds=(-inf, inf))[source]¶
Fit a Voigt profile to data.
- leavitt.utils.where(statement, comp=False)[source]¶
Wrapper around numpy.where() to be more like IDL
- leavitt.utils.writelines(filename=None, lines=None, overwrite=True, raw=False)[source]¶
Write a list of lines to a file.
- Parameters:
- filenamestr
The filename to write the lines to.
- lineslist
The list of lines to write to a file.
- overwritebool, optional, default is True
If the output file already exists, then overwrite it.
- rawbool, optional, default is False
Do not modify the lines. Write out as is.
- Returns:
- Nothing is returned. The lines are written to
fil.
- Nothing is returned. The lines are written to
Examples
- leavitt.utils.wtmean(x, sigma, error=False, reweight=False, magnitude=False)[source]¶
Calculate weighted mean and error