def image_coordinates(infile, outfile, make_coordinate_maps, make_distance_map, overwrite): """Make maps that can be used to create profiles. The following images can be created: * LON -- Longitude coordinate * LAT -- Latitude coordinate * DIST -- Distance to mask * SOLID_ANGLE -- Solid angle """ from astropy.io import fits from gammapy.utils.fits import get_hdu from gammapy.image import SkyMap, ExclusionMask log.info('Reading {0}'.format(infile)) hdu = get_hdu(infile) out_hdus = fits.HDUList() if make_coordinate_maps: skymap = SkyMap.empty_like(hdu) log.info('Computing LON and LAT maps') lon, lat = skymap.coordinates() out_hdus.append(fits.ImageHDU(lon, hdu.header, 'LON')) out_hdus.append(fits.ImageHDU(lat, hdu.header, 'LAT')) if make_distance_map: excl = ExclusionMask.from_image_hdu(hdu) log.info('Computing DIST map') dist = excl.exclusion_distance out_hdus.append(fits.ImageHDU(dist, hdu.header, 'DIST')) log.info('Writing {0}'.format(outfile)) out_hdus.writeto(outfile, clobber=overwrite)
def look_up_image(infile, x, y, # pix, ): """Look up values in a map at given positions.""" from gammapy.utils.fits import get_hdu from gammapy.image import lookup log.debug('Reading {0}'.format(infile)) hdu = get_hdu(infile) value = lookup(hdu, x, y) print('Map value at position ({0}, {1}) is {2}'.format(x, y, value))
def look_up_image(infile, x, y, # pix, ): """Look up values in a map at given positions.""" import logging logging.basicConfig(level=logging.DEBUG, format='%(levelname)s - %(message)s') from gammapy.utils.fits import get_hdu from gammapy.image import lookup logging.debug('Reading {0}'.format(infile)) hdu = get_hdu(infile) value = lookup(hdu, x, y) print('Map value at position ({0}, {1}) is {2}'.format(x, y, value))
def look_up_image( infile, x, y, # pix, ): """Look up values in a map at given positions.""" import logging logging.basicConfig(level=logging.DEBUG, format='%(levelname)s - %(message)s') from gammapy.utils.fits import get_hdu from gammapy.image import lookup logging.debug('Reading {0}'.format(infile)) hdu = get_hdu(infile) value = lookup(hdu, x, y) print('Map value at position ({0}, {1}) is {2}'.format(x, y, value))
def coordinate_images(infile, outfile, make_coordinate_maps, make_distance_map, overwrite): """Make maps that can be used to create profiles. The following images can be created: * LON -- Longitude coordinate * LAT -- Latitude coordinate * DIST -- Distance to mask * SOLID_ANGLE -- Solid angle """ import logging logging.basicConfig(level=logging.DEBUG, format='%(levelname)s - %(message)s') from astropy.io import fits from gammapy.utils.fits import get_hdu logging.info('Reading {0}'.format(infile)) hdu = get_hdu(infile) out_hdus = fits.HDUList() if make_coordinate_maps: from gammapy.image import coordinates logging.info('Computing LON and LAT maps') lon, lat = coordinates(hdu) out_hdus.append(fits.ImageHDU(lon, hdu.header, 'LON')) out_hdus.append(fits.ImageHDU(lat, hdu.header, 'LAT')) if make_distance_map: from gammapy.image import exclusion_distance logging.info('Computing DIST map') dist = exclusion_distance(hdu.data) out_hdus.append(fits.ImageHDU(dist, hdu.header, 'DIST')) logging.info('Writing {0}'.format(outfile)) out_hdus.writeto(outfile, clobber=overwrite)
def image_coordinates(infile, outfile, make_coordinate_maps, make_distance_map, overwrite): """Make maps that can be used to create profiles. The following images can be created: * LON -- Longitude coordinate * LAT -- Latitude coordinate * DIST -- Distance to mask * SOLID_ANGLE -- Solid angle """ from astropy.io import fits from gammapy.utils.fits import get_hdu from gammapy.image import SkyMap, ExclusionMask log.info('Reading {0}'.format(infile)) hdu = get_hdu(infile) out_hdus = fits.HDUList() if make_coordinate_maps: skymap = SkyMap.empty_like(hdu) log.info('Computing LON and LAT maps') lon, lat = skymap.coordinates() out_hdus.append(fits.ImageHDU(lon, hdu.header, 'LON')) out_hdus.append(fits.ImageHDU(lat, hdu.header, 'LAT')) if make_distance_map: excl = ExclusionMask.read(hdu) log.info('Computing DIST map') dist = excl.exclusion_distance out_hdus.append(fits.ImageHDU(dist, hdu.header, 'DIST')) log.info('Writing {0}'.format(outfile)) out_hdus.writeto(outfile, clobber=overwrite)
from gammapy.utils.fits import get_hdu from gammapy.background import Cube import matplotlib.pyplot as plt irf_path = 'perf_prod2/South_5h/irf_file.fits.gz' table_hdu_bg = get_hdu(irf_path + '[BACKGROUND]') # Need to fix that table_hdu_bg.header['TTYPE7'] = 'Bgd' table_hdu_bg.header['TUNIT7'] = '1 / (MeV s sr)' # cube_bg = Cube.from_fits_table(table_hdu_bg, scheme='bg_cube') ### Bkg integrated on the entire FOV bkg_rate_diff = cube_bg.integral_images delta_energy = cube_bg.energy_edges[1:] - cube_bg.energy_edges[:-1] bkg_rate = bkg_rate_diff * delta_energy.to('MeV') plt.figure('bkg rate') plt.plot(cube_bg.energy_edges.log_centers.to('TeV'), bkg_rate, 'o', drawstyle='default') plt.axis([1.e-2, 1.e3, 1.e-8, 1.e2]) plt.loglog() plt.show(block=False)
from astropy import units as u from gammapy.utils.fits import get_hdu from gammapy.irf import EnergyDispersion2D import matplotlib.pyplot as plt irf_path = 'perf_prod2/South_5h/irf_file.fits.gz' table_hdu_disp = get_hdu(irf_path + '[ENERGY DISPERSION]') e_disp_2d = EnergyDispersion2D.from_fits(table_hdu_disp) # Theta values are weird, nedd to be investiguated: # THETA_LO: 0., 4.5 # THETA_HI: 4.5, 9.0 e_disp = e_disp_2d.to_energy_dispersion(offset=4.5 * u.deg) #plt.figure('edisp') #e_disp.plot_matrix() #plt.show()
from astropy.table import Table from astropy import units as u from gammapy.utils.fits import get_hdu from gammapy.irf import EffectiveAreaTable2D import matplotlib.pyplot as plt irf_path = 'perf_prod2/South_5h/irf_file.fits.gz' table_hdu_area = get_hdu(irf_path + '[EFFECTIVE AREA]') table_area = Table(table_hdu_area.data) # Needed fix table_area['ENERG_LO'].unit = u.TeV table_area['ENERG_HI'].unit = u.TeV table_area['THETA_LO'].unit = u.deg table_area['THETA_HI'].unit = u.deg table_area['EFFAREA'].unit = u.m * u.m table_area['EFFAREA_RECO'].unit = u.m * u.m # End eff_area_2d = EffectiveAreaTable2D.from_table(table_area) eff_area = eff_area_2d.to_effective_area_table(offset=0.5 * u.deg) plt.figure('AREA') ax = eff_area.plot() ax.set_yscale('log') plt.show(block=False)