def __init__(self, tag='repro', clobber=False): """dir should contain the cubes already as produced by prepare()""" self.tag = tag self.clobber = clobber # Use toal component as reference self.ref_file = filename(tag=tag) self.fitsimage = FITSimage(self.ref_file) # Construct vectors of glon, glat, energy e.g. for plotting ac = iu.axis_coordinates(self.fitsimage) self.glon = ac['GLON'] self.glat = ac['GLAT'] self.energy = 10 ** ac['PHOTON ENERGY'] # Read mask if there is one, else don't use a mask try: self.mask = fits.getdata('mask.fits') logging.info('Loaded mask.fits') except IOError: self.mask = 1 logging.info('mask.fits not found') try: self.area = fits.getdata('area.fits') logging.info('Loaded area.fits') except IOError: self.area = iu.area(self.fitsimage, deg=False) logging.info('area.fits not found')
def make_mask_and_area(ref_file, clobber=True): """Make the mask and area images for use by Galprop mask == 0 pixels are excluded, mask == 1 pixels are included""" ref_image = FITSimage(ref_file) mask = (ref_image.dat != 0).astype(np.uint8) mask_image = FITSimage(externaldata=mask, externalheader=ref_image.hdr) mask_image.writetofits('mask.fits', clobber=clobber) area = iu.area(ref_image, deg=False) area_image = FITSimage(externaldata=area, externalheader=ref_image.hdr) area_image.writetofits('area.fits', clobber=clobber)