def plot_source_spectra(name): plot_source_spectrum(source=SourceCatalog3FGL()[name], label="3FGL", color="r") plot_source_spectrum(source=SourceCatalog2FHL()[name], label="2FHL", color="g") plot_source_spectrum(source=SourceCatalog3FHL()[name], label="3FHL", color="b") ax = plt.gca() ax.set_ylim(1.0e-12, 7.0e-11) ax.set_xlim(1.0e-4, 2.0) ax.set_xlabel("Energy (TeV)") ax.set_ylabel("E^2 dN/dE (erg cm-2 s-1])") plt.legend(loc=0)
def plot_source_spectra(name): plot_source_spectrum(source=SourceCatalog3FGL()[name], label='Fermi 3FGL', color='r') plot_source_spectrum(source=SourceCatalog2FHL()[name], label='Fermi 2FHL', color='g') plot_source_spectrum(source=SourceCatalog1FHL()[name], label='Fermi 1FHL', color='c') plot_source_spectrum(source=SourceCatalog3FHL()[name], label='Fermi 3FHL', color='b') ax = plt.gca() ax.set_ylim(1.e-12, 7.e-11) ax.set_xlim(1.e-4, 2.) ax.set_xlabel('Energy (TeV)') ax.set_ylabel('E^2 dN/dE (erg cm-2 s-1])') plt.legend(loc=0)
def setup_class(cls): cls.cat = SourceCatalog2FHL()
def setup_class(cls): cls.cat = SourceCatalog2FHL() # Use 2FHL J0534.5+2201 (Crab) as a test source cls.source_name = "2FHL J0534.5+2201" cls.source = cls.cat[cls.source_name]
# # * Load builtins catalogs from [gammapy.catalog](http://docs.gammapy.org/dev/catalog/index.html) # * Sort and index the underlying Astropy tables # * Access data from individual sources # # Let's start with importing the 2FHL catalog object from the [gammapy.catalog](http://docs.gammapy.org/dev/catalog/index.html) submodule: # In[ ]: from gammapy.catalog import SourceCatalog2FHL # First we initialize the Fermi-LAT 2FHL catalog and directly take a look at the `.table` attribute: # In[ ]: fermi_2fhl = SourceCatalog2FHL( "$GAMMAPY_DATA/catalogs/fermi/gll_psch_v08.fit.gz") fermi_2fhl.table # This looks very familiar again. The data is just stored as an [astropy.table.Table](http://docs.astropy.org/en/stable/api/astropy.table.Table.html#astropy.table.Table) object. We have all the methods and attributes of the `Table` object available. E.g. we can sort the underlying table by `TS` to find the top 5 most significant sources: # # # In[ ]: # sort table by TS fermi_2fhl.table.sort("TS") # invert the order to find the highest values and take the top 5 top_five_TS_2fhl = fermi_2fhl.table[::-1][:5] # print the top five significant sources with association and source class
# # * Load builtins catalogs from [gammapy.catalog](http://docs.gammapy.org/dev/catalog/index.html) # * Sort and index the underlying Astropy tables # * Access data from individual sources # # Let's start with importing the 2FHL catalog object from the [gammapy.catalog](http://docs.gammapy.org/dev/catalog/index.html) submodule: # In[27]: from gammapy.catalog import SourceCatalog2FHL # First we initialize the Fermi-LAT 2FHL catalog and directly take a look at the `.table` attribute: # In[28]: fermi_2fhl = SourceCatalog2FHL( '$GAMMAPY_EXTRA/datasets/catalogs/fermi/gll_psch_v08.fit.gz') fermi_2fhl.table # This looks very familiar again. The data is just stored as an [astropy.table.Table](http://docs.astropy.org/en/stable/api/astropy.table.Table.html#astropy.table.Table) object. We have all the methods and attributes of the `Table` object available. E.g. we can sort the underlying table by `TS` to find the top 5 most significant sources: # # # In[29]: # sort table by TS fermi_2fhl.table.sort('TS') # invert the order to find the highest values and take the top 5 top_five_TS_2fhl = fermi_2fhl.table[::-1][:5] # print the top five significant sources with association and source class
"""Example how to plot Fermi-LAT catalog spectra. """ import matplotlib.pyplot as plt from gammapy.catalog import SourceCatalog3FGL, SourceCatalog2FHL from gammapy.utils.energy import EnergyBounds plt.style.use('ggplot') # load catalogs fermi_3fgl = SourceCatalog3FGL() fermi_2fhl = SourceCatalog2FHL() # access crab data by corresponding identifier crab_3fgl = fermi_3fgl['3FGL J0534.5+2201'] crab_2fhl = fermi_2fhl['2FHL J0534.5+2201'] ax = crab_3fgl.spectral_model.plot(crab_3fgl.energy_range, energy_power=2, label='Fermi 3FGL', color='r', flux_unit='erg-1 cm-2 s-1') ax.set_ylim(1e-12, 1E-9) # set up an energy array to evaluate the butterfly emin, emax = crab_3fgl.energy_range energy = EnergyBounds.equal_log_spacing(emin, emax, 100) butterfly_3fg = crab_3fgl.spectrum.butterfly(energy) butterfly_3fg.plot(crab_3fgl.energy_range, ax=ax, energy_power=2,