||
天文学家、天文观测者往往手中有多张不同时间拍摄的图片,这些图片有时在天空中坐标接近,甚至有重合之处。为了对整片大区域有一个更加系统的了解,我们往往需要将多片区域进行拼接(mosaic)。
该文档关注使用Python已有的MontagePy包实现对于多个FITS文件的拼接
(Montage官网:http://montage.ipac.caltech.edu/)
具体代码如下:
# include packages from MontagePy.main import mGetHdr, mHdr, mImgtbl, mMakeHdr, mProjectQL, mAdd import os import shutil import glob def mkdir(filePath): ''' Delete the original file first and then initate a new one ''' try: shutil.rmtree(filePath) except: pass os.mkdir(filePath) def make_mosaic(pre_mosaic_path='./', proj_path = './proj/', final_path = './final/', output_name = 'final_mosaic.fits'): ''' ''' # create pre-mosaic image list rtn = mImgtbl(pre_mosaic_path, 'pre_mosaic.tbl') # update the process print("mImgtbl (pre-mosaic image table): " + str(rtn), flush=True) # create the header for the mosaic mMakeHdr('pre_mosaic.tbl', 'mosaic_template.hdr') mkdir(proj_path) for each in glob.glob('*.fits'): # reproject all the pre-mosaic fields into the same template header mProjectQL(each, proj_path + each[:-5] + '_proj.fits', pre_mosaic_path + 'mosaic_template.hdr') rtn = mImgtbl(proj_path, 'reprojected.tbl') # update the process print("mImgtbl (reprojected image table): " + str(rtn), flush=True) mkdir(final_path) # Add the reprojected images into one mosaic image rtn = mAdd('./', 'reprojected.tbl', 'mosaic_template.hdr', final_path+'final_mosaic.fits',debug=1) print("mAdd: " + str(rtn), flush=True)
使用方法:
在某目录下统一放置一系列待拼接的FITS文件和内容为上述的.py文件(.py自行创建即可,或者下载https://github.com/XFengwei/python-code/blob/master/Mosaic/mosaic2D.py)。然后,在该目录下运行此Python代码。最终图像将在final/final_mosaic.fits找到。
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-11-24 18:30
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社