def convert_hpx(self, comp_id, freq_id, clobber=False):
"""
Convert the specified HEALPix map product to HPX projected FITS image.
Also add the metadata of the HPX image to the manifest.
Raises
------
IOError :
Output HPX image already exists and ``clobber=False``
"""
from astropy.io import fits
from .utils.healpix import healpix2hpx
#
root_dir = self.get_root_dir()
metadata = self.get_product(comp_id, freq_id)
infile = os.path.join(root_dir, metadata["healpix"]["path"])
outfile = os.path.splitext(infile)[0] + "_hpx.fits"
if os.path.exists(outfile):
if clobber:
os.remove(outfile)
logger.warning("Removed existing HPX image: %s" % outfile)
else:
raise IOError("Output HPX image already exists: %s" % outfile)
# Convert HEALPix map to HPX projected FITS image
logger.info("Converting HEALPix map to HPX image: %s" % infile)
hpx_data, hpx_header = healpix2hpx(infile)
hdu = fits.PrimaryHDU(data=hpx_data, header=hpx_header)
hdu.writeto(outfile)
logger.info("Converted HEALPix map to HPX image: %s" % outfile)
#
size = os.path.getsize(outfile)
md5 = calc_md5(outfile)
metadata["hpx"] = {
"path": os.path.relpath(outfile, root_dir),
"size": size,
"md5": md5,
}
return (outfile, size, md5)
评论列表
文章目录