annotate numerics/reduce.py @ 150:8a1fe454c98a

STUB
author Jeff Hammel <k0scist@gmail.com>
date Mon, 13 Apr 2015 10:17:47 -0700
parents c9ae21955ca5
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
124
84baf80a5202 stubbing massive deletion of code (okay not that massive)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
84baf80a5202 stubbing massive deletion of code (okay not that massive)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
84baf80a5202 stubbing massive deletion of code (okay not that massive)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
3
84baf80a5202 stubbing massive deletion of code (okay not that massive)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
4 """
84baf80a5202 stubbing massive deletion of code (okay not that massive)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
5 reduce a vector to a scalar
84baf80a5202 stubbing massive deletion of code (okay not that massive)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
6 """
84baf80a5202 stubbing massive deletion of code (okay not that massive)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
7
84baf80a5202 stubbing massive deletion of code (okay not that massive)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
8 # imports
84baf80a5202 stubbing massive deletion of code (okay not that massive)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
9 import sys
125
d255058333b2 putzing
Jeff Hammel <k0scist@gmail.com>
parents: 124
diff changeset
10 from .filters import mean
d255058333b2 putzing
Jeff Hammel <k0scist@gmail.com>
parents: 124
diff changeset
11 from .manipulate import FloatParser
d255058333b2 putzing
Jeff Hammel <k0scist@gmail.com>
parents: 124
diff changeset
12 from .write import CSVWriter
124
84baf80a5202 stubbing massive deletion of code (okay not that massive)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
13
84baf80a5202 stubbing massive deletion of code (okay not that massive)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
14 # module globals
125
d255058333b2 putzing
Jeff Hammel <k0scist@gmail.com>
parents: 124
diff changeset
15 __all__ = ['ReduceParser']
124
84baf80a5202 stubbing massive deletion of code (okay not that massive)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
16
84baf80a5202 stubbing massive deletion of code (okay not that massive)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
17
126
575c8e44227c this should work and shit
Jeff Hammel <k0scist@gmail.com>
parents: 125
diff changeset
18 class ReduceParser(FloatParser):
124
84baf80a5202 stubbing massive deletion of code (okay not that massive)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
19 """CLI option parser"""
126
575c8e44227c this should work and shit
Jeff Hammel <k0scist@gmail.com>
parents: 125
diff changeset
20
127
c9ae21955ca5 how to make this really small
Jeff Hammel <k0scist@gmail.com>
parents: 126
diff changeset
21 def __init__(self, function, **kwargs):
c9ae21955ca5 how to make this really small
Jeff Hammel <k0scist@gmail.com>
parents: 126
diff changeset
22 """
c9ae21955ca5 how to make this really small
Jeff Hammel <k0scist@gmail.com>
parents: 126
diff changeset
23 function -- reducing function
c9ae21955ca5 how to make this really small
Jeff Hammel <k0scist@gmail.com>
parents: 126
diff changeset
24 """
126
575c8e44227c this should work and shit
Jeff Hammel <k0scist@gmail.com>
parents: 125
diff changeset
25
127
c9ae21955ca5 how to make this really small
Jeff Hammel <k0scist@gmail.com>
parents: 126
diff changeset
26 self.function = function
124
84baf80a5202 stubbing massive deletion of code (okay not that massive)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
27 kwargs.setdefault('description', __doc__)
127
c9ae21955ca5 how to make this really small
Jeff Hammel <k0scist@gmail.com>
parents: 126
diff changeset
28 FloatParser.__init__(self, **kwargs)
124
84baf80a5202 stubbing massive deletion of code (okay not that massive)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
29
126
575c8e44227c this should work and shit
Jeff Hammel <k0scist@gmail.com>
parents: 125
diff changeset
30 def __call__(self, *args):
124
84baf80a5202 stubbing massive deletion of code (okay not that massive)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
31
126
575c8e44227c this should work and shit
Jeff Hammel <k0scist@gmail.com>
parents: 125
diff changeset
32 # parse command line options
575c8e44227c this should work and shit
Jeff Hammel <k0scist@gmail.com>
parents: 125
diff changeset
33 self.parse_args(args or sys.argv[1:])
124
84baf80a5202 stubbing massive deletion of code (okay not that massive)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
34
126
575c8e44227c this should work and shit
Jeff Hammel <k0scist@gmail.com>
parents: 125
diff changeset
35 # read data
575c8e44227c this should work and shit
Jeff Hammel <k0scist@gmail.com>
parents: 125
diff changeset
36 columns = self.typed_data()
575c8e44227c this should work and shit
Jeff Hammel <k0scist@gmail.com>
parents: 125
diff changeset
37 if not columns:
575c8e44227c this should work and shit
Jeff Hammel <k0scist@gmail.com>
parents: 125
diff changeset
38 self.error("No data given")
575c8e44227c this should work and shit
Jeff Hammel <k0scist@gmail.com>
parents: 125
diff changeset
39
575c8e44227c this should work and shit
Jeff Hammel <k0scist@gmail.com>
parents: 125
diff changeset
40 # calculate scalars
127
c9ae21955ca5 how to make this really small
Jeff Hammel <k0scist@gmail.com>
parents: 126
diff changeset
41 data = [self.function(column) for column in columns]
126
575c8e44227c this should work and shit
Jeff Hammel <k0scist@gmail.com>
parents: 125
diff changeset
42
575c8e44227c this should work and shit
Jeff Hammel <k0scist@gmail.com>
parents: 125
diff changeset
43 # write CSV
127
c9ae21955ca5 how to make this really small
Jeff Hammel <k0scist@gmail.com>
parents: 126
diff changeset
44 writer = CSVWriter(self.options.output)
126
575c8e44227c this should work and shit
Jeff Hammel <k0scist@gmail.com>
parents: 125
diff changeset
45 writer.write([data])