@@ -204,10 +204,23 @@ def parse_arguments(progname='requake'):
204
204
'config file. Specify FREQ_MIN and FREQ_MAX in Hz.'
205
205
)
206
206
# ---
207
+ # --- parent parser for saving plots to file instead of showing
208
+ # them on screen
209
+ output = argparse .ArgumentParser (add_help = False )
210
+ output .add_argument (
211
+ '-o' , '--output' , type = str , default = 'NO_OUTPUT' , nargs = '?' ,
212
+ metavar = 'FILE_OR_FORMAT' ,
213
+ help = 'Save the plot instead of displaying it. Provide a filename '
214
+ '(e.g., "plot.png") to specify the output name and format, or '
215
+ 'just a format (e.g., "png", "pdf", "svg") to automatically '
216
+ 'generate a default filename. If omitted, the plot is saved as '
217
+ 'a PNG file with a default name.'
218
+ )
219
+ # ---
207
220
# --- plot_pair
208
221
plot_pair = subparser .add_parser (
209
222
'plot_pair' ,
210
- parents = [traceid , freq_band ],
223
+ parents = [traceid , freq_band , output ],
211
224
help = 'plot traces for a given event pair'
212
225
)
213
226
plot_pair .add_argument ('evid1' )
@@ -309,37 +322,37 @@ def parse_arguments(progname='requake'):
309
322
)
310
323
# ---
311
324
# --- print_families
312
- printfamilies = subparser .add_parser (
325
+ print_families = subparser .add_parser (
313
326
'print_families' ,
314
327
parents = [
315
328
longerthan , shorterthan , minevents , family_numbers , print_format
316
329
],
317
330
help = 'print families to screen'
318
331
)
319
- printfamilies .add_argument (
332
+ print_families .add_argument (
320
333
'-d' , '--detailed' , action = 'store_true' ,
321
334
help = 'print detailed information for each family, including a list '
322
335
'of events'
323
336
)
324
337
# ---
325
338
# --- plot_families
326
- plotfamilies = subparser .add_parser (
339
+ plot_families = subparser .add_parser (
327
340
'plot_families' ,
328
341
parents = [
329
342
longerthan , shorterthan , minevents , family_numbers ,
330
- traceid , freq_band
343
+ traceid , freq_band , output
331
344
],
332
345
help = 'plot traces for one ore more event families'
333
346
)
334
- plotfamilies .add_argument (
347
+ plot_families .add_argument (
335
348
'-s' , '--starttime' , type = float , default = None ,
336
349
help = 'start time, in seconds relative to trace start, for the plot'
337
350
)
338
- plotfamilies .add_argument (
351
+ plot_families .add_argument (
339
352
'-e' , '--endtime' , type = float , default = None ,
340
353
help = 'end time, in seconds relative to trace start, for the plot'
341
354
)
342
- plotfamilies .add_argument (
355
+ plot_families .add_argument (
343
356
'-T' , '--template' , action = 'store_true' ,
344
357
help = 'plot family members found with template scan'
345
358
)
@@ -349,7 +362,7 @@ def parse_arguments(progname='requake'):
349
362
'plot_timespans' ,
350
363
parents = [
351
364
longerthan , shorterthan , minevents , family_numbers , colorby ,
352
- colormap , color_range
365
+ colormap , color_range , output
353
366
],
354
367
help = 'plot family timespans'
355
368
)
@@ -369,7 +382,7 @@ def parse_arguments(progname='requake'):
369
382
'plot_cumulative' ,
370
383
parents = [
371
384
longerthan , shorterthan , minevents , family_numbers , colorby ,
372
- colormap , color_range
385
+ colormap , color_range , output
373
386
],
374
387
help = 'cumulative plot for one or more families'
375
388
)
@@ -390,7 +403,7 @@ def parse_arguments(progname='requake'):
390
403
'map_families' ,
391
404
parents = [
392
405
longerthan , shorterthan , minevents , family_numbers , colorby ,
393
- colormap , color_range
406
+ colormap , color_range , output
394
407
],
395
408
help = 'plot families on a map'
396
409
)
0 commit comments