Utility Functions

boomslang.Utils.cdf(values)

Returns a boomslang.Line.Line representing the CDF of the list of values given in values.

boomslang.Utils.getBarsFromFile(filename, regex, postFunction=None, autofillXValues=False)

Turns a regularly-structured file into a collection of boomslang.Bar.Bar objects.

For more details on arguments, see getLinesFromFile().

Returns a list of boomslang.Bar.Bar objects.

boomslang.Utils.getLinesFromFile(filename, regex, postFunction=None, autofillXValues=False)

Turn a regularly-structured file into a collection of boomslang.Line.Line objects.

Parses each line in filename using the regular expression regex. By default, the first matching group from the regular expression gives the x-axis value for a set of points and all subsequent matching groups give the y-axis values for each line. If postFunction is not None, it is a function that is applied to the matching groups before they are inserted into the lines. If autofillXValues is True, all matching groups are treated as y-axis values for lines and the x-axis value is the line number, indexed from 0.

Returns a list of boomslang.Line.Line objects.

Example: Suppose I had a file blah.txt that looked like this:

1980 - 1, 2, 3
1981 - 4, 5, 6
1982 - 7, 8, 9

The snippet below shows the result of running boomslang.Utils.getLinesFromFile() on blah.txt:

>>> lines = boomslang.Utils.getLinesFromFile("blah.txt", "(\d+) - (\d+), (\d+), (\d+)")
>>> len(lines)
3
>>> lines[0].xValues
[1980, 1981, 1982]
>>> lines[1].xValues
[1980, 1981, 1982]
>>> lines[2].xValues
[1980, 1981, 1982]
>>> lines[0].yValues
[1, 4, 7]
>>> lines[1].yValues
[2, 5, 8]
>>> lines[1].yValues
[3, 6, 9]
boomslang.Utils.histogram(values, binSize)

Returns a boomslang.Line.Line representing a histogram of the list of values given in values with bin size binSize.