Commit 621c9c33b2a2071da78689ec0a3d18548358e7a9

Authored by Grizonnet Manuel (CNES)
1 parent d30d3eb5
Exists in develop and in 2 other branches master, utils

WIP: plot histogram utilities

Showing 1 changed file with 66 additions and 0 deletions   Show diff stats
utils/snow_line.py 0 → 100755
... ... @@ -0,0 +1,66 @@
  1 +#!/usr/bin/python
  2 +#coding=utf8
  3 +#=========================================================================
  4 +#
  5 +# Program: lis
  6 +# Language: Python
  7 +#
  8 +# Copyright (c) Simon Gascoin
  9 +# Copyright (c) Manuel Grizonnet
  10 +#
  11 +# See lis-copyright.txt for details.
  12 +#
  13 +# This software is distributed WITHOUT ANY WARRANTY; without even
  14 +# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15 +# PURPOSE. See the above copyright notices for more information.
  16 +#
  17 +#=========================================================================
  18 +
  19 +import numpy as np
  20 +from matplotlib import pyplot as plt
  21 +from optparse import OptionParser
  22 +
  23 +def print_histo(histo_path):
  24 + with open(histo_path) as f:
  25 + v = np.loadtxt(f, delimiter=",", dtype='int', comments="#", skiprows=3, usecols=(0,1,3))
  26 +
  27 + #_hist = np.ravel(v) # 'flatten' v
  28 + #fig = plt.figure()
  29 + #ax1 = fig.add_subplot(111)
  30 +
  31 + #n, bins, patches = ax1.hist(v_hist, bins=50, normed=1, facecolor='green')
  32 + #plt.show()
  33 +
  34 + print v
  35 +
  36 + dem=v[:,0]
  37 + width = 0.8
  38 + #indices = np.arange(len(dem))
  39 +
  40 + plt.bar(dem, v[:,1], width=width, color="red", label="all")
  41 + plt.bar([i+0.25*width for i in dem], v[:,2], width=0.5*width, color="blue", alpha=1. , label="snow")
  42 +
  43 + plt.xticks(dem+width/2.,
  44 + [i for i in dem] )
  45 +
  46 + plt.legend()
  47 + plt.show()
  48 +
  49 +def main():
  50 + parser = OptionParser(usage="usage: %prog [options] filename",
  51 + version="%prog")
  52 +
  53 + parser.add_option("-f","--file", help="absolute path to histogram file", dest="histo_path", type="string")
  54 +
  55 + (opts, args) = parser.parse_args()
  56 +
  57 + if opts.histo_path is None:
  58 + print "A mandatory option is missing\n"
  59 + parser.print_help()
  60 + exit(-1)
  61 + else:
  62 + #print opts.path
  63 + print_histo(opts.histo_path)
  64 +if __name__ == '__main__':
  65 + main()
  66 +
... ...