Administrator
|
This post was updated on .
Multi-Extension FITS (MEF) files containing multiple images from detector arrays are not directly compatible with AIJ. However, the image array can be assembled into a single image FITS file using several methods.
The ideal method for Linux installations (and possibly OS X??) is to use swarp to assemble all of the MEF images into a mosaic which preserves the detector spacing and arrangement and results in a single image with valid WCS headers. swarp is available for download here: http://www.astromatic.net/software/swarp An example command line would be: swarp my_mef_file.fits -c swarp.default where swarp.default is a good start at appropriate settings for the task at hand. The swarp.default file is available here to help users get started: swarp.default If tracking and guiding are good for a time series of images, WCS headers are likely not required for apertures to track appropriate stars throughout the time series. In that case, a simple IDL/GDL or python script can be used to assemble the array of images into a single image, but because the images are edge-butted into an N x M array without accounting for the detector separation, a WCS solution is generally not possible on the resulting mosaic. AIJ users have written and graciously provided IDL/GDL and python scripts that will assemble multiple image arrays into a single image FITS image that is compatible with AIJ, but that does not account for the detector spacing. Again, if good tracking/guiding is maintained throughout the image sequence, differential photometry can likely be run on the composite images without proper spacing or WCS headers. If you understand your detector spacing precisely, you may be able to adjust the scripts to add the spacing into the mosaic and a WCS solution may then be possible. The first option requires IDL or the open source version GDL to run the script to convert a batch of images. The author offers this script as is and can't directly support it. But if you have questions, maybe other users could help out. This particular version of the script assembles the image extension [1] in the lower left, [2] in lower right, [3] in upper left, and [4] in upper right. That ordering may need to be changed depending on your detector array orientation and detector control software. In this case, the four detectors in the array produce square 2046x2046 pixel images and the resulting single image is then a 4092 x 4092 pixel image. The user will likely need to customize this procedure to handle their specific multi-detector array configuration. The IDL/GDL code is as follows: ---------------------------------------------------------------------------- pro convert_mef imagedir = "/yourpath/" naxis1 = 2046 naxis2 = 2046 readcol, ''+imagedir+'raw/image.list', imagename, format = 'a' filename = imagedir + 'raw/' + imagename nim = n_elements(filename) ;loop through the list of image files for n=0,nim-1 do begin ;combine each extension into one image rdfits_struct,filename[n],quadi, /silent im1 = quadi.im1 im2 = quadi.im2 im3 = quadi.im3 im4 = quadi.im4 image1 = im1[0:naxis1-1,0:naxis2-1] image2 = im2[0:naxis1-1,0:naxis2-1] image3 = im3[0:naxis1-1,0:naxis2-1] image4 = im4[0:naxis1-1,0:naxis2-1] image = dblarr(naxis1*2,naxis2*2) image[0:naxis1-1,0:naxis2-1] = image1 image[0:naxis1-1,naxis2:naxis2*2-1] = image3 image[naxis1:naxis1*2-1,0:naxis2-1] = image2 image[naxis1:naxis1*2-1,naxis2:naxis2*2-1] = image4 header = headfits(filename[n]) ;save processed image cimagename = strmid(imagename[n], 0, 22) writefits, imagedir+'pipeline/'+cimagename,image, header endfor return end -------------------------------------------------------------------------- The following python script provides the same functionality. Again, the script will likely need to be customized for your specific multi-detector configuration, but this should serve a good template for python users: -------------------------------------------------------------------------- #!/usr/bin/python # Extract images from a FITS Multi-Extension file import os import sys import numpy as np import pyfits from time import gmtime, strftime # for utc # Set output image size oxsize = 4096 oysize = 4096 # Set input image size ixsize = 2048 iysize = 2048 # Create a numpy array with zeros outimage = np.zeros((oxsize,oysize)) # Set verbose flag True to show headers and other information verbose = True # Set a clobber flag True so that images can be overwritten # Otherwise set it False for safety clobberflag = True if len(sys.argv) == 1: print " " print "Usage: fits_mef_to_fits_images.py meffile.fits" print " " sys.exit("Mosaic images from a fits Multi-Extension file\n") elif len(sys.argv) == 2: infile = sys.argv[1] else: print " " print "Usage: fits_mef_to_one_image.py meffile.fits" print " " sys.exit("Mosaic images from a fits Multi-Extension file\n") # Extract the base name of the MEF file filebase = os.path.splitext(os.path.basename(infile))[0] # Open the fits file readonly by default and create an input hdulist inlist = pyfits.open(infile) nimages = len(inlist) - 1 if (nimages < 1): print "This file does not appear to be a FITS MEF file." exit() if verbose: print "The file "+infile+" contains %d images: \n" %(nimages,) print inlist.info() print "" print "with the global header:" print inlist[0].header print "" # Merge the extension images into one numpy array # The pattern here depends on how the images were placed in the MEF outimage[0:ixsize-2,0:iysize-2] = inlist[1].data outimage[0:ixsize-2,iysize:oysize-2] = inlist[2].data outimage[ixsize:oxsize-2,0:iysize-2] = inlist[3].data outimage[ixsize:oxsize-2,iysize:oysize-2] = inlist[4].data # Write the array as a fits file file_time = strftime("%Y-%m-%d %H:%M:%S", gmtime()) outlist = pyfits.PrimaryHDU(outimage) outfile = filebase+"_mosaic.fits" outheader = outlist.header outheader['DATE'] = file_time outheader['history'] = 'Created by fits_mef_to_one_image.py' outheader['history'] = ' from '+infile outlist = pyfits.PrimaryHDU(outimage,outheader) outlist.writeto(outfile, clobber = clobberflag) if verbose: print "Combined Images written as %s \n" %(outfile,) exit() ---------------------------------------------------------------------- |
Free forum by Nabble | Edit this page |