python\_lib

Table of Contents

Description

python\_lib is a series of utilities, that I find useful when doing data analysis. Most of the functions are short but oddly missing, and I found myself writing them over and over again.

A public version can be found on our local git repository.

git clone git://adaptive.cs.unm.edu/python_lib.git

stats

general.py

This contains a number of functions for computing thing I need all the time, like cumulative distribution functions and probability density functions, as well as divergence measures for the dictionaries my ccdf and pdf functions return. Requires numpy and scipy.

power_law.py

A python implementation of the methods described by Aaron Clauset for identifying power laws. Requires numpy and scipy.

plot_utils.py

Mostly this library came out of a need for me to be able to use matpotlib to plot a dictionary, assuming that the keys were \(x\) values and the values were \(y\)'s. I slowly added functions to do this for loglog and semilog plots as well as functions to automatically take a list of data, compute the ccdf and plot it on a loglog plot. Additionally, there are functions which attempt to simplify dual axis plotting in matplotlib. Requires numpy, scipy, and matplotlib

p_utils.py

Some improvements to Python's multiprocessing library. Frankly, parts of this library are broken. The multiprocessing map function does not take the same arguments as the builtin, and doesn't allow lambda functions, and upon failure will usually take the spawing process terminal or interpreter with it. I've tried to rectify some of this by providing a class ePool, which is derived from multiprocessing.Pool. It provides a function emap, which works exactly like the builtin map. There are also functions for parallel reduce, filter, and a number of other builtins. I wrap the creation of the ePool class in the end so you can do something like

import p_utils as p
p.map(my_function, list)

I'd like to provide an asynchronous application decorator as well in the future.

utils.py

Just a few random functions. The most useful of which is probably weighted_random_choice, which takes a dictionary of keys pointing to numeric weight values, and selects a key.

timing.py

This is not my own but rather from Ian Johnson, but it is too awesome not to include. Just a small little library that makes it easy to put timing decorators around functions for evaluation.

gl_windows.py

This was adapted from a class also made by Ian Johnson with a number of improvements. It creates a openGL window for 2 or 3 dimensional data and handles all the rotation, translation, and zooming, with reasonable lighting (sort of) and good smoothing. You can pass a rendering function into the class to draw the scene. Then all you have to worry about is the scene, not the window crap.

nx_opengl.py

A function utilizing gl_windows.py to draw NetworkX graphs.

This document is created using Org-mode and Org-babel. The original plain-text document is available at ben-edwards.org (preview).