Commit ee8348cc01ac40b3970ee0f369608bc471e0f688
1 parent
d6fb8eb4
Remove all global variables from example scripts
All global variables have been removed from the example scripts by introducing a main function with the same name as the file that is called from main. Consequently, all variables are local. This is to avoid any problems between global and local scope of variables.
Showing
20 changed files
with
403 additions
and
150 deletions
examples/generate_prod3_irfs.py
| ... | ... | @@ -53,11 +53,13 @@ def set_prod3_desy(datadir): |
| 53 | 53 | return db |
| 54 | 54 | |
| 55 | 55 | |
| 56 | -# ======================== # | |
| 57 | -# Main routine entry point # | |
| 58 | -# ======================== # | |
| 59 | -if __name__ == '__main__': | |
| 60 | - | |
| 56 | +# =================== # | |
| 57 | +# Generate Prod3 IRFs # | |
| 58 | +# =================== # | |
| 59 | +def generate_prod3_irfs(): | |
| 60 | + """ | |
| 61 | + Generate Prod3 IRFs | |
| 62 | + """ | |
| 61 | 63 | # Get optional argument |
| 62 | 64 | if len(sys.argv) == 2: |
| 63 | 65 | datadir = sys.argv[1] |
| ... | ... | @@ -93,3 +95,15 @@ if __name__ == '__main__': |
| 93 | 95 | |
| 94 | 96 | # Add CALDB entry |
| 95 | 97 | caldb.execute() |
| 98 | + | |
| 99 | + # Return | |
| 100 | + return | |
| 101 | + | |
| 102 | + | |
| 103 | +# ======================== # | |
| 104 | +# Main routine entry point # | |
| 105 | +# ======================== # | |
| 106 | +if __name__ == '__main__': | |
| 107 | + | |
| 108 | + # Generate Prod3 IRFs | |
| 109 | + generate_prod3_irfs() | ... | ... |
examples/make_pointings.py
| ... | ... | @@ -437,11 +437,13 @@ def write_obsdef(filename, obsdef): |
| 437 | 437 | return |
| 438 | 438 | |
| 439 | 439 | |
| 440 | -# ======================== # | |
| 441 | -# Main routine entry point # | |
| 442 | -# ======================== # | |
| 443 | -if __name__ == '__main__': | |
| 444 | - | |
| 440 | +# ============== # | |
| 441 | +# Make pointings # | |
| 442 | +# ============== # | |
| 443 | +def make_pointings(): | |
| 444 | + """ | |
| 445 | + Make pointings | |
| 446 | + """ | |
| 445 | 447 | # Initialise flags |
| 446 | 448 | need_help = False |
| 447 | 449 | |
| ... | ... | @@ -491,3 +493,15 @@ if __name__ == '__main__': |
| 491 | 493 | # Invalid pattern |
| 492 | 494 | else: |
| 493 | 495 | print('Unknown option "' + obsname + '"') |
| 496 | + | |
| 497 | + # Return | |
| 498 | + return | |
| 499 | + | |
| 500 | + | |
| 501 | +# ======================== # | |
| 502 | +# Main routine entry point # | |
| 503 | +# ======================== # | |
| 504 | +if __name__ == '__main__': | |
| 505 | + | |
| 506 | + # Make pointings | |
| 507 | + make_pointings() | ... | ... |
examples/make_spectrum.py
| ... | ... | @@ -25,15 +25,15 @@ try: |
| 25 | 25 | import matplotlib.pyplot as plt |
| 26 | 26 | plt.figure() |
| 27 | 27 | plt.close() |
| 28 | -except: | |
| 28 | +except (ImportError, RuntimeError): | |
| 29 | 29 | print('This script needs the "matplotlib" module') |
| 30 | 30 | sys.exit() |
| 31 | 31 | |
| 32 | 32 | |
| 33 | 33 | # =============== # |
| 34 | -# Make a spectrum # | |
| 34 | +# Create spectrum # | |
| 35 | 35 | # =============== # |
| 36 | -def make_spectrum(datadir): | |
| 36 | +def create_spectrum(datadir): | |
| 37 | 37 | """ |
| 38 | 38 | Simulate events and generate a source spectrum |
| 39 | 39 | |
| ... | ... | @@ -178,11 +178,13 @@ def plot_spectrum(spectrum, plotfile): |
| 178 | 178 | return |
| 179 | 179 | |
| 180 | 180 | |
| 181 | -# ======================== # | |
| 182 | -# Main routine entry point # | |
| 183 | -# ======================== # | |
| 184 | -if __name__ == '__main__': | |
| 185 | - | |
| 181 | +# ============= # | |
| 182 | +# Make spectrum # | |
| 183 | +# ============= # | |
| 184 | +def make_spectrum(): | |
| 185 | + """ | |
| 186 | + Make spectrum | |
| 187 | + """ | |
| 186 | 188 | # Set usage string |
| 187 | 189 | usage = 'make_spectrum.py [-d datadir] [-p plotfile]' |
| 188 | 190 | |
| ... | ... | @@ -198,7 +200,18 @@ if __name__ == '__main__': |
| 198 | 200 | plotfile = options[1]['value'] |
| 199 | 201 | |
| 200 | 202 | # Generate spectrum |
| 201 | - spectrum = make_spectrum(datadir) | |
| 203 | + spectrum = create_spectrum(datadir) | |
| 202 | 204 | |
| 203 | 205 | # Plot spectrum |
| 204 | 206 | plot_spectrum(spectrum, plotfile) |
| 207 | + | |
| 208 | + # Return | |
| 209 | + return | |
| 210 | + | |
| 211 | +# ======================== # | |
| 212 | +# Main routine entry point # | |
| 213 | +# ======================== # | |
| 214 | +if __name__ == '__main__': | |
| 215 | + | |
| 216 | + # Make spectrum | |
| 217 | + make_spectrum() | ... | ... |
examples/make_ts_distributions.py
| ... | ... | @@ -82,11 +82,13 @@ def create_ts(datadir, loge, emin, emax, ntrials=100, duration=180000.0, |
| 82 | 82 | return |
| 83 | 83 | |
| 84 | 84 | |
| 85 | -# ======================== # | |
| 86 | -# Main routine entry point # | |
| 87 | -# ======================== # | |
| 88 | -if __name__ == '__main__': | |
| 89 | - | |
| 85 | +# ==================== # | |
| 86 | +# Make TS distribution # | |
| 87 | +# ==================== # | |
| 88 | +def make_ts_distribution(): | |
| 89 | + """ | |
| 90 | + Make TS distribution | |
| 91 | + """ | |
| 90 | 92 | # Set usage string |
| 91 | 93 | usage = 'make_ts_distributions.py [-n ntrials] [-e enumbins]'\ |
| 92 | 94 | ' [-t duration] [-m max_threads] [-d datadir]' |
| ... | ... | @@ -125,3 +127,15 @@ if __name__ == '__main__': |
| 125 | 127 | # Create TS |
| 126 | 128 | create_ts(datadir, loge, emin, emax, ntrials=ntrials, enumbins=enumbins, |
| 127 | 129 | duration=duration) |
| 130 | + | |
| 131 | + # Return | |
| 132 | + return | |
| 133 | + | |
| 134 | + | |
| 135 | +# ======================== # | |
| 136 | +# Main routine entry point # | |
| 137 | +# ======================== # | |
| 138 | +if __name__ == '__main__': | |
| 139 | + | |
| 140 | + # Make TS distribution | |
| 141 | + make_ts_distribution() | ... | ... |
examples/pipeline_binned_disk.py
| ... | ... | @@ -124,16 +124,13 @@ def run_pipeline(obs, emin=0.1, emax=100.0, |
| 124 | 124 | return |
| 125 | 125 | |
| 126 | 126 | |
| 127 | -# ======================== # | |
| 128 | -# Main routine entry point # | |
| 129 | -# ======================== # | |
| 130 | -if __name__ == '__main__': | |
| 131 | - | |
| 132 | - # Dump header | |
| 133 | - print('********************************************') | |
| 134 | - print('* CTA binned analysis pipeline *') | |
| 135 | - print('********************************************') | |
| 136 | - | |
| 127 | +# ===================================================== # | |
| 128 | +# Run binned pipeline with intermediate results on disk # | |
| 129 | +# ===================================================== # | |
| 130 | +def pipeline_binned_disk(): | |
| 131 | + """ | |
| 132 | + Run binned pipeline with intermediate results on disk | |
| 133 | + """ | |
| 137 | 134 | # Set usage string |
| 138 | 135 | usage = 'pipeline_binned_disk.py [-d datadir]' |
| 139 | 136 | |
| ... | ... | @@ -157,3 +154,15 @@ if __name__ == '__main__': |
| 157 | 154 | # Run analysis pipeline |
| 158 | 155 | run_pipeline(obs, model=datadir+'/crab.xml', enumbins=10, nxpix=40, |
| 159 | 156 | nypix=40, binsz=0.1) |
| 157 | + | |
| 158 | + # Return | |
| 159 | + return | |
| 160 | + | |
| 161 | + | |
| 162 | +# ======================== # | |
| 163 | +# Main routine entry point # | |
| 164 | +# ======================== # | |
| 165 | +if __name__ == '__main__': | |
| 166 | + | |
| 167 | + # Run binned pipeline with intermediate results on disk | |
| 168 | + pipeline_binned_disk() | ... | ... |
examples/pipeline_binned_mem.py
| ... | ... | @@ -95,16 +95,13 @@ def run_pipeline(obs, emin=0.1, emax=100.0, |
| 95 | 95 | return |
| 96 | 96 | |
| 97 | 97 | |
| 98 | -# ======================== # | |
| 99 | -# Main routine entry point # | |
| 100 | -# ======================== # | |
| 101 | -if __name__ == '__main__': | |
| 102 | - | |
| 103 | - # Dump header | |
| 104 | - print('********************************************') | |
| 105 | - print('* CTA binned analysis pipeline *') | |
| 106 | - print('********************************************') | |
| 107 | - | |
| 98 | +# ============================= # | |
| 99 | +# Run binned in-memory pipeline # | |
| 100 | +# ============================= # | |
| 101 | +def pipeline_binned_mem(): | |
| 102 | + """ | |
| 103 | + Run binned in-memory pipeline | |
| 104 | + """ | |
| 108 | 105 | # Set usage string |
| 109 | 106 | usage = 'pipeline_binned_mem.py [-d datadir]' |
| 110 | 107 | |
| ... | ... | @@ -127,3 +124,15 @@ if __name__ == '__main__': |
| 127 | 124 | |
| 128 | 125 | # Run analysis pipeline |
| 129 | 126 | run_pipeline(obs, enumbins=10, nxpix=40, nypix=40, binsz=0.1) |
| 127 | + | |
| 128 | + # Return | |
| 129 | + return | |
| 130 | + | |
| 131 | + | |
| 132 | +# ======================== # | |
| 133 | +# Main routine entry point # | |
| 134 | +# ======================== # | |
| 135 | +if __name__ == '__main__': | |
| 136 | + | |
| 137 | + # Run binned in-memory pipeline | |
| 138 | + pipeline_binned_mem() | ... | ... |
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, |
| 174 | 174 | return |
| 175 | 175 | |
| 176 | 176 | |
| 177 | -# ======================== # | |
| 178 | -# Main routine entry point # | |
| 179 | -# ======================== # | |
| 180 | -if __name__ == '__main__': | |
| 181 | - | |
| 182 | - # Dump header | |
| 183 | - print('********************************************') | |
| 184 | - print('* CTA stacked analysis pipeline *') | |
| 185 | - print('********************************************') | |
| 186 | - | |
| 177 | +# ====================================================== # | |
| 178 | +# Run stacked pipeline with intermediate results on disk # | |
| 179 | +# ====================================================== # | |
| 180 | +def pipeline_stacked_disk(): | |
| 181 | + """ | |
| 182 | + Run stacked pipeline with intermediate results on disk | |
| 183 | + """ | |
| 187 | 184 | # Set usage string |
| 188 | 185 | usage = 'pipeline_stacked_disk.py [-d datadir]' |
| 189 | 186 | |
| ... | ... | @@ -207,3 +204,15 @@ if __name__ == '__main__': |
| 207 | 204 | # Run analysis pipeline |
| 208 | 205 | run_pipeline(obs, model=datadir+'/crab.xml', enumbins=10, nxpix=40, |
| 209 | 206 | nypix=40, binsz=0.1) |
| 207 | + | |
| 208 | + # Return | |
| 209 | + return | |
| 210 | + | |
| 211 | + | |
| 212 | +# ======================== # | |
| 213 | +# Main routine entry point # | |
| 214 | +# ======================== # | |
| 215 | +if __name__ == '__main__': | |
| 216 | + | |
| 217 | + # Run stacked pipeline with intermediate results on disk | |
| 218 | + pipeline_stacked_disk() | ... | ... |
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, |
| 147 | 147 | return |
| 148 | 148 | |
| 149 | 149 | |
| 150 | -# ======================== # | |
| 151 | -# Main routine entry point # | |
| 152 | -# ======================== # | |
| 153 | -if __name__ == '__main__': | |
| 154 | - | |
| 155 | - # Dump header | |
| 156 | - print('********************************************') | |
| 157 | - print('* CTA stacked analysis pipeline *') | |
| 158 | - print('********************************************') | |
| 159 | - | |
| 150 | +# ============================== # | |
| 151 | +# Run stacked in-memory pipeline # | |
| 152 | +# ============================== # | |
| 153 | +def pipeline_stacked_mem(): | |
| 154 | + """ | |
| 155 | + Run stacked in-memory pipeline | |
| 156 | + """ | |
| 160 | 157 | # Set usage string |
| 161 | 158 | usage = 'pipeline_stacked_mem.py [-d datadir]' |
| 162 | 159 | |
| ... | ... | @@ -179,3 +176,15 @@ if __name__ == '__main__': |
| 179 | 176 | |
| 180 | 177 | # Run analysis pipeline |
| 181 | 178 | run_pipeline(obs, enumbins=10, nxpix=40, nypix=40, binsz=0.1) |
| 179 | + | |
| 180 | + # Return | |
| 181 | + return | |
| 182 | + | |
| 183 | + | |
| 184 | +# ======================== # | |
| 185 | +# Main routine entry point # | |
| 186 | +# ======================== # | |
| 187 | +if __name__ == '__main__': | |
| 188 | + | |
| 189 | + # Run stacked in-memory pipeline | |
| 190 | + pipeline_stacked_mem() | ... | ... |
examples/pipeline_unbinned_disk.py
| ... | ... | @@ -98,16 +98,13 @@ def run_pipeline(obs, ra=83.63, dec=22.01, rad=3.0, |
| 98 | 98 | return |
| 99 | 99 | |
| 100 | 100 | |
| 101 | -# ======================== # | |
| 102 | -# Main routine entry point # | |
| 103 | -# ======================== # | |
| 104 | -if __name__ == '__main__': | |
| 105 | - | |
| 106 | - # Dump header | |
| 107 | - print('********************************************') | |
| 108 | - print('* CTA unbinned analysis pipeline *') | |
| 109 | - print('********************************************') | |
| 110 | - | |
| 101 | +# ======================================================= # | |
| 102 | +# Run unbinned pipeline with intermediate results on disk # | |
| 103 | +# ======================================================= # | |
| 104 | +def pipeline_unbinned_disk(): | |
| 105 | + """ | |
| 106 | + Run unbinned pipeline with intermediate results on disk | |
| 107 | + """ | |
| 111 | 108 | # Set usage string |
| 112 | 109 | usage = 'pipeline_unbinned_disk.py [-d datadir]' |
| 113 | 110 | |
| ... | ... | @@ -130,3 +127,15 @@ if __name__ == '__main__': |
| 130 | 127 | |
| 131 | 128 | # Run analysis pipeline |
| 132 | 129 | run_pipeline(obs, model=datadir+'/crab.xml') |
| 130 | + | |
| 131 | + # Return | |
| 132 | + return | |
| 133 | + | |
| 134 | + | |
| 135 | +# ======================== # | |
| 136 | +# Main routine entry point # | |
| 137 | +# ======================== # | |
| 138 | +if __name__ == '__main__': | |
| 139 | + | |
| 140 | + # Run unbinned pipeline with intermediate results on disk | |
| 141 | + pipeline_unbinned_disk() | ... | ... |
examples/pipeline_unbinned_mem.py
| ... | ... | @@ -80,16 +80,13 @@ def run_pipeline(obs, ra=83.63, dec=22.01, rad=3.0, |
| 80 | 80 | return |
| 81 | 81 | |
| 82 | 82 | |
| 83 | -# ======================== # | |
| 84 | -# Main routine entry point # | |
| 85 | -# ======================== # | |
| 86 | -if __name__ == '__main__': | |
| 87 | - | |
| 88 | - # Dump header | |
| 89 | - print('********************************************') | |
| 90 | - print('* CTA unbinned analysis pipeline *') | |
| 91 | - print('********************************************') | |
| 92 | - | |
| 83 | +# =============================== # | |
| 84 | +# Run unbinned in-memory pipeline # | |
| 85 | +# =============================== # | |
| 86 | +def pipeline_unbinned_mem(): | |
| 87 | + """ | |
| 88 | + Run unbinned in-memory pipeline | |
| 89 | + """ | |
| 93 | 90 | # Set usage string |
| 94 | 91 | usage = 'pipeline_unbinned_mem.py [-d datadir]' |
| 95 | 92 | |
| ... | ... | @@ -112,3 +109,15 @@ if __name__ == '__main__': |
| 112 | 109 | |
| 113 | 110 | # Run analysis pipeline |
| 114 | 111 | run_pipeline(obs) |
| 112 | + | |
| 113 | + # Return | |
| 114 | + return | |
| 115 | + | |
| 116 | + | |
| 117 | +# ======================== # | |
| 118 | +# Main routine entry point # | |
| 119 | +# ======================== # | |
| 120 | +if __name__ == '__main__': | |
| 121 | + | |
| 122 | + # Run unbinned in-memory pipeline | |
| 123 | + pipeline_unbinned_mem() | ... | ... |
examples/show_butterfly.py
| ... | ... | @@ -93,11 +93,13 @@ def plot_butterfly(filename, plotfile): |
| 93 | 93 | return |
| 94 | 94 | |
| 95 | 95 | |
| 96 | -# ======================== # | |
| 97 | -# Main routine entry point # | |
| 98 | -# ======================== # | |
| 99 | -if __name__ == '__main__': | |
| 100 | - | |
| 96 | +# ====================== # | |
| 97 | +# Show butterfly diagram # | |
| 98 | +# ====================== # | |
| 99 | +def show_butterfly(): | |
| 100 | + """ | |
| 101 | + Show butterfly diagram | |
| 102 | + """ | |
| 101 | 103 | # Set usage string |
| 102 | 104 | usage = 'show_butterfly.py [-p plotfile] file' |
| 103 | 105 | |
| ... | ... | @@ -112,3 +114,15 @@ if __name__ == '__main__': |
| 112 | 114 | |
| 113 | 115 | # Plot butterfly diagram |
| 114 | 116 | plot_butterfly(args[0], plotfile) |
| 117 | + | |
| 118 | + # Return | |
| 119 | + return | |
| 120 | + | |
| 121 | + | |
| 122 | +# ======================== # | |
| 123 | +# Main routine entry point # | |
| 124 | +# ======================== # | |
| 125 | +if __name__ == '__main__': | |
| 126 | + | |
| 127 | + # Show butterfly diagram | |
| 128 | + show_butterfly() | ... | ... |
examples/show_model.py
| ... | ... | @@ -86,11 +86,13 @@ def plot_spectrum(model, plotfile, emin=0.01, emax=100.0, enumbins=100): |
| 86 | 86 | return |
| 87 | 87 | |
| 88 | 88 | |
| 89 | -# ======================== # | |
| 90 | -# Main routine entry point # | |
| 91 | -# ======================== # | |
| 92 | -if __name__ == '__main__': | |
| 93 | - | |
| 89 | +# =================== # | |
| 90 | +# Show model spectrum # | |
| 91 | +# =================== # | |
| 92 | +def show_model(): | |
| 93 | + """ | |
| 94 | + Show model spectrum | |
| 95 | + """ | |
| 94 | 96 | # Set usage string |
| 95 | 97 | usage = 'show_model.py [-n name] [-p plotfile] file' |
| 96 | 98 | |
| ... | ... | @@ -115,3 +117,15 @@ if __name__ == '__main__': |
| 115 | 117 | |
| 116 | 118 | # Plot spectrum |
| 117 | 119 | plot_spectrum(model, plotfile) |
| 120 | + | |
| 121 | + # Return | |
| 122 | + return | |
| 123 | + | |
| 124 | + | |
| 125 | +# ======================== # | |
| 126 | +# Main routine entry point # | |
| 127 | +# ======================== # | |
| 128 | +if __name__ == '__main__': | |
| 129 | + | |
| 130 | + # Show model spectrum | |
| 131 | + show_model() | ... | ... |
examples/show_obs.py
| ... | ... | @@ -79,7 +79,7 @@ def run_csobsinfo(filename, ra, dec, debug=True): |
| 79 | 79 | # ================ # |
| 80 | 80 | # Plot information # |
| 81 | 81 | # ================ # |
| 82 | -def plot_information(info, plotfile): | |
| 82 | +def plot_information(info, ra, dec, plotfile): | |
| 83 | 83 | """ |
| 84 | 84 | Plot information |
| 85 | 85 | |
| ... | ... | @@ -87,6 +87,10 @@ def plot_information(info, plotfile): |
| 87 | 87 | ---------- |
| 88 | 88 | info : `~cscripts.csobsinfo` |
| 89 | 89 | csobsinfo instance |
| 90 | + ra : float | |
| 91 | + Right Ascension (deg) | |
| 92 | + dec : float | |
| 93 | + Declination (deg) | |
| 90 | 94 | plotfile : str |
| 91 | 95 | Plot filename |
| 92 | 96 | """ |
| ... | ... | @@ -173,13 +177,15 @@ def plot_information(info, plotfile): |
| 173 | 177 | return |
| 174 | 178 | |
| 175 | 179 | |
| 176 | -# ======================== # | |
| 177 | -# Main routine entry point # | |
| 178 | -# ======================== # | |
| 179 | -if __name__ == '__main__': | |
| 180 | - | |
| 180 | +# ================ # | |
| 181 | +# Show observation # | |
| 182 | +# ================ # | |
| 183 | +def show_obs(): | |
| 184 | + """ | |
| 185 | + Show observation | |
| 186 | + """ | |
| 181 | 187 | # Set usage string |
| 182 | - usage = 'show_model.py [-ra ra] [-dec dec] [-p plotfile] file' | |
| 188 | + usage = 'show_obs.py [-ra ra] [-dec dec] [-p plotfile] file' | |
| 183 | 189 | |
| 184 | 190 | # Set default options |
| 185 | 191 | options = [{'option': '-ra', 'value': ''}, |
| ... | ... | @@ -198,4 +204,16 @@ if __name__ == '__main__': |
| 198 | 204 | info = run_csobsinfo(args[0], ra, dec) |
| 199 | 205 | |
| 200 | 206 | # Plot information |
| 201 | - plot_information(info, plotfile) | |
| 207 | + plot_information(info, ra, dec, plotfile) | |
| 208 | + | |
| 209 | + # Return | |
| 210 | + return | |
| 211 | + | |
| 212 | + | |
| 213 | +# ======================== # | |
| 214 | +# Main routine entry point # | |
| 215 | +# ======================== # | |
| 216 | +if __name__ == '__main__': | |
| 217 | + | |
| 218 | + # Show observation | |
| 219 | + show_obs() | ... | ... |
examples/show_pha.py
| ... | ... | @@ -32,11 +32,11 @@ except (ImportError, RuntimeError): |
| 32 | 32 | |
| 33 | 33 | |
| 34 | 34 | # ================= # |
| 35 | -# Show PHA spectrum # | |
| 35 | +# Plot PHA spectrum # | |
| 36 | 36 | # ================= # |
| 37 | -def show_pha(pha, plotfile): | |
| 37 | +def plot_pha(pha, plotfile): | |
| 38 | 38 | """ |
| 39 | - Show PHA spectrum | |
| 39 | + Plot PHA spectrum | |
| 40 | 40 | |
| 41 | 41 | Parameters |
| 42 | 42 | ---------- |
| ... | ... | @@ -90,11 +90,13 @@ def show_pha(pha, plotfile): |
| 90 | 90 | return |
| 91 | 91 | |
| 92 | 92 | |
| 93 | -# ======================== # | |
| 94 | -# Main routine entry point # | |
| 95 | -# ======================== # | |
| 96 | -if __name__ == '__main__': | |
| 97 | - | |
| 93 | +# ================= # | |
| 94 | +# Show PHA spectrum # | |
| 95 | +# ================= # | |
| 96 | +def show_pha(): | |
| 97 | + """ | |
| 98 | + Show PHA spectrum | |
| 99 | + """ | |
| 98 | 100 | # Set usage string |
| 99 | 101 | usage = 'show_pha.py [-p plotfile] file' |
| 100 | 102 | |
| ... | ... | @@ -110,5 +112,17 @@ if __name__ == '__main__': |
| 110 | 112 | # Load PHA spectrum |
| 111 | 113 | pha = gammalib.GPha(args[0]) |
| 112 | 114 | |
| 115 | + # Plot PHA spectrum | |
| 116 | + plot_pha(pha, plotfile) | |
| 117 | + | |
| 118 | + # Return | |
| 119 | + return | |
| 120 | + | |
| 121 | + | |
| 122 | +# ======================== # | |
| 123 | +# Main routine entry point # | |
| 124 | +# ======================== # | |
| 125 | +if __name__ == '__main__': | |
| 126 | + | |
| 113 | 127 | # Show PHA spectrum |
| 114 | - show_pha(pha, plotfile) | |
| 128 | + show_pha() | ... | ... |
examples/show_pull_evolution.py
| ... | ... | @@ -87,11 +87,13 @@ def plot_pull_evolution(filename, parname, plotfile): |
| 87 | 87 | return |
| 88 | 88 | |
| 89 | 89 | |
| 90 | -# ======================== # | |
| 91 | -# Main routine entry point # | |
| 92 | -# ======================== # | |
| 93 | -if __name__ == '__main__': | |
| 94 | - | |
| 90 | +# =================== # | |
| 91 | +# Show pull evolution # | |
| 92 | +# =================== # | |
| 93 | +def show_pull_evolution(): | |
| 94 | + """ | |
| 95 | + Show pull evolution | |
| 96 | + """ | |
| 95 | 97 | # Set usage string |
| 96 | 98 | usage = 'show_pull_evolution.py [-p plotfile] file parameter' |
| 97 | 99 | |
| ... | ... | @@ -106,3 +108,15 @@ if __name__ == '__main__': |
| 106 | 108 | |
| 107 | 109 | # Plot pull evolution |
| 108 | 110 | plot_pull_evolution(args[0], args[1], plotfile) |
| 111 | + | |
| 112 | + # Return | |
| 113 | + return | |
| 114 | + | |
| 115 | + | |
| 116 | +# ======================== # | |
| 117 | +# Main routine entry point # | |
| 118 | +# ======================== # | |
| 119 | +if __name__ == '__main__': | |
| 120 | + | |
| 121 | + # Show pull evolution | |
| 122 | + show_pull_evolution() | ... | ... |
examples/show_pull_histogram.py
| ... | ... | @@ -81,11 +81,13 @@ def plot_pull_histogram(filename, parname, nbins, plotfile): |
| 81 | 81 | return |
| 82 | 82 | |
| 83 | 83 | |
| 84 | -# ======================== # | |
| 85 | -# Main routine entry point # | |
| 86 | -# ======================== # | |
| 87 | -if __name__ == '__main__': | |
| 88 | - | |
| 84 | +# =================== # | |
| 85 | +# Show pull histogram # | |
| 86 | +# =================== # | |
| 87 | +def show_pull_histogram(): | |
| 88 | + """ | |
| 89 | + Show pull histogram | |
| 90 | + """ | |
| 89 | 91 | # Set usage string |
| 90 | 92 | usage = 'show_pull_histogram.py [-n bins] [-p plotfile] file parameter' |
| 91 | 93 | |
| ... | ... | @@ -102,3 +104,15 @@ if __name__ == '__main__': |
| 102 | 104 | |
| 103 | 105 | # Plot pull histogram |
| 104 | 106 | plot_pull_histogram(args[0], args[1], nbins, plotfile) |
| 107 | + | |
| 108 | + # Return | |
| 109 | + return | |
| 110 | + | |
| 111 | + | |
| 112 | +# ======================== # | |
| 113 | +# Main routine entry point # | |
| 114 | +# ======================== # | |
| 115 | +if __name__ == '__main__': | |
| 116 | + | |
| 117 | + # Show pull histogram | |
| 118 | + show_pull_histogram() | ... | ... |
examples/show_response.py
| ... | ... | @@ -317,7 +317,7 @@ def show_one_response(rspname, dbname, name, rootdir=None, color='r'): |
| 317 | 317 | # ==================== # |
| 318 | 318 | # Show one sensitivity # |
| 319 | 319 | # ==================== # |
| 320 | -def show_response(plotfile): | |
| 320 | +def plot_response(plotfile): | |
| 321 | 321 | """ |
| 322 | 322 | Show response |
| 323 | 323 | |
| ... | ... | @@ -367,11 +367,13 @@ def show_response(plotfile): |
| 367 | 367 | return |
| 368 | 368 | |
| 369 | 369 | |
| 370 | -# ======================== # | |
| 371 | -# Main routine entry point # | |
| 372 | -# ======================== # | |
| 373 | -if __name__ == '__main__': | |
| 374 | - | |
| 370 | +# ============= # | |
| 371 | +# Show response # | |
| 372 | +# ============= # | |
| 373 | +def show_response(): | |
| 374 | + """ | |
| 375 | + Show response | |
| 376 | + """ | |
| 375 | 377 | # Set usage string |
| 376 | 378 | usage = 'show_response.py [-p plotfile]' |
| 377 | 379 | |
| ... | ... | @@ -385,4 +387,16 @@ if __name__ == '__main__': |
| 385 | 387 | plotfile = options[0]['value'] |
| 386 | 388 | |
| 387 | 389 | # Show response |
| 388 | - show_response(plotfile) | |
| 390 | + plot_response(plotfile) | |
| 391 | + | |
| 392 | + # Return | |
| 393 | + return | |
| 394 | + | |
| 395 | + | |
| 396 | +# ======================== # | |
| 397 | +# Main routine entry point # | |
| 398 | +# ======================== # | |
| 399 | +if __name__ == '__main__': | |
| 400 | + | |
| 401 | + # Show response | |
| 402 | + show_response() | ... | ... |
examples/show_sensitivity.py
| ... | ... | @@ -95,9 +95,9 @@ def read_sensitivity(filename): |
| 95 | 95 | |
| 96 | 96 | |
| 97 | 97 | # ===================== # |
| 98 | -# Show sensitivity data # | |
| 98 | +# Plot sensitivity data # | |
| 99 | 99 | # ===================== # |
| 100 | -def show_sensitivity(sensitivity, filename, plotfile): | |
| 100 | +def plot_sensitivity(sensitivity, filename, plotfile): | |
| 101 | 101 | """ |
| 102 | 102 | Plot sensitivity data |
| 103 | 103 | |
| ... | ... | @@ -141,11 +141,13 @@ def show_sensitivity(sensitivity, filename, plotfile): |
| 141 | 141 | return |
| 142 | 142 | |
| 143 | 143 | |
| 144 | -# ======================== # | |
| 145 | -# Main routine entry point # | |
| 146 | -# ======================== # | |
| 147 | -if __name__ == '__main__': | |
| 148 | - | |
| 144 | +# ================ # | |
| 145 | +# Show sensitivity # | |
| 146 | +# ================ # | |
| 147 | +def show_sensitivity(): | |
| 148 | + """ | |
| 149 | + Show sensitivity | |
| 150 | + """ | |
| 149 | 151 | # Set usage string |
| 150 | 152 | usage = 'show_sensitivity.py [-p plotfile] [file]' |
| 151 | 153 | |
| ... | ... | @@ -165,5 +167,17 @@ if __name__ == '__main__': |
| 165 | 167 | # Read sensitivity data |
| 166 | 168 | sensitivity = read_sensitivity(filename) |
| 167 | 169 | |
| 168 | - # Show sensitivity data | |
| 169 | - show_sensitivity(sensitivity, filename, plotfile) | |
| 170 | + # Plot sensitivity data | |
| 171 | + plot_sensitivity(sensitivity, filename, plotfile) | |
| 172 | + | |
| 173 | + # Return | |
| 174 | + return | |
| 175 | + | |
| 176 | + | |
| 177 | +# ======================== # | |
| 178 | +# Main routine entry point # | |
| 179 | +# ======================== # | |
| 180 | +if __name__ == '__main__': | |
| 181 | + | |
| 182 | + # Show sensitivity | |
| 183 | + show_sensitivity() | ... | ... |
examples/show_spectrum.py
| ... | ... | @@ -31,9 +31,9 @@ except (ImportError, RuntimeError): |
| 31 | 31 | |
| 32 | 32 | |
| 33 | 33 | # ============= # |
| 34 | -# Show spectrum # | |
| 34 | +# Plot spectrum # | |
| 35 | 35 | # ============= # |
| 36 | -def show_spectrum(filename, plotfile): | |
| 36 | +def plot_spectrum(filename, plotfile): | |
| 37 | 37 | """ |
| 38 | 38 | Plot sensitivity data |
| 39 | 39 | |
| ... | ... | @@ -112,11 +112,13 @@ def show_spectrum(filename, plotfile): |
| 112 | 112 | return |
| 113 | 113 | |
| 114 | 114 | |
| 115 | -# ======================== # | |
| 116 | -# Main routine entry point # | |
| 117 | -# ======================== # | |
| 118 | -if __name__ == '__main__': | |
| 119 | - | |
| 115 | +# ============= # | |
| 116 | +# Show spectrum # | |
| 117 | +# ============= # | |
| 118 | +def show_spectrum(): | |
| 119 | + """ | |
| 120 | + Show spectrum | |
| 121 | + """ | |
| 120 | 122 | # Set usage string |
| 121 | 123 | usage = 'show_spectrum.py [-p plotfile] [file]' |
| 122 | 124 | |
| ... | ... | @@ -130,4 +132,16 @@ if __name__ == '__main__': |
| 130 | 132 | plotfile = options[0]['value'] |
| 131 | 133 | |
| 132 | 134 | # Show spectrum |
| 133 | - show_spectrum(args[0], plotfile) | |
| 135 | + plot_spectrum(args[0], plotfile) | |
| 136 | + | |
| 137 | + # Return | |
| 138 | + return | |
| 139 | + | |
| 140 | + | |
| 141 | +# ======================== # | |
| 142 | +# Main routine entry point # | |
| 143 | +# ======================== # | |
| 144 | +if __name__ == '__main__': | |
| 145 | + | |
| 146 | + # Show spectrum | |
| 147 | + show_spectrum() | ... | ... |
examples/show_ts_distribution.py
| ... | ... | @@ -279,11 +279,13 @@ def dist_pdf(values, nbins, title, plotfile, expect=''): |
| 279 | 279 | return |
| 280 | 280 | |
| 281 | 281 | |
| 282 | -# ======================== # | |
| 283 | -# Main routine entry point # | |
| 284 | -# ======================== # | |
| 285 | -if __name__ == '__main__': | |
| 286 | - | |
| 282 | +# ==================== # | |
| 283 | +# Show TS distribution # | |
| 284 | +# ==================== # | |
| 285 | +def show_ts_distribution(): | |
| 286 | + """ | |
| 287 | + Show TS distribution | |
| 288 | + """ | |
| 287 | 289 | # Set usage string |
| 288 | 290 | usage = ('show_ts_distribution.py [-n bins] [-c column] [-title title] ' |
| 289 | 291 | '[-e expect] [-t type] [-p plotfile] file') |
| ... | ... | @@ -316,3 +318,15 @@ if __name__ == '__main__': |
| 316 | 318 | dist_pdf(values, nbins, title, plotfile, expect=expect) |
| 317 | 319 | else: |
| 318 | 320 | dist_cdf(values, nbins, title, plotfile, expect=expect) |
| 321 | + | |
| 322 | + # Return | |
| 323 | + return | |
| 324 | + | |
| 325 | + | |
| 326 | +# ======================== # | |
| 327 | +# Main routine entry point # | |
| 328 | +# ======================== # | |
| 329 | +if __name__ == '__main__': | |
| 330 | + | |
| 331 | + # Show TS distribution | |
| 332 | + show_ts_distribution() | ... | ... |