# 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: smorley@lanl.gov, jniehof@lanl.gov, balarsen@lanl.gov, jkoller@lanl.gov, dwelling@lanl.gov Los Alamos National Laboratory

Copyright 2010 Los Alamos National Security, LLC.

- Array binning

- Array creation

- Array searching and masking

- Other functions

- Multithreading and multiprocessing

- System tools

- Quaternion math

## Array binning

`arraybin`(array, bins) | Split a sequence into subsequences based on value.
`bin_center_to_edges`(centers) | Convert a list of bin centers to their edges
`bin_edges_to_center`(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
`feq`(x, y[, precision]) | compare two floating point values if they are equal after: http://www.lahey.com/float.htm
`getNamedPath`(name) | Return the full path of a parent directory with name as the leaf
`human_sort`(l) | Sort the given list in the way that humans expect.
`hypot`(*args) | compute the N-dimensional hypot of an iterable or many arguments
`indsFromXrange`(inxrange) | 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
`pmm`(*args) | 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
`loadpickle`(fln) | 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.
`TimeoutError` | Raised when a time-limited process times out
`update`([all, QDomni, omni, omni2, leapsecs, …]) | Download and update local database for omni, leapsecs etc

## Quaternion math

Quaternion functions have moved to `coordinates`; new functions are also added there.

`quaternionRotateVector`(Qin, Vin[, …]) | Given quaternion and vector, return vector rotated by quaternion.
`quaternionNormalize`(Qin[, scalarPos]) | Given an input quaternion, return the unit quaternion.
`quaternionMultiply`(Qin1, Qin2[, scalarPos]) | Given quaternions, return the product.
`quaternionConjugate`(Qin[, scalarPos]) | Given an input quaternion, return the conjugated.