wobble API

Data

class wobble.Data(filename, filepath='', orders=None, epochs=None, min_flux=1.0, max_norm_flux=2.0, padding=2, min_snr=5.0, log_flux=True)

The data object: contains the spectra and associated data. All objects in data are numpy arrays or lists of arrays. Includes all orders and epochs.

Parameters:
  • filename (str) – Name of HDF5 file storing the data.
  • filepath (str (default ../data/)) – Path to append to filename.
  • orders (list (default None)) – Indices of spectral orders to read in. If None include all. Even if it’s only one index, it must be a list.
  • epochs (int or list (default None)) – Indices of epochs to read in. If None include all.
  • min_flux (float (default 1.)) – Flux in counts/pixel below which a pixel is masked out.
  • max_norm_flux (float (default 2.)) – Flux in normalized counts/pixel above which a pixel is masked out.
  • padding (int (default 2)) – Number of pixels to additionally mask on either side of a bad high pixel.
  • min_snr (float (default 5.)) – Mean SNR below which which we discard sections of data.
  • log_flux (bool (default True)) – Determines whether fitting will happen using logarithmic flux (default) or linear flux.
continuum_normalize(**kwargs)

Continuum-normalize all spectra using a polynomial fit. Takes kwargs of utils.fit_continuum

mask_low_pixels(min_flux=1.0, padding=2, min_snr=5.0)

Set ivars to zero for pixels and edge regions that are bad.

read_data(origin_file, orders=None, epochs=None)

Read origin file and set up data attributes from it

trim_bad_edges(r, window_width=128, min_snr=5.0)

Find edge regions that contain no information and trim them.

Parameters:
  • r (int) – order index
  • window_width (int) – number of pixels to average over for local SNR
  • min_snr (float) – SNR threshold below which we discard the data

Model

class wobble.Model(data, results, r)

Keeps track of all components in the model. Model is specific to order r of data object data.

Parameters:
  • data (object) – a wobble Data object
  • results (object) – a wobble Results object
  • r (int) – the index of the order to be fit in Data
add_component(name, starting_rvs, **kwargs)

Add a new Component object to the model.

add_star(name, starting_rvs=None, **kwargs)

Add a component with RVs initialized to zero in the barycentric-corrected rest frame.

add_telluric(name, starting_rvs=None, **kwargs)

Add a component with RVs initialized to zero in the observatory rest frame.

estimate_uncertainties(verbose=True, rvs=True, templates=False)

Estimate uncertainties using the second derivative of the likelihood.

Parameters:
  • verbose (bool (default True)) – Toggle print statements and progress bars.
  • rvs (bool (default True)) – Calculate uncertainties for rvs.
  • templates (bool (default False)) – Calculate uncertainties for template_ys. (NOTE: this may take a while!)
initialize_templates()

Initialize spectral templates for all components.

NOTE: this will initialize each subsequent component from the residuals of the previous, so make sure you have added the components in order of largest to smallest contribution to the net spectrum.

optimize(niter=100, save_history=False, basename='wobble', feed_dict=None, verbose=True, rv_uncertainties=True, template_uncertainties=False, **kwargs)

Optimize the model!

Parameters:
  • niter (int (default 100)) – Number of iterations.
  • save_history (bool (default False)) – If True, create a wobble History object to track progress across iterations and generate plots.
  • basename (str (default wobble)) – Path/name to use when saving plots. Only accessed if save_history = True.
  • feed_dict (dict (default None)) – TensorFlow magic; passed to the optimizer. If None, does nothing.
  • verbose (bool (default True)) – Toggle print statements and progress bars.
  • rv_uncertainties (bool (default True)) – Toggle whether RV uncertainty estimates should be calculated.
  • template_uncertainties (bool (default False)) – Toggle whether template uncertainty estimates should be calculated.
setup()

Initialize component templates and do TensorFlow magic in prep for optimizing

class wobble.Component(name, r, starting_rvs, regularization_par_file=None, L1_template=0.0, L2_template=0.0, L1_basis_vectors=0.0, L2_basis_vectors=0.0, L2_basis_weights=1.0, learning_rate_rvs=1.0, learning_rate_template=0.01, learning_rate_basis=0.01, rvs_fixed=False, template_fixed=False, variable_bases=0, scale_by_airmass=False, template_xs=None, template_ys=None, initialize_at_zero=False)

Generic class for an additive component in the spectral model.

initialize_template(data_xs, data_ys, data_ivars)

Doppler-shift data into component rest frame, subtract off other components, and average to make a composite spectrum.

setup(data, r)

Do TensorFlow magic in prep for optimizing

Results

class wobble.Results(data=None, filename=None)

A read/writeable object which stores RV & template results across all orders. At the end of each Model optimize() call, the associated Results object is updated with numpy outputs from each optimized TensorFlow variable. This allows us to clear out the graph and retain the solution.

One of the two keywords is required for initialization.

Parameters:
  • data (object) – a wobble Data object
  • filename (str) – a file path pointing to a saved Results object (HDF5 format).
add_component(c)

Initialize a new model component and prepare to save its optimized outputs. The component name should be consistent across all order models.

Note that if a component name was initialized in the models for 1+ orders but was not included in all order models, its RV values/uncertainties will be set to NaNs and all other properties set to 0 for the excluded order(s).

Parameters:c (a wobble.Model.Component object)
combine_orders(component_name)

Calculate and save final time-series RVs for a given component after all orders have been optimized.

Parameters:component_name (str) – Name of the model component to use.
get_design_matrix(restart=False)

Internal code used by combine_orders()

get_index_lists()

Internal code used by combine_orders()

lnlike_sigmas(sigmas, return_rvs=False, restart=False)

Internal code used by combine_orders()

opposite_lnlike_sigmas(pars, **kwargs)

…the opposite of lnlike_sigmas()

read(filename)

Read from HDF5 file.

update(c, **kwargs)

Update the attributes of a component from the current values of Model.

Parameters:c (a wobble.Model.Component object)
write(filename)

Write to HDF5 file.

class wobble.History(model, niter)

Information about optimization history of a single order stored in numpy arrays/lists.

animfunc(i, xs, ys, xlims, ylims, ax, driver, xlabel, ylabel)

Produces each frame; called by History.plot()

plot(xs, ys, linestyle='line', nframes=None, ylims=None, xlabel='', ylabel='')

Generate a matplotlib animation of xs and ys Linestyle options: ‘scatter’, ‘line’

plot_rvs(ind, compare_to_pipeline=True, **kwargs)

Generate a matplotlib animation of RVs vs. time ind: index of component in model to be plotted compare_to_pipeline keyword subtracts off the HARPS DRS values (useful for removing BERVs)

plot_synth(e, nframes=None, ylims=None, ylims2=None, **kwargs)

Generate a matplotlib animation of the data + model prediction for a given epoch e: index of epoch to be plotted

plot_template(ind, **kwargs)

Generate a matplotlib animation of the template inferred from data ind: index of component in model to be plotted

save_iter(model, i)

Save all necessary information after optimization number i

Other Utilities

wobble.utils.bin_data(xs, ys, ivars, xps)

Bin data onto a uniform grid using medians.

Args:
xs: [N, M] array of xs ys: [N, M] array of ys ivars: [N, M] array of y-ivars xps: M’ grid of x-primes for output template
Returns:
yps: M’ grid of y-primes
wobble.utils.doppler(v, tensors=True)
wobble.utils.fit_continuum(x, y, ivars, order=6, nsigma=[0.3, 3.0], maxniter=50)

Fit the continuum using sigma clipping

Args:
x: The wavelengths y: The log-fluxes order: The polynomial order to use nsigma: The sigma clipping threshold: tuple (low, high) maxniter: The maximum number of iterations to do
Returns:
The value of the continuum at the wavelengths in x
wobble.utils.get_session(restart=False)

Get the globally defined TensorFlow session. If the session is not already defined, then the function will create a global session. Returns:

_SESSION: tf.Session.

(Code from edward package.)

wobble.interp.interp(t, x, y, **kwargs)