<jupyter_start><jupyter_text>Let's created one by reading the Fermi-LAT 3FHL event list:<jupyter_code>events_3fh1 = EventList.read("/Users/dhruvkumar/Desktop/fermi-3fhl-gc-events.fits.gz")
# let's HAve a look at the data
events_3fh1.table
len(events_3fh1.table)
events_3fh1.table.colnames   # name of the columns
# Conversions along the units
x = events_3fh1.energy.to("GeV") # energy is in GeV
y = events_3fh1.energy.to("TeV") # energy is in TeV
x,y
events_3fh1.galactic
events_3fh1.time
events_3fh1.plot_image()
# select all events within a radius of 1 deg around center
from regions import CircleSkyRegion

center = SkyCoord("0d", "0d", frame="galactic")  # Centre
region = CircleSkyRegion(center, radius=1 * u.deg) # specify the region
events_gc_3fhl = events_3fh1.select_region(region) # select the region

# sort events by energy
events_gc_3fhl.table.sort("ENERGY")

# and show highest energy photon
events_gc_3fhl.energy[-1].to("TeV") # hightest Energy bust {As we have taken it from the last of table}<jupyter_output><empty_output><jupyter_text>Maps<jupyter_code>from gammapy.maps import Map
gc_3fh1 = Map.create(
    width=(30 * u.degree , 30*u.degree),
    skydir = center,
    proj="CAR",
    binsz=0.05 * u.degree,
    map_type="wcs",
    frame="galactic"
)
gc_3fh1
print(gc_3fh1.geom) # to get more idea about the geometry
gc_3fh1.fill_events(events_3fh1)
gc_3fh1.plot(stretch="sqrt",cmap='inferno');
gc_3fh1.fill_events(events_3fh1)
gc_3fh1.plot(stretch="log",cmap='inferno'); # Much sensetative
gc_3fh1.fill_events(events_3fh1)
gc_3fh1.plot(stretch="linear",cmap='inferno');
gc_3fh1.data
print(f"Total number of counts in the image: {gc_3fh1.data.sum():.0f}")
from gammapy.maps import MapAxis
energy_axis = MapAxis.from_energy_bounds(
    energy_min = "10 GeV", energy_max="3 TeV", nbin=5
)
print(energy_axis)
# 3D data Cube
gc_3fh1_cube = Map.create(
    width = (30*u.degree,30*u.degree),
    skydir = center,
    proj="CAR",
    binsz=0.05 * u.degree,
    map_type="wcs",
    frame = "galactic",
    axes =[energy_axis]
)
print(gc_3fh1_cube)
gc_3fh1_cube.fill_events(events_3fh1)
gc_3fh1_cube_smoothed = gc_3fh1_cube.smooth(
    kernel ="gauss",width=0.1 *u.degree
)
gc_3fh1_cube_smoothed.plot_interactive(cmap='inferno')
gc_3fh1_cube_smoothed.plot_grid(
    ncols=3 ,figsize=(16,12),cmap='inferno',stretch="sqrt"
);
gc_3fh1_cube_smoothed.plot_grid(
    ncols=3 ,figsize=(16,12),cmap='inferno',stretch="linear"
);
gc_3fh1_cube_smoothed.plot_grid(
    ncols=3 ,figsize=(16,12),cmap='inferno',stretch="log"
);<jupyter_output><empty_output><jupyter_text>__*We can also do a rectangular cutout of a certain region in the image:*__<jupyter_code># define centre and cutout of the rectangular region
center = SkyCoord(0,0,unit ='deg',frame ='galactic')
gc_3fh1_cutout = gc_3fh1_cube_smoothed.cutout(center,9*u.deg) # width of the cutout = 9 degrees
gc_3fh1_cutout.plot_interactive(stretch='sqrt',cmap='inferno'); # Great!!!<jupyter_output><empty_output><jupyter_text>Source Catalogs<jupyter_code>from gammapy.catalog import SourceCatalog3FHL
fermi_3fh1 = SourceCatalog3FHL("/Users/dhruvkumar/Desktop/gll_psch_v13.fit.gz")
fermi_3fh1.table<jupyter_output><empty_output><jupyter_text>--------  __*Important*__<jupyter_code># lets perform some operation on it
# sort table by signifience
fermi_3fh1.table.sort("Signif_Avg")
# invert the order to find the highest value and take top ten
Top_10_TS_3fh1 = fermi_3fh1.table[::-1][:10]
# print top ten signifientsources with association and source class
Top_10_TS_3fh1[["Source_Name","ASSOC1","ASSOC2","CLASS","Signif_Avg"]]
# Here, we get the top ten sources according to their Signif_Avg
# To Access an Individual Source 
PG_1553_3fh1 = fermi_3fh1["3FHL J1555.7+1111"]
type(PG_1553_3fh1)
print(PG_1553_3fh1) # all the imformation 
PG_1553_3fh1.data["RAJ2000"],PG_1553_3fh1.data["DEJ2000"] # like this we can handle indivaidual attricutes<jupyter_output><empty_output><jupyter_text>------<jupyter_code># To get the value of a particular attribute in the catalog
Crab_Nebula_3fh1 = fermi_3fh1["Crab Nebula"]
print(Crab_Nebula_3fh1.data["Signif_Avg"])
# Let's Plot of  the Sources on Image
ax = gc_3fh1.smooth("0.1 deg").plot(
    stretch="sqrt",cmap="inferno");

positions = fermi_3fh1.positions
ax.scatter(positions.data.lon.deg,
          positions.data.lat.deg,
          transform=ax.get_transform("icrs"),
          color ="w",
          marker ="x")<jupyter_output><empty_output><jupyter_text>__Spectral Models and Flux Points__ __In the previous section we learned how access basic data from individual sources in the catalog. Now we will go one step further and explore the full spectral information of sources.____As a first example we will start with the Crab Nebula:__<jupyter_code>crab_3fh1 = fermi_3fh1["Crab Nebula"]
crab_3fh1_model = crab_3fh1.sky_model()
print(crab_3fh1_model)
type(crab_3fh1_model) # it is now an SkyModel object
crab_3fh1_spec = crab_3fh1_model.spectral_model<jupyter_output><empty_output><jupyter_text>__The crab_3fhl.spectral_model is an instance of the PowerLaw2SpectralModel model, with the parameter values and errors taken from the 3FHL catalog.__*Let's plot the spectral model in the energy range between 10 GeV and 2000 GeV:*<jupyter_code>ax_crab_3fh1 = crab_3fh1_spec.plot(energy_bounds= [10, 2000] * u.GeV) # energy_bound is used insted of enegy_range
plt.ylabel("Flux[1/$cm^2$ s TeV]")<jupyter_output><empty_output><jupyter_text>__To compute the differential flux at 100 GeV we can simply call the model like normal Python function and convert to the desired units:__<jupyter_code>crab_3fh1_spec(100 * u.GeV).to("cm-2 s-1 GeV-1") # Flux at 100 GeV energy
crab_3fh1_spec([100,200,300] * u.GeV).to("cm-2 s-1 TeV-1") # Flux at 100,200,300 TeV energy
# Flux
crab_3fh1_spec.integral(
    energy_min = 10 * u.GeV, energy_max = 2 * u.TeV
).to("cm-2 s-1")
# Flux
crab_3fh1.data["Flux"]
# Energy Flux
crab_3fh1_spec.energy_flux(
    energy_min= 10*u.GeV,energy_max= 2*u.TeV 
).to("J m-2 s-1")
# Flux point data of Crab
print(crab_3fh1.flux_points)
crab_3fh1.flux_points.table
ax = crab_3fh1_spec.plot(energy_bounds=[10, 2000] * u.GeV, energy_power=2)

ax = crab_3fh1_spec.plot_error(energy_bounds=[10, 2000] * u.GeV,energy_power=2, facecolor="tab:blue")

fp = crab_3fh1.flux_points.to_sed_type("dnde")
fp.plot(ax=ax, energy_power=2);
help(FluxPoints)<jupyter_output>Help on class FluxPoints in module gammapy.estimators.points.core:

class FluxPoints(gammapy.estimators.map.core.FluxMaps)
 |  FluxPoints(data, reference_model, meta=None, gti=None, filter_success_nan=True)
 |  
 |  Flux points container.
 |  
 |  The supported formats are described here: :ref:`gadf:flux-points`
 |  
 |  In summary, the following formats and minimum required columns are:
 |  
 |  * Format ``dnde``: columns ``e_ref`` and ``dnde``
 |  * Format ``e2dnde``: columns ``e_ref``, ``e2dnde``
 |  * Format ``flux``: columns ``e_min``, ``e_max``, ``flux``
 |  * Format ``eflux``: columns ``e_min``, ``e_max``, ``eflux``
 |  
 |  Parameters
 |  ----------
 |  table : `~astropy.table.Table`
 |      Table with flux point data
 |  
 |  Attributes
 |  ----------
 |  table : `~astropy.table.Table`
 |      Table with flux point data
 |  
 |  Examples
 |  --------
 |  The `FluxPoints` object is most easily created by reading a file with
 |  flux points given in one of the formats documented[...]
{'fraction_non_alphanumeric': 0.12647738079065343, 'fraction_numerical': 0.044695014264366256, 'mean_word_length': 5.469244288224956, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '582600', 'license': 'MIT', 'n_tokens_mistral': 3075, 'n_tokens_neox': 2831, 'n_words': 617, 'path': 'GammaPy***.ipynb', 'repo_name': 'DhruvKumarPHY/Astronomy_-on_fingertips', 'size': '7361'}