Package drivers :: Package GEN :: Module plot_file
[hide private]
[frames] | no frames]

Source Code for Module drivers.GEN.plot_file

  1  #                  High-Level Reduction Functions 
  2  #           A part of the SNS Analysis Software Suite. 
  3  # 
  4  #                  Spallation Neutron Source 
  5  #          Oak Ridge National Laboratory, Oak Ridge TN. 
  6  # 
  7  # 
  8  #                             NOTICE 
  9  # 
 10  # For this software and its associated documentation, permission is granted 
 11  # to reproduce, prepare derivative works, and distribute copies to the public 
 12  # for any purpose and without fee. 
 13  # 
 14  # This material was prepared as an account of work sponsored by an agency of 
 15  # the United States Government.  Neither the United States Government nor the 
 16  # United States Department of Energy, nor any of their employees, makes any 
 17  # warranty, express or implied, or assumes any legal liability or 
 18  # responsibility for the accuracy, completeness, or usefulness of any 
 19  # information, apparatus, product, or process disclosed, or represents that 
 20  # its use would not infringe privately owned rights. 
 21  # 
 22   
 23  # $Id: plot_file.py 2546 2008-10-14 19:03:14Z 2zr $ 
 24   
 25  """ 
 26  This programs plots data files handled or produced by data reduction.  
 27  """ 
 28   
29 -def run(config):
30 """ 31 This method is where the data reduction process gets done. 32 33 @param config: Object containing the data reduction configuration 34 information. 35 @type config: L{hlr_utils.Configure} 36 """ 37 import dr_lib 38 39 if config.data is None: 40 raise RuntimeError("Need to pass a data filename(s) to the driver "\ 41 +"script.") 42 43 dst_type = hlr_utils.file_peeker(config.data[0]) 44 45 if config.verbose: 46 print "Initial file type (data set):", dst_type 47 48 d_som = dr_lib.add_files(config.data, dst_type=dst_type, 49 Signal_ROI=config.roi_file, 50 Verbose=config.verbose) 51 52 if dst_type == "text/Spec": 53 __plot_a3c(d_som, config) 54 elif dst_type == "text/Dave2d": 55 if config.projx: 56 drplot.plot_1D_slice(d_som, "y", config.range, (None, None), 57 logx=config.logx, logy=config.logy, 58 line=config.line) 59 elif config.projy: 60 drplot.plot_1D_slice(d_som, "x", (None, None), config.range, 61 logx=config.logx, logy=config.logy, 62 line=config.line) 63 elif config.slicex: 64 drplot.plot_1D_slices(d_som, "y", config.range, 65 logx=config.logx, logy=config.logy, 66 line=config.line) 67 elif config.slicey: 68 drplot.plot_1D_slices(d_som, "x", config.range, 69 logx=config.logx, logy=config.logy, 70 line=config.line) 71 else: 72 drplot.plot_2D_so(d_som, logz=config.logz, box=config.box) 73 elif dst_type == "text/num-info": 74 drplot.plot_numinfo(d_som) 75 else: 76 raise RuntimeError("Do not know how to plot file type %s" % dst_type) 77 78 pylab.show()
79
80 -def __plot_a3c(som, conf):
81 """ 82 This subroutine is responsible for plotting a 3-column ASCII file. 83 """ 84 len_som = len(som) 85 86 if len_som > 1: 87 # Get the number of figures needed 88 num_figs = len_som / 10 + 1 89 # Get left over plots if length isn't evenly divisible 90 left_over = len_som % 10 91 else: 92 num_figs = 1 93 left_over = 1 94 95 for i in xrange(num_figs): 96 if len_som > 1: 97 pylab.figure(i+1) 98 if i+1 == num_figs: 99 extent = left_over 100 else: 101 extent = 10 102 103 for j in xrange(extent): 104 if len_som > 1: 105 pylab.subplot(2, 5, j+1) 106 index = (i*10) + j 107 108 pid = som[index].id 109 110 try: 111 drplot.plot_1D_so(som, pid, title=pid, logy=conf.logy, 112 logx=conf.logx, line=conf.line) 113 except ValueError: 114 # All data got filtered 115 pass
116 117 if __name__ == "__main__": 118 import drplot 119 import hlr_utils 120 121 import pylab 122 123 # Make description for driver 124 description = [] 125 description.append("") 126 127 # Set up the options available 128 parser = hlr_utils.BasicOptions("usage: %prog [options]", None, None, 129 hlr_utils.program_version(), 'error', 130 " ".join(description)) 131 132 parser.add_option("", "--roi-file", dest="roi_file", 133 help="Specify a file that contains a list of pixel "\ 134 +"ids to be read from the data") 135 136 parser.add_option("", "--logy", dest="logy", action="store_true", 137 help="Set the y-axis to logarithmic scale.") 138 parser.set_defaults(logy=False) 139 140 parser.add_option("", "--logx", dest="logx", action="store_true", 141 help="Set the x-axis to logarithmic scale.") 142 parser.set_defaults(logx=False) 143 144 parser.add_option("", "--logz", dest="logz", action="store_true", 145 help="Set the z-axis to logarithmic scale.") 146 parser.set_defaults(logz=False) 147 148 parser.add_option("", "--projx", dest="projx", action="store_true", 149 help="Project a 2D distribution along x.") 150 parser.set_defaults(projx=False) 151 152 parser.add_option("", "--projy", dest="projy", action="store_true", 153 help="Project a 2D distribution along y.") 154 parser.set_defaults(projy=False) 155 156 parser.add_option("", "--range", dest="range", type="float", nargs=2, 157 help="Set the range to filter on the opposite "\ 158 +"axis when projecting or slicing a 2D distribution.") 159 160 parser.add_option("", "--slicex", dest="slicex", action="store_true", 161 help="Show x distributions for each y from a 2D "\ 162 +"distribution.") 163 parser.set_defaults(slicex=False) 164 165 parser.add_option("", "--slicey", dest="slicey", action="store_true", 166 help="Show y distributions for each x from a 2D "\ 167 +"distribution.") 168 parser.set_defaults(slicey=False) 169 170 parser.add_option("-l", "--line", dest="line", action="store_true", 171 help="Draw a line connecting points for 1D plots.") 172 173 parser.add_option("-b", "--box", dest="box", action="store_true", 174 help="Plot 2D distribution as a box plot.") 175 parser.set_defaults(box=False) 176 177 # Do not need to use the following options 178 parser.remove_option("--config") 179 parser.remove_option("--data") 180 parser.remove_option("--output") 181 182 (options, args) = parser.parse_args() 183 184 # set up the configuration 185 configure = hlr_utils.Configure() 186 187 # Need to set the inst parameter to None to spoof data file finder 188 configure.inst = None 189 190 # Need to set the facility parameter to None to spoof data file finder 191 configure.facility = None 192 193 # Temporarily silence verbosity 194 old_verbosity = options.verbose 195 options.verbose = False 196 197 # Call the configuration setter for SNSOptions 198 hlr_utils.BasicConfiguration(parser, configure, options, args) 199 200 # Reset verbosity 201 configure.verbose = old_verbosity 202 203 # Set the ROI file 204 configure.roi_file = hlr_utils.determine_files(options.roi_file, 205 one_file=True) 206 207 # Set the logarithmic y-axis 208 configure.logy = options.logy 209 210 # Set the logarithmic x-axis 211 configure.logx = options.logx 212 213 # Set the logarithmic z-axis 214 configure.logz = options.logz 215 216 # Set the flag to project to the x-axis 217 configure.projx = options.projx 218 219 # Set the flag to project to the y-axis 220 configure.projy = options.projy 221 222 # Set the range for filtering the opposite axis for the chosen projection 223 # or slicing scheme 224 if options.range is None: 225 configure.range = (None, None) 226 else: 227 configure.range = options.range 228 229 # Set the flag to make slices along the y-axis 230 configure.slicex = options.slicex 231 232 # Set the flag to make slices along the x-axis 233 configure.slicey = options.slicey 234 235 # Set the flag for a connecting line in 1D plots 236 configure.line = options.line 237 238 # Set the flag to make a 2D box plot 239 configure.box = options.box 240 241 # Run the program 242 run(configure) 243