Reference/API¶
APOGEE Data¶
Functions for reading in APOGEE spectra and training labels
-
TheCannon.apogee.
continuum_normalize_training
(ds)[source]¶ Continuum normalize the training set, using an iterative Cannon approach
Parameters: ds: dataset object Returns: updated dataset object
-
TheCannon.apogee.
get_pixmask
(fluxes, flux_errs)[source]¶ Create and return a bad pixel mask for an APOGEE spectrum
Bad pixels are defined as follows: fluxes or errors are not finite, or reported errors are <= 0, or fluxes are 0
Parameters: fluxes: ndarray
Flux data values
flux_errs: ndarray
Flux uncertainty data values
Returns: mask: ndarray
Bad pixel mask, value of True corresponds to bad pixels
-
TheCannon.apogee.
get_starmask
(ids, labels, aspcapflag, paramflag)[source]¶ Identifies which APOGEE objects have unreliable physical parameters, as laid out in Holzman et al 2015 and on the APOGEE DR12 website
Parameters: data: np array
all APOGEE DR12 IDs and labels
Returns: bad: np array
mask where 1 corresponds to a star with unreliable parameters
-
TheCannon.apogee.
load_labels
(filename)[source]¶ Extracts reference labels from a file
Parameters: filename: str
Name of the file containing the table of reference labels
ids: array
The IDs of stars to retrieve labels for
Returns: labels: ndarray
Reference label values for all reference objects
-
TheCannon.apogee.
load_spectra
(data_dir)[source]¶ Reads wavelength, flux, and flux uncertainty data from apogee fits files
Parameters: data_dir: str
Name of the directory containing all of the data files
Returns: wl: ndarray
Rest-frame wavelength vector
fluxes: ndarray
Flux data values
ivars: ndarray
Inverse variance values corresponding to flux values
Dataset¶
-
class
TheCannon.dataset.
Dataset
(wl, tr_ID, tr_flux, tr_ivar, tr_label, test_ID, test_flux, test_ivar)[source]¶ A class to represent Cannon input: a dataset of spectra and labels
-
continuum_normalize
(cont)[source]¶ Continuum normalize spectra, in chunks if spectrum has regions
Parameters: cont: ndarray
Flux values corresponding to the continuum
Returns: norm_tr_flux: ndarray
Normalized flux values for the training objects
norm_tr_ivar: ndarray
Rescaled inverse variance values for the training objects
norm_test_flux: ndarray
Normalized flux values for the test objects
norm_test_ivar: numpy ndarray
Rescaled inverse variance values for the test objects
-
continuum_normalize_gaussian_smoothing
(L)[source]¶ Continuum normalize using a Gaussian-weighted smoothed spectrum
Parameters: dataset: Dataset
the dataset to continuum normalize
L: float
the width of the Gaussian used for weighting
-
continuum_normalize_training_q
(q, delta_lambda, n_proc=1, verbose=True)[source]¶ Continuum normalize the training set using a running quantile
Parameters: q: float
The quantile cut
delta_lambda: float
The width of the pixel range used to calculate the median
Modified by:
[08 Jun 2016] Bo Zhang (NAOC): add multiprocessing option
Note:
Multiprocessing calls for more memory on computer.
-
diagnostics_1to1
(figname='1to1_label')[source]¶ Plots survey labels vs. training labels, color-coded by survey SNR
-
diagnostics_best_fit_spectra
(model)[source]¶ Plot results of best-fit spectra for ten random test objects
-
diagnostics_test_step_flagstars
()[source]¶ Write files listing stars whose inferred labels lie outside 2 standard deviations from the reference label space
-
fit_continuum
(deg, ffunc, n_proc=1)[source]¶ Fit a continuum to the continuum pixels
Parameters: deg: int
Degree of the fitting function
ffunc: str
Type of fitting function, ‘sinusoid’ or ‘chebyshev’
Returns: tr_cont: ndarray
Flux values corresponding to the fitted continuum of training objects
test_cont: ndarray
Flux values corresponding to the fitted continuum of test objects
-
get_plotting_labels
()[source]¶ Return the label names used make plots
Returns: label_names: ndarray
The label names
-
make_contmask
(fluxes, ivars, frac)[source]¶ Identify continuum pixels using training spectra
Does this for each region of the spectrum if dataset.ranges is not None
Parameters: fluxes: ndarray
Flux data values
ivars: ndarray
Inverse variances corresponding to flux data values
frac: float
The fraction of pixels that should be identified as continuum
Returns: contmask: ndarray
Mask with True indicating that the pixel is continuum
-
set_continuum
(contmask)[source]¶ Set the contmask attribute
Parameters: contmask: ndarray
Mask with True indicating that the pixel is continuum
-
set_label_names
(names)[source]¶ Set the label names for plotting
Parameters: names: ndarray or list
The names of the labels used for plotting, ex. in LaTeX syntax
-
smooth_spectrum
(wl, flux, ivar)[source]¶ Bins down one spectrum
Parameters: wl: numpy ndarray
wavelengths
flux: numpy ndarray
flux values
ivar: numpy ndarray
inverse variances associated with fluxes
Returns: wl: numpy ndarray
updated binned pixel wavelengths
flux: numpy ndarray
updated binned flux values
ivar: numpy ndarray
updated binned inverse variances
-
Model¶
-
class
TheCannon.model.
CannonModel
(order, useErrors)[source]¶ -
-
diagnostics_contpix
(data, nchunks=10, fig='baseline_spec_with_cont_pix')[source]¶ Call plot_contpix once for each nth of the spectrum
-
diagnostics_plot_chisq
(ds, figname='modelfit_chisqs.png')[source]¶ Produce a set of diagnostic plots for the model
Parameters: (optional) chisq_dist_plot_name: str
Filename of output saved plot
-
fit
(ds)¶ Run training step: solve for best-fit spectral model
-
infer_labels
(ds, starting_guess=None)[source]¶ Uses the model to solve for labels of the test set, updates Dataset Then use those inferred labels to set the model.test_spectra attribute
Parameters: ds: Dataset
Dataset that needs label inference
Returns: errs_all: ndarray
Covariance matrix of the fit
-
infer_spectra
(ds)[source]¶ After inferring labels for the test spectra, infer the model spectra and update the dataset model_spectra attribute.
Parameters: ds: Dataset object
-
plot_contpix
(x, y, contpix_x, contpix_y, figname)[source]¶ Plot baseline spec with continuum pix overlaid
-
predict
(model, dataset, starting_guess=None)¶ Uses the model to solve for labels of the test set.
Parameters: model: tuple
Coeffs_all, covs, scatters, chis, chisqs, pivots
dataset: Dataset
Dataset that needs label inference
Returns: errs_all:
Covariance matrix of the fit
-