def make_empty_cube(image_size, energy, center, data_unit=""): """ Parameters ---------- image_size:int, Total number of pixel of the 2D map energy: Energybounds center: SkyCoord of the source unit : str, Data unit. """ def_image = dict() def_image["nxpix"] = image_size def_image["nypix"] = image_size def_image["binsz"] = 0.02 def_image["xref"] = center.galactic.l.deg def_image["yref"] = center.galactic.b.deg def_image["proj"] = 'TAN' def_image["coordsys"] = 'GAL' def_image["unit"] = data_unit e_min = energy[0] e_max = energy[-1] nbins = len(energy) - 1 empty_cube = SkyCube.empty(emin=e_min.value, emax=e_max.value, enumbins=nbins, eunit=e_min.unit, mode='edges', **def_image) return empty_cube
def make_ref_cube(config): WCS_SPEC = { 'nxpix': config['binning']['nxpix'], 'nypix': config['binning']['nypix'], 'binsz': config['binning']['binsz'], 'xref': config['pointing']['ra'], 'yref': config['pointing']['dec'], 'proj': config['binning']['proj'], 'coordsys': config['binning']['coordsys'], } # define reconstructed energy binning ENERGY_SPEC = { 'mode': 'edges', 'enumbins': config['binning']['enumbins'], 'emin': config['selection']['emin'], 'emax': config['selection']['emax'], 'eunit': 'TeV', } CUBE_SPEC = {} CUBE_SPEC.update(WCS_SPEC) CUBE_SPEC.update(ENERGY_SPEC) cube = SkyCube.empty(**CUBE_SPEC) return cube
'xref': 83.63, 'yref': 22.01, 'proj': 'TAN', 'coordsys': 'CEL' } # define reconstructed energy binning ENERGY_SPEC = { 'mode': 'edges', 'enumbins': 5, 'emin': 0.5, 'emax': 40, 'eunit': 'TeV' } REF_CUBE = SkyCube.empty(emin=0.5, emax=40.0, enumbins=5, **WCS_SPEC) # setting up the data store data_store = DataStore.from_dir("$GAMMAPY_EXTRA/test_datasets/cube/data") # temporary fix for load psftable for one of the run that is not implemented yet... data_store.hdu_table.remove_row(14) # read in TeVCat exclusion mask exclusion_mask = SkyImage.read( '$GAMMAPY_EXTRA/datasets/exclusion_masks/tevcat_exclusion.fits') # reproject exclusion mask to reference cube exclusion_mask = exclusion_mask.reproject(reference=REF_CUBE.sky_image_ref, order='nearest-neighbor') exclusion_mask.show() #Select the offset band on which you want to select the events in the FOV of each observation
# define reconstructed energy binning ENERGY_SPEC = { 'mode': 'edges', 'enumbins': 5, 'emin': 0.5, 'emax': 40, 'eunit': 'TeV' } # From this we create an empty `SkyCube` object, that we will use as reference for all other sky cube data: # In[5]: # instanciate reference cube REF_CUBE = SkyCube.empty(**WCS_SPEC, **ENERGY_SPEC) # Next we create a `DataStore` object, which allows us to access and load DL3 level data. In this case we will use four Crab runs of simulated HESS data, which is bundled in gammapy-extra: # In[6]: # setting up the data store data_store = DataStore.from_dir("$GAMMAPY_EXTRA/test_datasets/cube/data") # temporary fix for load psftable for one of the run that is not implemented yet... data_store.hdu_table.remove_row(14) # For the later background estimation we define an exclusion mask. The background image will normalized on the counts map outside the exclusion region (the so called FOV background method). For convenience we use and all-sky exclusin mask, which was created from the TeVCat catalog and reproject it to our analysis region: # In[7]:
dirname = '$GAMMAPY_EXTRA/datasets/hess-crab4-hd-hap-prod2' log.info('Reading data from {}'.format(dirname)) data_store = DataStore.from_dir(dirname) obs = data_store.obs(23523) events = obs.events log.info('Number of events in event list: {}'.format(len(events))) log.info('Max. event energy: {}'.format(events['ENERGY'].max())) log.info('Min. event energy: {}'.format(events['ENERGY'].min())) aeff = obs.aeff counts = SkyCube.empty(emin=0.5, emax=80, enumbins=8, eunit='TeV', nxpix=200, nypix=200, xref=events.meta['RA_OBJ'], yref=events.meta['DEC_OBJ'], dtype='int', coordsys='CEL') log.info('Bin events into cube.') counts.fill_events(events) log.info('Counts cube shape: {}'.format(counts.data.shape)) log.info('Number of events in cube: {}'.format(counts.data.sum())) counts.write('counts.fits.gz', format='fermi-counts', clobber=True) # Exposure cube pointing = SkyCoord(events.meta['RA_PNT'], events.meta['DEC_PNT'], "icrs",
from gammapy.cube import exposure_cube, SkyCube from gammapy.utils.energy import EnergyBounds dirname = '$GAMMAPY_EXTRA/datasets/hess-crab4-hd-hap-prod2' log.info('Reading data from {}'.format(dirname)) data_store = DataStore.from_dir(dirname) obs = data_store.obs(23523) events = obs.events log.info('Number of events in event list: {}'.format(len(events))) log.info('Max. event energy: {}'.format(events['ENERGY'].max())) log.info('Min. event energy: {}'.format(events['ENERGY'].min())) aeff = obs.aeff counts = SkyCube.empty(emin=0.5, emax=80, enumbins=8, eunit='TeV', nxpix=200, nypix=200, xref=events.meta['RA_OBJ'], yref=events.meta['DEC_OBJ'], dtype='int', coordsys='CEL') log.info('Bin events into cube.') counts.fill_events(events) log.info('Counts cube shape: {}'.format(counts.data.shape)) log.info('Number of events in cube: {}'.format(counts.data.sum())) counts.write('counts.fits.gz', format='fermi-counts', clobber=True) # Exposure cube pointing = SkyCoord(events.meta['RA_PNT'], events.meta['DEC_PNT'], "icrs", unit="deg") livetime = Quantity(events.meta['LIVETIME'], 's') exposure = exposure_cube(pointing, livetime, aeff2d=aeff, ref_cube=counts, offset_max=Quantity(2.5, 'deg')) log.info('Exposure cube shape: {}'.format(exposure.data.shape)) log.info('Exposure unit: {}'.format(exposure.data.unit))