Commit 10d97daa855809e59def8cd3a204f3371d4d8d97
1 parent
e71941d0
Adapted show_obs.py to coding conventions and suggestions from jknoedlseder
Showing
1 changed file
with
11 additions
and
12 deletions
examples/show_obs.py
| @@ -21,24 +21,23 @@ | @@ -21,24 +21,23 @@ | ||
| 21 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 21 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 22 | # | 22 | # |
| 23 | # ========================================================================== | 23 | # ========================================================================== |
| 24 | - | 24 | +import sys |
| 25 | import gammalib | 25 | import gammalib |
| 26 | import ctools | 26 | import ctools |
| 27 | import cscripts | 27 | import cscripts |
| 28 | -import sys | ||
| 29 | try: | 28 | try: |
| 30 | import matplotlib.pyplot as plt | 29 | import matplotlib.pyplot as plt |
| 30 | + plt.figure() | ||
| 31 | + plt.close() | ||
| 31 | except: | 32 | except: |
| 32 | - sys.exit("This script requires matplotlib") | 33 | + print('This script needs the "matplotlib" module') |
| 34 | + sys.exit() | ||
| 33 | 35 | ||
| 34 | 36 | ||
| 35 | # ======================== # | 37 | # ======================== # |
| 36 | # Main routine entry point # | 38 | # Main routine entry point # |
| 37 | # ======================== # | 39 | # ======================== # |
| 38 | -if __name__ == "__main__": | ||
| 39 | - """ | ||
| 40 | - Print and display details of the observation container using matplotlib. | ||
| 41 | - """ | 40 | +if __name__ == '__main__': |
| 42 | 41 | ||
| 43 | # Print help if wrong number of arguments provided | 42 | # Print help if wrong number of arguments provided |
| 44 | if not len(sys.argv) > 1: | 43 | if not len(sys.argv) > 1: |
| @@ -91,7 +90,7 @@ if __name__ == "__main__": | @@ -91,7 +90,7 @@ if __name__ == "__main__": | ||
| 91 | amin = min(azimuths) | 90 | amin = min(azimuths) |
| 92 | amax = max(azimuths) | 91 | amax = max(azimuths) |
| 93 | plt.hist(azimuths, bins=30, range=(amin, amax),fc='blue') | 92 | plt.hist(azimuths, bins=30, range=(amin, amax),fc='blue') |
| 94 | - plt.xlabel("Azimuth Angle [deg]") | 93 | + plt.xlabel("Azimuth Angle (deg)") |
| 95 | plt.ylabel("Abundance") | 94 | plt.ylabel("Abundance") |
| 96 | plt.title("Azimuth distribution") | 95 | plt.title("Azimuth distribution") |
| 97 | 96 | ||
| @@ -101,7 +100,7 @@ if __name__ == "__main__": | @@ -101,7 +100,7 @@ if __name__ == "__main__": | ||
| 101 | omin = min(offsets) | 100 | omin = min(offsets) |
| 102 | omax = max(offsets) | 101 | omax = max(offsets) |
| 103 | plt.hist(offsets, bins=30, range=(omin, omax),fc='blue') | 102 | plt.hist(offsets, bins=30, range=(omin, omax),fc='blue') |
| 104 | - plt.xlabel("Offset from (RA, DEC)=("+str(ra)+","+str(dec)+") [deg]") | 103 | + plt.xlabel("Offset from (RA, DEC)=("+str(ra)+","+str(dec)+") (deg)") |
| 105 | plt.ylabel("Abundance") | 104 | plt.ylabel("Abundance") |
| 106 | plt.title("Offset distribution") | 105 | plt.title("Offset distribution") |
| 107 | 106 | ||
| @@ -116,7 +115,7 @@ if __name__ == "__main__": | @@ -116,7 +115,7 @@ if __name__ == "__main__": | ||
| 116 | plt.figure() | 115 | plt.figure() |
| 117 | plt.hist(emin, bins=80, range=(-1.0, 2.0), fc='red',label="emin") | 116 | plt.hist(emin, bins=80, range=(-1.0, 2.0), fc='red',label="emin") |
| 118 | plt.hist(emax, bins=80, range=(-1.0, 2.0), fc='blue', label ="emax") | 117 | plt.hist(emax, bins=80, range=(-1.0, 2.0), fc='blue', label ="emax") |
| 119 | - plt.xlabel("Energy threshold [log10 (E/TeV)]") | 118 | + plt.xlabel("Energy threshold (log10 (E/TeV))") |
| 120 | plt.ylabel("Abundance") | 119 | plt.ylabel("Abundance") |
| 121 | plt.legend(loc="upper left") | 120 | plt.legend(loc="upper left") |
| 122 | plt.title("Energy threshold") | 121 | plt.title("Energy threshold") |
| @@ -128,8 +127,8 @@ if __name__ == "__main__": | @@ -128,8 +127,8 @@ if __name__ == "__main__": | ||
| 128 | tmean = gti.tstart(i) + 0.5*(gti.tstart(i)-gti.tstart(i)) | 127 | tmean = gti.tstart(i) + 0.5*(gti.tstart(i)-gti.tstart(i)) |
| 129 | times.append(tmean.mjd()) | 128 | times.append(tmean.mjd()) |
| 130 | plt.plot(times, zeniths, 'o',lw=2.0, color='black') | 129 | plt.plot(times, zeniths, 'o',lw=2.0, color='black') |
| 131 | - plt.xlabel("Time [MJD]") | ||
| 132 | - plt.ylabel("Zenith Angle [deg]") | 130 | + plt.xlabel("Time (MJD)") |
| 131 | + plt.ylabel("Zenith Angle (deg)") | ||
| 133 | plt.title("Observation time") | 132 | plt.title("Observation time") |
| 134 | 133 | ||
| 135 | # Show plots | 134 | # Show plots |