@@ -22,6 +22,7 @@ def cli(ctx):
2222 '''
2323 pass
2424
25+
2526@cli .command ("plot" )
2627@click .option ("-n" , "--name" , default = "noise" ,
2728 help = "The test name" )
@@ -37,7 +38,6 @@ def plot(ctx, name, datafile, output):
3738 fp = ario .load (datafile )
3839 with plottools .pages (output ) as out :
3940 mod .plot (fp , out )
40-
4141
4242
4343def ssss_args (func ):
@@ -53,8 +53,11 @@ def ssss_args(func):
5353 @functools .wraps (func )
5454 def wrapper (* args , ** kwds ):
5555
56- kwds ["splat" ] = ssss .load_frame (kwds .pop ("splat" ))
57- kwds ["signal" ] = ssss .load_frame (kwds .pop ("signal" ))
56+ kwds ["splat_filename" ] = kwds .pop ("splat" )
57+ kwds ["signal_filename" ] = kwds .pop ("signal" )
58+
59+ kwds ["splat" ] = ssss .load_frame (kwds ["splat_filename" ])
60+ kwds ["signal" ] = ssss .load_frame (kwds ["signal_filename" ])
5861
5962 channel_ranges = kwds .pop ("channel_ranges" )
6063 if channel_ranges :
@@ -74,6 +77,8 @@ def plot_ssss(channel_ranges, nsigma, nbins, splat, signal, output,
7477 Perform the simple splat / sim+signal process comparison test and make plots.
7578 '''
7679
80+ nminsig = 3 # sanity check
81+
7782 with pages (output ) as out :
7883
7984 ssss .plot_frames (splat , signal , channel_ranges , title )
@@ -100,6 +105,13 @@ def plot_ssss(channel_ranges, nsigma, nbins, splat, signal, output,
100105
101106 spl_qch = numpy .sum (spl .activity [bbox ], axis = 1 )
102107 sig_qch = numpy .sum (sig .activity [bbox ], axis = 1 )
108+
109+ nspl = len (spl_qch )
110+ nsig = len (sig_qch )
111+ if nspl != nsig or nsig < nminsig :
112+ log .error (f'error: bad signals: { nspl = } { nsig = } { pln = } { ch = } ' )
113+ raise ValueError (f'bad signals: { nspl = } { nsig = } ' )
114+
103115 byplane .append ((spl_qch , sig_qch ))
104116
105117
@@ -132,7 +144,14 @@ def ssss_metrics(channel_ranges, nsigma, nbins, splat, signal, output, params, *
132144 spl_qch = numpy .sum (spl .activity [bbox ], axis = 1 )
133145 sig_qch = numpy .sum (sig .activity [bbox ], axis = 1 )
134146
135- m = ssss .calc_metrics (spl_qch , sig_qch , nbins )
147+ try :
148+ m = ssss .calc_metrics (spl_qch , sig_qch , nbins )
149+ except Exception as err :
150+ splat_filename = kwds ['splat_filename' ]
151+ signal_filename = kwds ['signal_filename' ]
152+ log .error (f'error: ({ err } ) failed to calculate metrics for { pln = } { ch = } { splat_filename = } { signal_filename = } ' )
153+ m = ssss .Metrics ()
154+
136155 metrics .append (dataclasses .asdict (m ))
137156
138157 if params :
@@ -149,8 +168,10 @@ def ssss_metrics(channel_ranges, nsigma, nbins, splat, signal, output, params, *
149168 help = "PDF file in which to plot metrics" )
150169@click .option ("--coordinate-plane" , default = None , type = int ,
151170 help = "Use given plane number as global coordinates plane, default uses per-plane coordinates" )
171+ @click .option ("-t" ,"--title" , default = "" ,
172+ help = "The title string" )
152173@click .argument ("files" ,nargs = - 1 )
153- def plot_metrics (output , coordinate_plane , files ):
174+ def plot_metrics (output , coordinate_plane , title , files ):
154175 '''Plot per-plane metrics from files.
155176
156177 Files are as produced by ssss-metrics and must include a "params" key.
@@ -176,9 +197,15 @@ def add(k,v):
176197
177198 pmet = met [plane ]
178199 add ('ineff' , pmet ['ineff' ])
179- add ('bias' , pmet ['fit' ]['avg' ])
180- hi = pmet ['fit' ]['hi' ]
181- lo = pmet ['fit' ]['lo' ]
200+ fit = pmet ['fit' ]
201+ if fit is None :
202+ add ('bias' , 1 ) # fixme: best way to show failure?
203+ add ('reso' , 1 )
204+ continue
205+
206+ add ('bias' , fit ['avg' ])
207+ hi = fit ['hi' ]
208+ lo = fit ['lo' ]
182209 add ('reso' , 0.5 * (hi + lo ) )
183210 continue ;
184211
@@ -193,9 +220,15 @@ def add(k,v):
193220 add ('ty' , par ['theta_y_wps' ][plane ])
194221 add ('txz' , par ['theta_xz_wps' ][plane ])
195222 add ('ineff' , pmet ['ineff' ])
196- add ('bias' , pmet ['fit' ]['avg' ])
197- hi = pmet ['fit' ]['hi' ]
198- lo = pmet ['fit' ]['lo' ]
223+ fit = pmet ['fit' ]
224+ if fit is None :
225+ add ('bias' , 1 ) # fixme: best way to show failure?
226+ add ('reso' , 1 )
227+ continue
228+
229+ add ('bias' , fit ['avg' ])
230+ hi = fit ['hi' ]
231+ lo = fit ['lo' ]
199232 add ('reso' , 0.5 * (hi + lo ) )
200233
201234
@@ -207,11 +240,13 @@ def add(k,v):
207240 pcolors = ('#58D453' , '#7D99D1' , '#D45853' )
208241
209242 fig , axes = plt .subplots (nrows = 3 , ncols = 1 , sharex = True )
243+ if title :
244+ title = ' - ' + title
210245 if coordinate_plane is None :
211- fig .suptitle ("Per-plane angles" )
246+ fig .suptitle ("Per-plane angles" + title )
212247 else :
213248 letter = "UVW" [coordinate_plane ]
214- fig .suptitle (f'Global angles ({ letter } -plane)' )
249+ fig .suptitle (f'Global angles ({ letter } -plane)' + title )
215250
216251 todeg = 180 / numpy .pi
217252 # xlabs = [f'{txz}/{ty}' for txz,ty in zip(
0 commit comments