diff --git a/examples/generate_prod3_irfs.py b/examples/generate_prod3_irfs.py index 3b406b0..15c6d5f 100755 --- a/examples/generate_prod3_irfs.py +++ b/examples/generate_prod3_irfs.py @@ -53,11 +53,13 @@ def set_prod3_desy(datadir): return db -# ======================== # -# Main routine entry point # -# ======================== # -if __name__ == '__main__': - +# =================== # +# Generate Prod3 IRFs # +# =================== # +def generate_prod3_irfs(): + """ + Generate Prod3 IRFs + """ # Get optional argument if len(sys.argv) == 2: datadir = sys.argv[1] @@ -93,3 +95,15 @@ if __name__ == '__main__': # Add CALDB entry caldb.execute() + + # Return + return + + +# ======================== # +# Main routine entry point # +# ======================== # +if __name__ == '__main__': + + # Generate Prod3 IRFs + generate_prod3_irfs() diff --git a/examples/make_pointings.py b/examples/make_pointings.py index 87bb6bc..6769c0e 100755 --- a/examples/make_pointings.py +++ b/examples/make_pointings.py @@ -437,11 +437,13 @@ def write_obsdef(filename, obsdef): return -# ======================== # -# Main routine entry point # -# ======================== # -if __name__ == '__main__': - +# ============== # +# Make pointings # +# ============== # +def make_pointings(): + """ + Make pointings + """ # Initialise flags need_help = False @@ -491,3 +493,15 @@ if __name__ == '__main__': # Invalid pattern else: print('Unknown option "' + obsname + '"') + + # Return + return + + +# ======================== # +# Main routine entry point # +# ======================== # +if __name__ == '__main__': + + # Make pointings + make_pointings() diff --git a/examples/make_spectrum.py b/examples/make_spectrum.py index b9734c8..31dc66a 100755 --- a/examples/make_spectrum.py +++ b/examples/make_spectrum.py @@ -25,15 +25,15 @@ try: import matplotlib.pyplot as plt plt.figure() plt.close() -except: +except (ImportError, RuntimeError): print('This script needs the "matplotlib" module') sys.exit() # =============== # -# Make a spectrum # +# Create spectrum # # =============== # -def make_spectrum(datadir): +def create_spectrum(datadir): """ Simulate events and generate a source spectrum @@ -178,11 +178,13 @@ def plot_spectrum(spectrum, plotfile): return -# ======================== # -# Main routine entry point # -# ======================== # -if __name__ == '__main__': - +# ============= # +# Make spectrum # +# ============= # +def make_spectrum(): + """ + Make spectrum + """ # Set usage string usage = 'make_spectrum.py [-d datadir] [-p plotfile]' @@ -198,7 +200,18 @@ if __name__ == '__main__': plotfile = options[1]['value'] # Generate spectrum - spectrum = make_spectrum(datadir) + spectrum = create_spectrum(datadir) # Plot spectrum plot_spectrum(spectrum, plotfile) + + # Return + return + +# ======================== # +# Main routine entry point # +# ======================== # +if __name__ == '__main__': + + # Make spectrum + make_spectrum() diff --git a/examples/make_ts_distributions.py b/examples/make_ts_distributions.py index d7ef009..880ccce 100755 --- a/examples/make_ts_distributions.py +++ b/examples/make_ts_distributions.py @@ -82,11 +82,13 @@ def create_ts(datadir, loge, emin, emax, ntrials=100, duration=180000.0, return -# ======================== # -# Main routine entry point # -# ======================== # -if __name__ == '__main__': - +# ==================== # +# Make TS distribution # +# ==================== # +def make_ts_distribution(): + """ + Make TS distribution + """ # Set usage string usage = 'make_ts_distributions.py [-n ntrials] [-e enumbins]'\ ' [-t duration] [-m max_threads] [-d datadir]' @@ -125,3 +127,15 @@ if __name__ == '__main__': # Create TS create_ts(datadir, loge, emin, emax, ntrials=ntrials, enumbins=enumbins, duration=duration) + + # Return + return + + +# ======================== # +# Main routine entry point # +# ======================== # +if __name__ == '__main__': + + # Make TS distribution + make_ts_distribution() diff --git a/examples/pipeline_binned_disk.py b/examples/pipeline_binned_disk.py index a6dffa7..e0043bd 100755 --- a/examples/pipeline_binned_disk.py +++ b/examples/pipeline_binned_disk.py @@ -124,16 +124,13 @@ def run_pipeline(obs, emin=0.1, emax=100.0, return -# ======================== # -# Main routine entry point # -# ======================== # -if __name__ == '__main__': - - # Dump header - print('********************************************') - print('* CTA binned analysis pipeline *') - print('********************************************') - +# ===================================================== # +# Run binned pipeline with intermediate results on disk # +# ===================================================== # +def pipeline_binned_disk(): + """ + Run binned pipeline with intermediate results on disk + """ # Set usage string usage = 'pipeline_binned_disk.py [-d datadir]' @@ -157,3 +154,15 @@ if __name__ == '__main__': # Run analysis pipeline run_pipeline(obs, model=datadir+'/crab.xml', enumbins=10, nxpix=40, nypix=40, binsz=0.1) + + # Return + return + + +# ======================== # +# Main routine entry point # +# ======================== # +if __name__ == '__main__': + + # Run binned pipeline with intermediate results on disk + pipeline_binned_disk() diff --git a/examples/pipeline_binned_mem.py b/examples/pipeline_binned_mem.py index 30b0639..176420b 100755 --- a/examples/pipeline_binned_mem.py +++ b/examples/pipeline_binned_mem.py @@ -95,16 +95,13 @@ def run_pipeline(obs, emin=0.1, emax=100.0, return -# ======================== # -# Main routine entry point # -# ======================== # -if __name__ == '__main__': - - # Dump header - print('********************************************') - print('* CTA binned analysis pipeline *') - print('********************************************') - +# ============================= # +# Run binned in-memory pipeline # +# ============================= # +def pipeline_binned_mem(): + """ + Run binned in-memory pipeline + """ # Set usage string usage = 'pipeline_binned_mem.py [-d datadir]' @@ -127,3 +124,15 @@ if __name__ == '__main__': # Run analysis pipeline run_pipeline(obs, enumbins=10, nxpix=40, nypix=40, binsz=0.1) + + # Return + return + + +# ======================== # +# Main routine entry point # +# ======================== # +if __name__ == '__main__': + + # Run binned in-memory pipeline + pipeline_binned_mem() diff --git a/examples/pipeline_stacked_disk.py b/examples/pipeline_stacked_disk.py index 008b3cf..30f7970 100755 --- a/examples/pipeline_stacked_disk.py +++ b/examples/pipeline_stacked_disk.py @@ -174,16 +174,13 @@ def run_pipeline(obs, ra=83.63, dec=22.01, emin=0.1, emax=100.0, return -# ======================== # -# Main routine entry point # -# ======================== # -if __name__ == '__main__': - - # Dump header - print('********************************************') - print('* CTA stacked analysis pipeline *') - print('********************************************') - +# ====================================================== # +# Run stacked pipeline with intermediate results on disk # +# ====================================================== # +def pipeline_stacked_disk(): + """ + Run stacked pipeline with intermediate results on disk + """ # Set usage string usage = 'pipeline_stacked_disk.py [-d datadir]' @@ -207,3 +204,15 @@ if __name__ == '__main__': # Run analysis pipeline run_pipeline(obs, model=datadir+'/crab.xml', enumbins=10, nxpix=40, nypix=40, binsz=0.1) + + # Return + return + + +# ======================== # +# Main routine entry point # +# ======================== # +if __name__ == '__main__': + + # Run stacked pipeline with intermediate results on disk + pipeline_stacked_disk() diff --git a/examples/pipeline_stacked_mem.py b/examples/pipeline_stacked_mem.py index 083b64e..798984a 100755 --- a/examples/pipeline_stacked_mem.py +++ b/examples/pipeline_stacked_mem.py @@ -147,16 +147,13 @@ def run_pipeline(obs, ra=83.63, dec=22.01, emin=0.1, emax=100.0, return -# ======================== # -# Main routine entry point # -# ======================== # -if __name__ == '__main__': - - # Dump header - print('********************************************') - print('* CTA stacked analysis pipeline *') - print('********************************************') - +# ============================== # +# Run stacked in-memory pipeline # +# ============================== # +def pipeline_stacked_mem(): + """ + Run stacked in-memory pipeline + """ # Set usage string usage = 'pipeline_stacked_mem.py [-d datadir]' @@ -179,3 +176,15 @@ if __name__ == '__main__': # Run analysis pipeline run_pipeline(obs, enumbins=10, nxpix=40, nypix=40, binsz=0.1) + + # Return + return + + +# ======================== # +# Main routine entry point # +# ======================== # +if __name__ == '__main__': + + # Run stacked in-memory pipeline + pipeline_stacked_mem() diff --git a/examples/pipeline_unbinned_disk.py b/examples/pipeline_unbinned_disk.py index a0953ac..c1f61b1 100755 --- a/examples/pipeline_unbinned_disk.py +++ b/examples/pipeline_unbinned_disk.py @@ -98,16 +98,13 @@ def run_pipeline(obs, ra=83.63, dec=22.01, rad=3.0, return -# ======================== # -# Main routine entry point # -# ======================== # -if __name__ == '__main__': - - # Dump header - print('********************************************') - print('* CTA unbinned analysis pipeline *') - print('********************************************') - +# ======================================================= # +# Run unbinned pipeline with intermediate results on disk # +# ======================================================= # +def pipeline_unbinned_disk(): + """ + Run unbinned pipeline with intermediate results on disk + """ # Set usage string usage = 'pipeline_unbinned_disk.py [-d datadir]' @@ -130,3 +127,15 @@ if __name__ == '__main__': # Run analysis pipeline run_pipeline(obs, model=datadir+'/crab.xml') + + # Return + return + + +# ======================== # +# Main routine entry point # +# ======================== # +if __name__ == '__main__': + + # Run unbinned pipeline with intermediate results on disk + pipeline_unbinned_disk() diff --git a/examples/pipeline_unbinned_mem.py b/examples/pipeline_unbinned_mem.py index 5ee396b..baf8a90 100755 --- a/examples/pipeline_unbinned_mem.py +++ b/examples/pipeline_unbinned_mem.py @@ -80,16 +80,13 @@ def run_pipeline(obs, ra=83.63, dec=22.01, rad=3.0, return -# ======================== # -# Main routine entry point # -# ======================== # -if __name__ == '__main__': - - # Dump header - print('********************************************') - print('* CTA unbinned analysis pipeline *') - print('********************************************') - +# =============================== # +# Run unbinned in-memory pipeline # +# =============================== # +def pipeline_unbinned_mem(): + """ + Run unbinned in-memory pipeline + """ # Set usage string usage = 'pipeline_unbinned_mem.py [-d datadir]' @@ -112,3 +109,15 @@ if __name__ == '__main__': # Run analysis pipeline run_pipeline(obs) + + # Return + return + + +# ======================== # +# Main routine entry point # +# ======================== # +if __name__ == '__main__': + + # Run unbinned in-memory pipeline + pipeline_unbinned_mem() diff --git a/examples/show_butterfly.py b/examples/show_butterfly.py index 006a4c7..2b34196 100755 --- a/examples/show_butterfly.py +++ b/examples/show_butterfly.py @@ -93,11 +93,13 @@ def plot_butterfly(filename, plotfile): return -# ======================== # -# Main routine entry point # -# ======================== # -if __name__ == '__main__': - +# ====================== # +# Show butterfly diagram # +# ====================== # +def show_butterfly(): + """ + Show butterfly diagram + """ # Set usage string usage = 'show_butterfly.py [-p plotfile] file' @@ -112,3 +114,15 @@ if __name__ == '__main__': # Plot butterfly diagram plot_butterfly(args[0], plotfile) + + # Return + return + + +# ======================== # +# Main routine entry point # +# ======================== # +if __name__ == '__main__': + + # Show butterfly diagram + show_butterfly() diff --git a/examples/show_model.py b/examples/show_model.py index d2b31c4..b57531d 100755 --- a/examples/show_model.py +++ b/examples/show_model.py @@ -86,11 +86,13 @@ def plot_spectrum(model, plotfile, emin=0.01, emax=100.0, enumbins=100): return -# ======================== # -# Main routine entry point # -# ======================== # -if __name__ == '__main__': - +# =================== # +# Show model spectrum # +# =================== # +def show_model(): + """ + Show model spectrum + """ # Set usage string usage = 'show_model.py [-n name] [-p plotfile] file' @@ -115,3 +117,15 @@ if __name__ == '__main__': # Plot spectrum plot_spectrum(model, plotfile) + + # Return + return + + +# ======================== # +# Main routine entry point # +# ======================== # +if __name__ == '__main__': + + # Show model spectrum + show_model() diff --git a/examples/show_obs.py b/examples/show_obs.py index daaa160..f674a9b 100755 --- a/examples/show_obs.py +++ b/examples/show_obs.py @@ -79,7 +79,7 @@ def run_csobsinfo(filename, ra, dec, debug=True): # ================ # # Plot information # # ================ # -def plot_information(info, plotfile): +def plot_information(info, ra, dec, plotfile): """ Plot information @@ -87,6 +87,10 @@ def plot_information(info, plotfile): ---------- info : `~cscripts.csobsinfo` csobsinfo instance + ra : float + Right Ascension (deg) + dec : float + Declination (deg) plotfile : str Plot filename """ @@ -173,13 +177,15 @@ def plot_information(info, plotfile): return -# ======================== # -# Main routine entry point # -# ======================== # -if __name__ == '__main__': - +# ================ # +# Show observation # +# ================ # +def show_obs(): + """ + Show observation + """ # Set usage string - usage = 'show_model.py [-ra ra] [-dec dec] [-p plotfile] file' + usage = 'show_obs.py [-ra ra] [-dec dec] [-p plotfile] file' # Set default options options = [{'option': '-ra', 'value': ''}, @@ -198,4 +204,16 @@ if __name__ == '__main__': info = run_csobsinfo(args[0], ra, dec) # Plot information - plot_information(info, plotfile) + plot_information(info, ra, dec, plotfile) + + # Return + return + + +# ======================== # +# Main routine entry point # +# ======================== # +if __name__ == '__main__': + + # Show observation + show_obs() diff --git a/examples/show_pha.py b/examples/show_pha.py index 2c42866..7aa2404 100755 --- a/examples/show_pha.py +++ b/examples/show_pha.py @@ -32,11 +32,11 @@ except (ImportError, RuntimeError): # ================= # -# Show PHA spectrum # +# Plot PHA spectrum # # ================= # -def show_pha(pha, plotfile): +def plot_pha(pha, plotfile): """ - Show PHA spectrum + Plot PHA spectrum Parameters ---------- @@ -90,11 +90,13 @@ def show_pha(pha, plotfile): return -# ======================== # -# Main routine entry point # -# ======================== # -if __name__ == '__main__': - +# ================= # +# Show PHA spectrum # +# ================= # +def show_pha(): + """ + Show PHA spectrum + """ # Set usage string usage = 'show_pha.py [-p plotfile] file' @@ -110,5 +112,17 @@ if __name__ == '__main__': # Load PHA spectrum pha = gammalib.GPha(args[0]) + # Plot PHA spectrum + plot_pha(pha, plotfile) + + # Return + return + + +# ======================== # +# Main routine entry point # +# ======================== # +if __name__ == '__main__': + # Show PHA spectrum - show_pha(pha, plotfile) + show_pha() diff --git a/examples/show_pull_evolution.py b/examples/show_pull_evolution.py index 8892b10..1f048ee 100755 --- a/examples/show_pull_evolution.py +++ b/examples/show_pull_evolution.py @@ -87,11 +87,13 @@ def plot_pull_evolution(filename, parname, plotfile): return -# ======================== # -# Main routine entry point # -# ======================== # -if __name__ == '__main__': - +# =================== # +# Show pull evolution # +# =================== # +def show_pull_evolution(): + """ + Show pull evolution + """ # Set usage string usage = 'show_pull_evolution.py [-p plotfile] file parameter' @@ -106,3 +108,15 @@ if __name__ == '__main__': # Plot pull evolution plot_pull_evolution(args[0], args[1], plotfile) + + # Return + return + + +# ======================== # +# Main routine entry point # +# ======================== # +if __name__ == '__main__': + + # Show pull evolution + show_pull_evolution() diff --git a/examples/show_pull_histogram.py b/examples/show_pull_histogram.py index 7c777f4..ef580de 100755 --- a/examples/show_pull_histogram.py +++ b/examples/show_pull_histogram.py @@ -81,11 +81,13 @@ def plot_pull_histogram(filename, parname, nbins, plotfile): return -# ======================== # -# Main routine entry point # -# ======================== # -if __name__ == '__main__': - +# =================== # +# Show pull histogram # +# =================== # +def show_pull_histogram(): + """ + Show pull histogram + """ # Set usage string usage = 'show_pull_histogram.py [-n bins] [-p plotfile] file parameter' @@ -102,3 +104,15 @@ if __name__ == '__main__': # Plot pull histogram plot_pull_histogram(args[0], args[1], nbins, plotfile) + + # Return + return + + +# ======================== # +# Main routine entry point # +# ======================== # +if __name__ == '__main__': + + # Show pull histogram + show_pull_histogram() diff --git a/examples/show_response.py b/examples/show_response.py index 533c910..ae62b97 100755 --- a/examples/show_response.py +++ b/examples/show_response.py @@ -317,7 +317,7 @@ def show_one_response(rspname, dbname, name, rootdir=None, color='r'): # ==================== # # Show one sensitivity # # ==================== # -def show_response(plotfile): +def plot_response(plotfile): """ Show response @@ -367,11 +367,13 @@ def show_response(plotfile): return -# ======================== # -# Main routine entry point # -# ======================== # -if __name__ == '__main__': - +# ============= # +# Show response # +# ============= # +def show_response(): + """ + Show response + """ # Set usage string usage = 'show_response.py [-p plotfile]' @@ -385,4 +387,16 @@ if __name__ == '__main__': plotfile = options[0]['value'] # Show response - show_response(plotfile) + plot_response(plotfile) + + # Return + return + + +# ======================== # +# Main routine entry point # +# ======================== # +if __name__ == '__main__': + + # Show response + show_response() diff --git a/examples/show_sensitivity.py b/examples/show_sensitivity.py index 5913347..0f5e6e7 100755 --- a/examples/show_sensitivity.py +++ b/examples/show_sensitivity.py @@ -95,9 +95,9 @@ def read_sensitivity(filename): # ===================== # -# Show sensitivity data # +# Plot sensitivity data # # ===================== # -def show_sensitivity(sensitivity, filename, plotfile): +def plot_sensitivity(sensitivity, filename, plotfile): """ Plot sensitivity data @@ -141,11 +141,13 @@ def show_sensitivity(sensitivity, filename, plotfile): return -# ======================== # -# Main routine entry point # -# ======================== # -if __name__ == '__main__': - +# ================ # +# Show sensitivity # +# ================ # +def show_sensitivity(): + """ + Show sensitivity + """ # Set usage string usage = 'show_sensitivity.py [-p plotfile] [file]' @@ -165,5 +167,17 @@ if __name__ == '__main__': # Read sensitivity data sensitivity = read_sensitivity(filename) - # Show sensitivity data - show_sensitivity(sensitivity, filename, plotfile) + # Plot sensitivity data + plot_sensitivity(sensitivity, filename, plotfile) + + # Return + return + + +# ======================== # +# Main routine entry point # +# ======================== # +if __name__ == '__main__': + + # Show sensitivity + show_sensitivity() diff --git a/examples/show_spectrum.py b/examples/show_spectrum.py index bf08c24..f7ff462 100755 --- a/examples/show_spectrum.py +++ b/examples/show_spectrum.py @@ -31,9 +31,9 @@ except (ImportError, RuntimeError): # ============= # -# Show spectrum # +# Plot spectrum # # ============= # -def show_spectrum(filename, plotfile): +def plot_spectrum(filename, plotfile): """ Plot sensitivity data @@ -112,11 +112,13 @@ def show_spectrum(filename, plotfile): return -# ======================== # -# Main routine entry point # -# ======================== # -if __name__ == '__main__': - +# ============= # +# Show spectrum # +# ============= # +def show_spectrum(): + """ + Show spectrum + """ # Set usage string usage = 'show_spectrum.py [-p plotfile] [file]' @@ -130,4 +132,16 @@ if __name__ == '__main__': plotfile = options[0]['value'] # Show spectrum - show_spectrum(args[0], plotfile) + plot_spectrum(args[0], plotfile) + + # Return + return + + +# ======================== # +# Main routine entry point # +# ======================== # +if __name__ == '__main__': + + # Show spectrum + show_spectrum() diff --git a/examples/show_ts_distribution.py b/examples/show_ts_distribution.py index 0a97f36..ac5a670 100755 --- a/examples/show_ts_distribution.py +++ b/examples/show_ts_distribution.py @@ -279,11 +279,13 @@ def dist_pdf(values, nbins, title, plotfile, expect=''): return -# ======================== # -# Main routine entry point # -# ======================== # -if __name__ == '__main__': - +# ==================== # +# Show TS distribution # +# ==================== # +def show_ts_distribution(): + """ + Show TS distribution + """ # Set usage string usage = ('show_ts_distribution.py [-n bins] [-c column] [-title title] ' '[-e expect] [-t type] [-p plotfile] file') @@ -316,3 +318,15 @@ if __name__ == '__main__': dist_pdf(values, nbins, title, plotfile, expect=expect) else: dist_cdf(values, nbins, title, plotfile, expect=expect) + + # Return + return + + +# ======================== # +# Main routine entry point # +# ======================== # +if __name__ == '__main__': + + # Show TS distribution + show_ts_distribution()