wtbarnes / mocksipipeline

Pipeline for producing synthetic images from the Multi-Order Spectral Imager (MOXSI)
MIT License
3 stars 1 forks source link

Refactor image stacking step to include all headers #33

Open wtbarnes opened 4 months ago

wtbarnes commented 4 months ago

The last step in the pipeline is to stack all of the images into a single array and write it to a FITS file. Currently, only one header is saved to the file which means only one WCS is saved. Instead, all headers should be saved in separate extensions. The following example script does this,

import pathlib
from mocksipipeline.util import stack_components

root = pathlib.Path('/Users/wtbarnes/Documents/codes/mocksipipeline/pipeline/results/soc-test-data/detector_images/')
filtergram_components = root.glob('filtergram*.fits')
spectrogram_components = root.glob('spectrogram*.fits')
all_components = sorted(filtergram_components) + sorted(spectrogram_components)

stacked_array = stack_components(all_components)

hdu_list = astropy.io.fits.HDUList()

# Create the image HDU
image_hdu = astropy.io.fits.ImageHDU(data=stacked_array.data[0], name='image data')
hdu_list.append(image_hdu)

for fname in all_components:
    cube = read_overlappogram(fname)
    hdu_list.append(astropy.io.fits.ImageHDU(header=astropy.io.fits.Header(cube.meta),
                                             name=fname.name.split('.')[0]))

hdu_list.writeto('/Users/wtbarnes/Desktop/all_components_with_meta.fits', overwrite=True)

There should also be some step that reads the image data from the first extension and can choose an appropriate extension to grab the metadata from.

wtbarnes commented 4 months ago

Another option would be to store all of the different possible WCS keys in a single header and label them with a different suffix, e.g. CTYPEA, PCIJB, etc. Then, a different WCS can be selected from the header upon instantiating the WCS object.

wtbarnes commented 4 months ago

This page has some instructions for building multi-extension FITS files: https://docs.astropy.org/en/stable/generated/examples/io/create-mef.html#sphx-glr-generated-examples-io-create-mef-py