def from_hdulist(cls, hdulist, format="ogip"): """Read region table and convert it to region list. Parameters ---------- hdulist : `~astropy.io.fits.HDUList` HDU list format : {"ogip"} HDU format Returns ------- geom : `RegionGeom` Region map geometry """ if "REGION" in hdulist: region_table = Table.read(hdulist["REGION"]) parser = FITSRegionParser(region_table) pix_region = parser.shapes.to_regions() wcs = WCS(region_table.meta) regions = [] for reg in pix_region: regions.append(reg.to_sky(wcs)) region = list_to_compound_region(regions) else: region, wcs = None, None axis = MapAxis.from_table_hdu(hdulist["EBOUNDS"]) return cls(region=region, wcs=wcs, axes=[axis])
def from_hdulist(cls, hdulist, format="ogip", hdu=None): """Read region table and convert it to region list. Parameters ---------- hdulist : `~astropy.io.fits.HDUList` HDU list format : {"ogip", "ogip-arf", "gadf"} HDU format Returns ------- geom : `RegionGeom` Region map geometry """ region_hdu = "REGION" if format == "gadf" and hdu: region_hdu = hdu + "_" + region_hdu if region_hdu in hdulist: region_table = Table.read(hdulist[region_hdu]) parser = FITSRegionParser(region_table) pix_region = parser.shapes.to_regions() wcs = WcsGeom.from_header(region_table.meta).wcs regions = [] for reg in pix_region: regions.append(reg.to_sky(wcs)) region = list_to_compound_region(regions) else: region, wcs = None, None if format == "ogip": hdu_bands = "EBOUNDS" elif format == "ogip-arf": hdu_bands = "SPECRESP" elif format == "gadf": hdu_bands = hdu + "_BANDS" else: raise ValueError(f"Unknown format {format}") axes = MapAxes.from_table_hdu(hdulist[hdu_bands], format=format) return cls(region=region, wcs=wcs, axes=axes)
def from_hdulist(cls, hdulist, format="ogip"): """Read region table and convert it to region list.""" if "REGION" in hdulist: region_table = Table.read(hdulist["REGION"]) parser = FITSRegionParser(region_table) pix_region = parser.shapes.to_regions() wcs = WCS(region_table.meta) regions = [] for reg in pix_region: regions.append(reg.to_sky(wcs)) region = list_to_compound_region(regions) else: region, wcs = None, None ebounds = Table.read(hdulist["EBOUNDS"]) emin = ebounds["E_MIN"].quantity emax = ebounds["E_MAX"].quantity edges = edges_from_lo_hi(emin, emax) axis = MapAxis.from_edges(edges, interp="log", name="energy") return cls(region=region, wcs=wcs, axes=[axis])