API Reference#
- class bsavi.Observable(name, data, plot_type=None, plot_opts=None, latex_labels=None)#
Annotate your data with names and plotting instructions to easily create interactive plots. Observable accepts data in the form of tables where each row contains a set of datapoints to plot.
- name#
Specifies the display name of the observable for things like plot titles.
- Type:
str or list[str]
- data#
The data associated with that observable. Can be python dict (or pandas DataFrame) whose keys (or column names) will be used for things like plot axis labels.
- Type:
dict-like or list[dict-like]
- Value:
None
- plot_type#
Specifies how the data should be visualized. Currently can pick either
'Curve'that connects data points together,'Bars'for a series of columns with their heights determined by the y-axis value at each point, or'Scatter'for a simple scatter plot. The default value is'Curve'Pass a single value to set it for all datasets in the Observable, or a list of values to be set for each dataset.
- Type:
str or list[str]
- plot_opts#
Customization options for the observable plot. For more information see HoloViews documentation.
- Type:
HoloViews Options object
- Value:
None
- latex_labels#
A dictionary that has parameter labels as keys and their corresponding LaTeX format as values.
- Type:
dict
- Value:
None
- properties()#
Prints information about the Observable.
- generate_plot(index)#
Generates plots of the data at the given indexes. Will call
Observable.myfuncwithObservable.myfunc_argson the data if given. The plots are returned as a dictionary of plot objects which can be manipulated as you wish.- Parameters:
index (list) – A list of indexes
- Returns:
A dictionary of Holoviews Elements
- draw_plot(index)#
Displays an interactive plot of the data at the given index. Whereas
Observable.generate_plot()returns a dict of plot objects but does not display them, this method will display plots arranged in a layout when evaluated in a Jupyter Notebook cell.- Parameters:
index (list) – A list of indexes
- Returns:
- class bsavi.LiveObservable(name, myfunc, myfunc_args, plot_type=None, plot_opts=None, latex_labels=None)#
Annotate a function with names and plotting instructions to easily create interactive plots. Live Observable will call the function to get a set of datapoints to plot.
- name#
Specifies the display name of the observable for things like plot titles.
- Type:
str or list[str]
- myfunc#
A user-provided function that returns data in the same data format that
Observable.dataaccepts. Can return more than one set of data.- Type:
Callable
- Value:
None
- myfunc_args#
Arguments for the user-provided function
Observable.myfunc.- Type:
tuple
- Value:
None
- plot_type#
Specifies how the data should be visualized. Currently can pick either
'Curve'that connects data points together,'Bars'for a series of columns with their heights determined by the y-axis value at each point, or'Scatter'for a simple scatter plot. The default value is'Curve'Pass a single value to set it for all datasets in the Observable, or a list of values to be set for each dataset.
- Type:
str or list[str]
- plot_opts#
Customization options for the observable plot. For more information see HoloViews documentation.
- Type:
HoloViews Options object
- Value:
None
- latex_labels#
A dictionary that has parameter labels as keys and their corresponding LaTeX format as values.
- Type:
dict
- Value:
None
- properties()#
Prints information about the Observable.
- generate_plot(index)#
Generates plots of the data at the given indexes. Will call
Observable.myfuncwithObservable.myfunc_argson the data if given. The plots are returned as a dictionary of plot objects which can be manipulated as you wish.- Parameters:
index (list) – A list of indexes
- Returns:
A dictionary of Holoviews Elements
- draw_plot(index)#
Displays an interactive plot of the data at the given index. Whereas
Observable.generate_plot()returns a dict of plot objects but does not display them, this method will display plots arranged in a layout when evaluated in a Jupyter Notebook cell.- Parameters:
index (list) – A list of indexes
- Returns:
- bsavi.viz(data, observables=None, show_observables=False, latex_dict=None)#
Displays an interactive dashboard that links
datatoobservables.- Parameters:
data (dict-like) – The data or distribution to be visualized as a scatterplot
observables (list[
bsavi.Observable]) – A list of the observables to be visualizedshow_observables (bool) – Whether to display the observable plots or not. Default behavior is:
Trueif observables are given,Falseif not.latex_dict (dict) – A dictionary containing the LaTeX formatting for the scatterplot axis labels
- Returns:
A collection of Panel components
- bsavi.loaders.load_params(filename)#
Reads in a
.paramnamesfile and returns a dict of each parameter’s plain text and LaTeX name. Assumes that the file is in the proper format: each line should contain one plain text param name and its LaTeX counterpart separated by atabcharacter (\t). Any amount of whitespace on either side of the tab character is acceptable.- Parameters:
filename (str) – path to the
.paramnamesfile or glob pattern. If glob returns multiple paths,load_paramswill only used the first one- Returns:
a dict of parameter names and LaTeX code
- bsavi.loaders.load_chains(path, params, params_only=True)#
Reads in a chain file and converts it to a DataFrame. Assumes that the file is a .txt file with the following columns: weight, -LogLkl, param1, param2, ….
Weight is the number of iterations the MCMC sampler stayed at that parameter set (the sample weight) and -LogLkl is the negative log of the likelihood. This is the standard format of both CosmoMC and Monte-Python chain files.
- Parameters:
path (str, list['str']) – name of the chain file, list of names, or glob pattern
params (list['str']) – list of parameter names which will be used as column names for the DataFrame.
params_only (bool) – whether to ignore the first two columns of the chain file (weight and -LogLKL). Default is True, which will disregard those columns when reading in the file.
- Returns:
Pandas DataFrame
- bsavi.cosmo.run_class(index, sample)#
Calls the CLASS code on a given index of the sample data to calculate the matter power spectrum \(P(k)\), the lensed power spectrum of the CMB temperature \(C_{l}^{TT}\), and the lensed power spectrum of the CMB polarization \(C_{l}^{EE}\).
Uses the following settings:
{'output':'mPk, tCl, pCl, lCl','P_k_max_1/Mpc':3.0, 'lensing':'yes'}
- Parameters:
index (int) – index location of the sample to be run through CLASS
sample (Pandas DataFrame) – a DataFrame where each row contains samples of cosmological parameters which CLASS accepts as inputs
- Returns:
the three power spectra in the form of a dictionary where each key contains an array of wave numbers \(k\) or multipole moments \(\ell\) and each value contains an array of the calculated values for each \(k\) or \(\ell\).
- bsavi.cosmo.compute_residuals(index, sample, sample_CDM)#
Useful for exploring beyond-CDM cosmologies. Calls the CLASS code on two sets of sample data (one with beyond-CDM parameters, and one with CDM parameters), at the specified index. Computes the percent difference in the three observables (\(P(k)\), \(C_{l}^{TT}\), \(C_{l}^{EE}\)) for each value of \(k\) or \(\ell\).
- Parameters:
index (int) – index location of the sample to be run through CLASS
sample (Pandas DataFrame) – a DataFrame where each row contains samples of beyond-CDM cosmological parameters
sample_CDM (Pandas DataFrame) – a DataFrame where each row contains samples of LCDM cosmological parameters
- Returns:
the power spectrum residuals in the same format as
run_class()