CSPadPixCoords/data/PlotCameraImageFromFile.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #--------------------
00003 
00004 import numpy as np
00005 import matplotlib.pyplot as plt
00006 import sys
00007 import h5py
00008 
00009 #--------------------
00010 # Define graphical methods
00011 
00012 def plot_image (arr, range=None, zrange=None) :    # range = (left, right, low, high), zrange=(zmin,zmax)
00013     fig = plt.figure(num=1, figsize=(12,12), dpi=80, facecolor='w',edgecolor='w',frameon=True)
00014     fig.subplots_adjust(left=0.10, bottom=0.08, right=0.98, top=0.92, wspace=0.2, hspace=0.1)
00015     figAxes = fig.add_subplot(111)
00016     imAxes = figAxes.imshow(arr, origin='upper', interpolation='nearest', aspect='auto',extent=range)
00017     #imAxes.set_clim(1300,2000)
00018     if zrange != None : imAxes.set_clim(zrange[0],zrange[1])
00019     colbar = fig.colorbar(imAxes, pad=0.03, fraction=0.04, shrink=1.0, aspect=40, orientation=1)
00020 
00021 def plot_histogram(arr,range=(0,500),figsize=(5,5)) :
00022     fig = plt.figure(figsize=figsize, dpi=80, facecolor='w',edgecolor='w',frameon=True)
00023     plt.hist(arr.flatten(), bins=100, range=range)
00024     #fig.canvas.manager.window.move(500,10)
00025     
00026 #--------------------
00027 
00028 def get_array_from_file(fname) :
00029     print 'get_array_from_file:', fname
00030     return np.loadtxt(fname, dtype=np.float32)
00031 
00032 #--------------------
00033 
00034 def get_input_parameters() :
00035 
00036     fname_def = './image0_ev000115.txt'
00037     Amin_def  =   0
00038     Amax_def  = 100
00039 
00040     nargs = len(sys.argv)
00041     print 'sys.argv[0]: ', sys.argv[0]
00042     print 'nargs: ', nargs
00043 
00044     if nargs == 1 :
00045         print 'Will use all default parameters\n',\
00046               'Expected command: ' + sys.argv[0] + ' <infname> <Amin> <Amax>' 
00047         sys.exit('CHECK INPUT PARAMETERS!')
00048 
00049     if nargs  > 1 : fname = sys.argv[1]
00050     else          : fname = fname_def
00051 
00052     if nargs  > 2 : Amin = int(sys.argv[2])
00053     else          : Amin = Amin_def
00054 
00055     if nargs  > 3 : Amax = int(sys.argv[3])
00056     else          : Amax = Amax_def
00057 
00058     if nargs  > 4 :         
00059         print 'WARNING: Too many input arguments! Exit program.\n'
00060         sys.exit('CHECK INPUT PARAMETERS!')
00061 
00062     ampRange = (Amin, Amax)
00063 
00064     print 'Input file name  :', fname
00065     print 'ampRange         :', ampRange
00066  
00067     return fname,ampRange 
00068 
00069 #--------------------
00070 
00071 def do_main() :
00072 
00073     fname, ampRange = get_input_parameters()
00074     arr = get_array_from_file(fname) 
00075     print 'arr:\n', arr
00076     print 'arr.shape=', arr.shape
00077 
00078     plot_image(arr, zrange=ampRange)
00079     plt.get_current_fig_manager().window.move(10,10)
00080 
00081     plot_histogram(arr,range=ampRange)
00082     plt.get_current_fig_manager().window.move(950,10)
00083 
00084     plt.show()
00085 
00086 #--------------------
00087 
00088 if __name__ == '__main__' :
00089     do_main()
00090     sys.exit('The End')
00091 
00092 #--------------------

Generated on 19 Dec 2016 for PSANAmodules by  doxygen 1.4.7