pygama package#

pygama init file. it might be better to declare more of the public functions here if it makes sphinx auto-generated documentation easier.

There’s a nice discussion about what to include in this file here: https://www.reddit.com/r/Python/comments/1bbbwk/whats_your_opinion_on_what_to_include_in_init_py/

Clint’s fav answer:

I like importing key functions and classes. Flat is better than nested, so as a user of a library, I prefer from library import ThingIWant or import library and then using library.ThingIWant rather than from library.things.thing_i_want import ThingIWant.

More specifically, I would often have the contents of __init__.py be:

“Docstring explaining package” (use triple quotes though) from thispackage.module_or_subpackage import * from thispackage.module_thats_next_alphabetically import * …

And then have each module use __all__ to specify which names constitute its public API that should be exposed by the package.

For something you are distributing publicly, I don’t think your __init__.py should ever by “blank” as specified by option 1: you should at least include a docstring explaining what the package does. This will help users poking around in ipython, etc.

Subpackages#

Submodules#

pygama.git module#

pygama.utils module#

pygama convenience functions.

class pygama.utils.SafeDict#

Bases: dict

used in handling LEGEND file format strings. when a key is missing, return the string value of that key.

pygama.utils.fit_simple_scaling(x, y, var=1)#

Fast computation of weighted linear least squares fit to a simple scaling

I.e. y = scale * x. Returns the best fit scale parameter and its variance.

Parameters:
  • x (array like) – x values for the fit

  • y (array like) – y values for the fit

  • var (array like (optional)) – The variances for each y-value

Returns:

scale, scale_var – The scale parameter and its variance

Return type:

tuple (float, float)

pygama.utils.get_dataset_from_cmdline(args, run_db, cal_db)#
make it easier to call this from argparse:

arg(“-ds”, nargs=’*’, action=”store”, help=”load runs for a DS”) arg(“-r”, “–run”, nargs=1, help=”load a single run”)

pygama.utils.get_formatted_stats(mean, sigma, ndigs=2)#

convenience function for formatting mean +/- sigma to the right number of significant figures.

pygama.utils.get_par_names(func)#

Return a list containing the names of the arguments of “func” other than the first argument. In pygamaland, those are the function’s “parameters.”

pygama.utils.linear_fit_by_sums(x, y, var=1)#

Fast computation of weighted linear least squares fit to a linear model

Note: doesn’t compute covariances. If you want covariances, just use polyfit

Parameters:
  • x (array like) – x values for the fit

  • y (array like) – y values for the fit

  • var (array like (optional)) – The variances for each y-value

Returns:

(m, b) – The slope (m) and y-intercept (b) of the best fit (in the least-squares sense) of the data to y = mx + b

Return type:

tuple (float, float)

pygama.utils.peakdet(v, delta, x=None)#

Converted from MATLAB script at: http://billauer.co.il/peakdet.html Returns two arrays: [maxtab, mintab] = peakdet(v, delta, x) An updated (vectorized) version is in pygama.dsp.transforms.peakdet

pygama.utils.plot_func(func, pars, range=None, npx=None, **kwargs)#

plot a function. take care of the x-axis points automatically, or user can specify via range and npx arguments.

pygama.utils.print_fit_results(pars, cov, func=None, title=None, pad=True)#

convenience function for scipy.optimize.curve_fit results

pygama.utils.set_plot_style(style)#

Choose a pygama plot style. Current options: ‘clint’, ‘root’ Or add your own [label].mpl file in the pygama directory!

pygama.utils.sh(cmd, sh=False)#

input a shell command as you would type it on the command line.

pygama.utils.sizeof_fmt(num, suffix='B')#

given a file size in bytes, output a human-readable form.

pygama.utils.tqdm_range(start, stop, step=1, verbose=False, text=None, bar_length=20, unit=None)#

Uses tqdm.trange which wraps around the python range and also has the option to display a progress

Example:

for start_row in range(0, tot_n_rows, buffer_len):

Can be converted to the following

for start_row in tqdm_range(0, tot_n_rows, buffer_len, verbose):

Parameters:
  • start (int) – starting iteration value

  • stop (int) – ending iteration value

  • step (int) – step size inbetween each iteration

  • verbose (int) – verbose = 0 hides progress bar verbose > 0 displays progress bar

  • text (str) – text to display in front of the progress bar

  • bar_length (str) – horizontal length of the bar in cursor spaces

Returns:

iterable – object that can be iterated over in a for loop

Return type:

tqdm.trange

pygama.utils.tree_draw(tree, vars, tcut)#

if you have to debase yourself and use ROOT, this is an easy convenience function for quickly extracting data from TTrees. TTree::Draw can only handle groups of 4 variables at a time, but here we can put in as many as we want, and return a list of numpy.ndarrays for each one

pygama.utils.update_progress(tqdm_bar, progress)#

pygama.version module#