Commit 97cf14031ff7d4f02715cb8977282950efdbf815
1 parent
c6aa9b8e
Add comments
Showing
1 changed file
with
15 additions
and
5 deletions
examples/make_spectrum.py
| ... | ... | @@ -125,17 +125,21 @@ def plot_spectrum(spectrum, plotfile): |
| 125 | 125 | ul_ed_engs = [] |
| 126 | 126 | ul_eu_engs = [] |
| 127 | 127 | ul_flux = [] |
| 128 | - | |
| 129 | - # Loop over rows of the file | |
| 128 | + | |
| 129 | + # Get number of spectral points | |
| 130 | 130 | nrows = table.nrows() |
| 131 | + | |
| 132 | + # Loop over rows of the file | |
| 131 | 133 | for row in range(nrows): |
| 132 | 134 | |
| 133 | - # Get TS | |
| 135 | + # Get TS value, flux and flux error | |
| 134 | 136 | ts = c_ts.real(row) |
| 135 | 137 | flx = c_flux.real(row) |
| 136 | 138 | e_flx = c_eflux.real(row) |
| 137 | 139 | |
| 138 | - # Switch | |
| 140 | + # If the TS > 9 and the flux error is smaller than the flux then | |
| 141 | + # take the fitted flux and flux error and append them to the | |
| 142 | + # arrays | |
| 139 | 143 | if ts > 9.0 and e_flx < flx: |
| 140 | 144 | |
| 141 | 145 | # Add information |
| ... | ... | @@ -145,7 +149,8 @@ def plot_spectrum(spectrum, plotfile): |
| 145 | 149 | eu_engs.append(c_eu.real(row)) |
| 146 | 150 | e_flux.append(c_eflux.real(row)) |
| 147 | 151 | |
| 148 | - # | |
| 152 | + # ... otherwise take the upper limit and append it to the upper | |
| 153 | + # limit array | |
| 149 | 154 | else: |
| 150 | 155 | |
| 151 | 156 | # Add information |
| ... | ... | @@ -161,10 +166,15 @@ def plot_spectrum(spectrum, plotfile): |
| 161 | 166 | # Plot the spectrum |
| 162 | 167 | plt.loglog() |
| 163 | 168 | plt.grid() |
| 169 | + | |
| 170 | + # Plot error bars for flux points and upper limits for upper limit | |
| 171 | + # points | |
| 164 | 172 | plt.errorbar(energies, flux, yerr=e_flux, xerr=[ed_engs, eu_engs], |
| 165 | 173 | fmt='ro') |
| 166 | 174 | plt.errorbar(ul_energies, ul_flux, xerr=[ul_ed_engs, ul_eu_engs], |
| 167 | 175 | yerr=1.0e-11, uplims=True, fmt='ro') |
| 176 | + | |
| 177 | + # Add plot labels | |
| 168 | 178 | plt.xlabel('Energy (TeV)') |
| 169 | 179 | plt.ylabel(r'E$^{2}$dN/dE (erg cm$^{-2}$ s$^{-1}$)') |
| 170 | 180 | ... | ... |