/scripts/getmin.py
Python | 66 lines | 55 code | 9 blank | 2 comment | 17 complexity | 2d6b9201fa5f5cbff7162426fcb75596 MD5 | raw file
Possible License(s): GPL-2.0
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- import os
- import sys
- from optparse import OptionParser
- from libextrema import extremamin
- usage = "usage: %prog [options]"
- parser = OptionParser(usage = usage)
- parser.add_option("-i", "--input", dest="inputfile",
- help="input file, two tab separated columns -- x and y",
- metavar="INPUT")
- parser.add_option("-b", "--bounds", dest="bounds",
- help="bounds on x for extremum finding, comma separated list"
- + " of two values",
- metavar="INPUT")
- (options, args) = parser.parse_args()
- if options.inputfile == None:
- inputfile = sys.stdin
- else:
- inputfile = open(options.inputfile, 'r')
- lower = None
- upper = None
- if options.bounds != None:
- bounds = options.bounds.split(',')
- if len(bounds) == 2:
- lower = float(bounds[0])
- upper = float(bounds[1])
- elif len(bounds) == 1:
- lower = float(bounds[0])
- input = []
- for line in inputfile:
- input.append([float(i) for i in line.split()])
- size = len(input)
- if size == 0:
- print "Error, input is empty"
- os._exit(1)
- xvals = []
- yvals = []
- for i in input:
- x = i[0]
- y = i[1]
- if lower != None and upper != None:
- if x < lower or x > upper:
- continue
- elif lower != None and x < lower:
- continue
- xvals.append(x)
- yvals.append(y)
- if len(xvals) == 0:
- print "Error, input is empty"
- os._exit(1)
- from numpy import array
- xvals = array(xvals)
- yvals = array(yvals)
- (indices, values) = extremamin(yvals)
- for i in indices:
- print xvals[i], yvals[i]