toolbox - Toolbox of various functions and generic utilities

Toolbox of various functions and generic utilities.

Authors: Steve Morley, Jon Niehof, Brian Larsen, Josef Koller, Dan Welling Institution: Los Alamos National Laboratory Contact:,,,, Los Alamos National Laboratory

Copyright 2010 Los Alamos National Security, LLC.

Array binning

arraybin(array, bins)

Split a sequence into subsequences based on value.


Convert a list of bin centers to their edges


Convert a list of bin edges to their centers

binHisto(data[, verbose])

Calculates bin width and number of bins for histogram using Freedman-Diaconis rule, if rule fails, defaults to square-root method

Array creation

dist_to_list(func, length[, min, max])

Convert a probability distribution function to a list of values

geomspace(start[, ratio, stop, num])

Returns geometrically spaced numbers.

linspace(min, max, num, **kwargs)

Returns linear-spaced bins.

logspace(min, max, num, **kwargs)

Returns log-spaced bins.

Array searching and masking

interweave(a, b)

given two array-like variables interweave them together.

isview(array1[, array2])

Returns if an object is a view of another object.

tCommon(ts1, ts2[, mask_only])

Finds the elements in a list of datetime objects present in another

tOverlap(ts1, ts2, *args, **kwargs)

Finds the overlapping elements in two lists of datetime objects

tOverlapHalf(ts1, ts2[, presort])

Find overlapping elements in two lists of datetime objects

Other functions

assemble(fln_pattern, outfln[, sortkey, verbose])

assembles all pickled files matching fln_pattern into single file and save as outfln.

bootHisto(data[, inter, n, seed, plot, ...])

Bootstrap confidence intervals for a histogram.

dictree(in_dict[, verbose, spaces, levels, ...])

pretty print a dictionary tree

eventTimer(Event, Time1)

Times an event then prints out the time and the name of the event, nice for debugging and seeing that the code is progressing


Return the full path of a parent directory with name as the leaf


Sort the given list in the way that humans expect.


compute the N-dimensional hypot of an iterable or many arguments


return the start and end indices implied by an xrange, useful when xrange is zero-length

interpol(newx, x, y[, wrap])

1-D linear interpolation with interpolation of hours/longitude

intsolve(func, value[, start, stop, maxit])

Find the function input such that definite integral is desired value.

medAbsDev(series[, scale])

Calculate median absolute deviation of a given input series

mlt2rad(mlt[, midnight])

Convert mlt values to radians for polar plotting transform mlt angles to radians from -pi to pi referenced from noon by default

normalize(vec[, low, high])

Given an input vector normalize the vector to a given range


print min and max of input arrays

poisson_fit(data[, initial, method])

Fit a Poisson distribution to data using the method and initial guess provided.

rad2mlt(rad[, midnight])

Convert radians values to mlt transform radians from -pi to pi to mlt referenced from noon by default

windowMean(data[, time, winsize, overlap, ...])

Windowing mean function, window overlap is user defined

Multithreading and multiprocessing

thread_job(job_size, thread_count, target, ...)

Split a job into subjobs and run a thread for each

thread_map(target, iterable[, thread_count])

Apply a function to every element of a list, in separate threads

System tools

do_with_timeout(timeout, target, *args, **kwargs)

Execute a function (or method) with a timeout.

get_url(url[, outfile, reporthook, cached, ...])

Read data from a URL


load a pickle and return content as dictionary

progressbar(count, blocksize, totalsize[, text])

print a progress bar with urllib.urlretrieve reporthook functionality

query_yes_no(question[, default])

Ask a yes/no question via raw_input() and return their answer.

savepickle(fln, dict[, compress])

save dictionary variable dict to a pickle with filename fln

timeout_check_call(timeout, *args, **kwargs)

Call a subprocess with a timeout.


Raised when a time-limited process times out

update([all, QDomni, omni, omni2, leapsecs, ...])

Download and update local database for omni, leapsecs etc