<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Generating a sky map and finding sources
In this tutorial you will learn how to generate a sky map from the selected events and how to find potential sources in the data.
As next step you will make a sky map of the selected events to inspect what’s in the data. You do this using the ctskymap tool. 
We start with the usual gammalib, ctools, and cscripts imports.
Step1:  We will use the matplotlib package to display the results.
Step2:  We will use the events selected in the previous step. Since the data correspond to observations of the Crab nebula we should centre the sky map on this source. The energy limits of the sky map should be set to the energy interval of the data (0.66 - 100 TeV).
Step3:  We can visualise the skymap.
Step4:  Based on the sky map you can now extract a model for all potentially significant sources in the data. You do this using the cssrcdetect script, and to extract only significant sources, you should set the detection threshold for example to 5 sigma. We will make a copy of the skymap since the detection process involves smoothing and we do not want to modify the original map.
Step5:  Let's look at the resulting model. It contains a point source Src001 at the position of the Crab nebula.
Step6:  We can overlay the position of the source we found to the smoothed skymap to make sure everything worked well.
<ASSISTANT_TASK:>
Python Code:
import gammalib
import ctools
import cscripts
Explanation: Generating a sky map and finding sources
In this tutorial you will learn how to generate a sky map from the selected events and how to find potential sources in the data.
As next step you will make a sky map of the selected events to inspect what’s in the data. You do this using the ctskymap tool. 
We start with the usual gammalib, ctools, and cscripts imports.
End of explanation
%matplotlib inline
import matplotlib.pyplot as plt
Explanation: We will use the matplotlib package to display the results.
End of explanation
obsfile = 'obs_crab_selected.xml'
emin    = 0.66
emax    = 100.0
skymap  = ctools.ctskymap()
skymap['inobs']       = obsfile
skymap['proj']        = 'CAR'
skymap['coordsys']    = 'CEL'
skymap['xref']        = 83.63
skymap['yref']        = 22.01
skymap['binsz']       = 0.02
skymap['nxpix']       = 200
skymap['nypix']       = 200
skymap['emin']        = emin
skymap['emax']        = emax
skymap['bkgsubtract'] = 'NONE'
skymap.run()
Explanation: We will use the events selected in the previous step. Since the data correspond to observations of the Crab nebula we should centre the sky map on this source. The energy limits of the sky map should be set to the energy interval of the data (0.66 - 100 TeV).
End of explanation
#module used to stretch the color palette
import matplotlib.colors as colors
ax = plt.subplot()
plt.imshow(skymap.skymap().array(),origin='lower',
            extent=[83.63+0.02*200,83.63-0.02*200,22.01-0.02*200,22.01+0.02*200],
            # boundaries of the coord grid
            norm=colors.PowerNorm(gamma=0.5),
            cmap=plt.get_cmap('jet')) # square root scale 
ax.set_xlabel('R.A. (deg)')
ax.set_ylabel('Dec (deg)')
cbar = plt.colorbar()
cbar.set_label('Counts')
Explanation: We can visualise the skymap.
End of explanation
srcmodel  = 'crab.xml'
regfile   = 'crab_sources.ds9'
srcdetect = cscripts.cssrcdetect(skymap.skymap().copy())
srcdetect['srcmodel']   = 'POINT'
srcdetect['bkgmodel']   = 'NONE' # we will determine the background model in a later step
srcdetect['threshold']  = 5
srcdetect['corr_rad']   =  0.1
srcdetect['outmodel']   = srcmodel
srcdetect['outds9file'] = regfile
srcdetect.execute()
Explanation: Based on the sky map you can now extract a model for all potentially significant sources in the data. You do this using the cssrcdetect script, and to extract only significant sources, you should set the detection threshold for example to 5 sigma. We will make a copy of the skymap since the detection process involves smoothing and we do not want to modify the original map.
End of explanation
models = gammalib.GModels(srcmodel)
print(models)
Explanation: Let's look at the resulting model. It contains a point source Src001 at the position of the Crab nebula.
End of explanation
ax1 = plt.subplot()
plt.imshow(srcdetect._map.array(),origin='lower',
            extent=[83.63+0.02*200,83.63-0.02*200,22.01-0.02*200,22.01+0.02*200],
            # boundaries of the coord grid
            cmap=plt.get_cmap('jet')) # square root scale 
ax1.set_xlabel('R.A. (deg)')
ax1.set_ylabel('Dec (deg)')
cbar = plt.colorbar()
cbar.set_label('Counts')
crab = models['Src001']
ax1.scatter(crab['RA'].value(),crab['DEC'].value(),
           marker='x',c='white')
Explanation: We can overlay the position of the source we found to the smoothed skymap to make sure everything worked well.
End of explanation
<END_TASK>