Mercurial > hg > numerics
changeset 87:8448c62a4917
almost to output; frange done
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sun, 01 Mar 2015 17:47:22 -0800 |
parents | fa23c078b928 |
children | 8ad844281bf8 |
files | numerics/generate.py numerics/histogram.py tests/test_generate.py |
diffstat | 3 files changed, 43 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/numerics/generate.py Sun Mar 01 17:01:38 2015 -0800 +++ b/numerics/generate.py Sun Mar 01 17:47:22 2015 -0800 @@ -7,6 +7,8 @@ rather than rolling our own. Bootstrapping... """ +__all__ = ['frange'] + def frange(xmin, xmax, n): """ float range @@ -16,4 +18,5 @@ n -- number of slices (one less than number of points) """ dx = (xmax - xmin)/float(n) - raise NotImplementedError('TODO') # -> record TODO items + retval = [xmin+dx*i for i in range(0,n)] + retval.append(xmax)
--- a/numerics/histogram.py Sun Mar 01 17:01:38 2015 -0800 +++ b/numerics/histogram.py Sun Mar 01 17:47:22 2015 -0800 @@ -24,6 +24,7 @@ import sys import time from .data import transpose +from .generate import frange from .read import CSVParser from collections import OrderedDict @@ -119,8 +120,17 @@ # We'll use a guess of 2 items per bin, on average options.nbins = len(columns[0]) / 2 + # make some bins + bins = frange(options.min, options.max, options.nbins) + # make some histograms + histograms = [] + for column in columns: + histogram = Histogram(bins) + histogram.add(*column) + # output delimeters + data = histograms[0].keys() if __name__ == '__main__': main()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_generate.py Sun Mar 01 17:47:22 2015 -0800 @@ -0,0 +1,29 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +unit tests for generate +""" + +import os +import sys +import tempfile +import unittest + +# globals +here = os.path.dirname(os.path.abspath(__file__)) + +class generateUnitTest(unittest.TestCase): + + def test_generate(self): + tf = tempfile.mktemp() + try: + # pass + pass + finally: + if os.path.exists(tf): + os.remove(tf) + +if __name__ == '__main__': + unittest.main() +