casconvection /scripts/getpeakrange.py

Language Python Lines 57
MD5 Hash 9a9553f5b4b309ae9d21c96ed33fca94
Repository https://github.com/Gim6626/casconvection.git View Raw File View Project SPDX
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
from optparse import OptionParser
from libextrema import extremamax

usage = "usage: %prog [options] LOWERBOUND UPPERBOUND"
parser = OptionParser(usage = usage)
parser.add_option("-i", "--input", dest="inputfile",
                  help="input file, two tab separated columns -- xvals and yvals",
                  metavar="INPUT")
(options, args) = parser.parse_args()

if options.inputfile == None:
    inputfile = sys.stdin
else:
    inputfile = open(options.inputfile, 'r')

if len(args) != 2:
    parser.print_usage()
    os._exit(1)

lower = float(args[0])
upper = float(args[1])

xvals = []
yvals = []
for line in inputfile:
    vals = [float(i) for i in line.split()]
    x = vals[0]
    y = vals[1]
    if x >= lower and x <= upper:
        xvals.append(x)
        yvals.append(y)

size = len(xvals)

if size == 0:
    print "Error, input is empty"
    os._exit(1)

from numpy import array
xvals = array(xvals)
yvals = array(yvals)
(indices, values) = extremamax(yvals)
prev = None
for i in indices:
    cur = i
    if prev == None:
        print '{0}\t\t{1}'.format(xvals[cur], yvals[cur])
    else:
        print '{0}\t{1}\t{2}'.format(xvals[cur], xvals[cur] - xvals[prev],
                                     yvals[cur])
    prev = i
Back to Top