PageRenderTime 54ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/scripts/getmax.py

https://github.com/Gim6626/casconvection
Python | 66 lines | 55 code | 9 blank | 2 comment | 17 complexity | 648be49688a6646918529c15c2641f87 MD5 | raw file
Possible License(s): GPL-2.0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import os
  4. import sys
  5. from optparse import OptionParser
  6. from libextrema import extremamax
  7. usage = "usage: %prog [options]"
  8. parser = OptionParser(usage = usage)
  9. parser.add_option("-i", "--input", dest="inputfile",
  10. help="input file, two tab separated columns -- x and y",
  11. metavar="INPUT")
  12. parser.add_option("-b", "--bounds", dest="bounds",
  13. help="bounds on x for extremum finding, comma separated list"
  14. + " of two values",
  15. metavar="INPUT")
  16. (options, args) = parser.parse_args()
  17. if options.inputfile == None:
  18. inputfile = sys.stdin
  19. else:
  20. inputfile = open(options.inputfile, 'r')
  21. lower = None
  22. upper = None
  23. if options.bounds != None:
  24. bounds = options.bounds.split(',')
  25. if len(bounds) == 2:
  26. lower = float(bounds[0])
  27. upper = float(bounds[1])
  28. elif len(bounds) == 1:
  29. lower = float(bounds[0])
  30. input = []
  31. for line in inputfile:
  32. input.append([float(i) for i in line.split()])
  33. size = len(input)
  34. if size == 0:
  35. print "Error, input is empty"
  36. os._exit(1)
  37. xvals = []
  38. yvals = []
  39. for i in input:
  40. x = i[0]
  41. y = i[1]
  42. if lower != None and upper != None:
  43. if x < lower or x > upper:
  44. continue
  45. elif lower != None and x < lower:
  46. continue
  47. xvals.append(x)
  48. yvals.append(y)
  49. if len(xvals) == 0:
  50. print "Error, input is empty"
  51. os._exit(1)
  52. from numpy import array
  53. xvals = array(xvals)
  54. yvals = array(yvals)
  55. (indices, values) = extremamax(yvals)
  56. for i in indices:
  57. print xvals[i], yvals[i]