ImgPixSpectra/data/MergeArrays.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 import sys
00003 
00004 import h5py
00005 import numpy as np
00006 import time
00007 
00008 #---------------------------------------------------
00009 def get_list_of_input_file_names() :
00010     """Returns the list of files with 2-d arrays which need to be summed."""
00011 
00012     list_of_files = [
00013     #'spv2-cxi49812-r0200-ev-000000-042962.np',
00014     #'spv2-cxi49812-r0201-ev-000000-015990.np',
00015     'spv2-cxi49812-r0202-ev-000000-040336.np',
00016     'spv2-cxi49812-r0203-ev-000000-010197.np',
00017     'spv2-cxi49812-r0204-ev-000000-066368.np',
00018     'spv2-cxi49812-r0205-ev-000000-032111.np',
00019     'spv2-cxi49812-r0206-ev-000000-073412.np',
00020     'spv2-cxi49812-r0207-ev-000000-029735.np']
00021     #'spv2-cxi49812-r0208-ev-000000-035901.np',
00022     #'spv2-cxi49812-r0209-ev-000000-027595.np',
00023     #'spv2-cxi49812-r0210-ev-000000-034038.np',
00024     #'spv2-cxi49812-r0211-ev-000000-015550.np',
00025     #'spv2-cxi49812-r0212-ev-000000-047923.np',
00026     #'spv2-cxi49812-r0213-ev-000000-022799.np',
00027     #'spv2-cxi49812-r0214-ev-000000-025638.np']
00028 
00029     print 'list_of_files = ', list_of_files
00030     return list_of_files
00031 
00032 #---------------------------------------------------
00033 
00034 def print_time_stamp() :
00035     """Prints the current local time.""" 
00036     tloc   = time.localtime(time.time())
00037     tstamp = time.strftime('%Y-%m-%d %H:%M',tloc)
00038     print 'Local time:', tstamp
00039     #tstart0= time.time()
00040 
00041 #---------------------------------------------------
00042 
00043 def spectra_merging(out_fname='sum-of-spectra.np') :
00044     """Merging of spectral arrays.
00045 
00046     1. Get the list of files for merging from get_list_of_input_file_names()
00047     2. Add the spectral 2d arrays together
00048     3. Save them in the file out_fname
00049     """
00050 
00051     list_of_files = get_list_of_input_file_names()
00052     print_time_stamp()
00053     spectra_sum = None
00054 
00055     for fname in list_of_files :
00056         spectra = np.fromfile(fname, dtype=np.int16)
00057         print 'Read spectrum from the file :', fname,  
00058         print ' shape :', spectra.shape  
00059 
00060         if  spectra_sum == None :
00061             spectra_sum  = spectra
00062         else :
00063             spectra_sum += spectra
00064 
00065     spectra_sum.tofile(out_fname)
00066  
00067     print 'The merged spectral array is saved in the file =', out_fname
00068 
00069 #---------------------------------------------------
00070 
00071 if __name__ == "__main__" :
00072 
00073     spectra_merging(out_fname = 'sum-2d-arr.np')
00074     sys.exit ( 'End of job' )
00075 
00076 #---------------------------------------------------

Generated on 19 Dec 2016 for PSANAmodules by  doxygen 1.4.7