Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moment Map plugin should write out moment map WCS too #1516

Closed
Jdaviz-Triage-Bot opened this issue Jul 21, 2022 · 0 comments · Fixed by #2009
Closed

Moment Map plugin should write out moment map WCS too #1516

Jdaviz-Triage-Bot opened this issue Jul 21, 2022 · 0 comments · Fixed by #2009
Labels
cubeviz feature Feature request

Comments

@Jdaviz-Triage-Bot
Copy link

Jdaviz-Triage-Bot commented Jul 21, 2022

Reporter: pllim

As requested by @PatrickOgle, even though we now display WCS in moment map images in Cubeviz, the WCS is kind of a hack and not really attached to Data.coords . As a result, when you save the moment map out to a FITS file, the file header has no WCS information, thus breaking round-trip.

The reason we do not attach the WCS to Data.coords properly for a moment map is because in order to do so, we have to slice the cube WCS to obtain only spatial WCS (3D to 2D). Unfortunately, that breaks CCDData conversion as CCDData does not take sliced WCS object. The proper fix is to stop using CCDData.

The quicker but more hacky fix is to insert WCS into the FITS header at the time of writing out the moment map image. Patrick provided some code on how he did this manually for his data but the code appears a little too specific (and also won't work with writing out as GWCS). Whoever takes this ticket should investigate whether a more generic solution is possible (e.g., see if we can slice the cube WCS and write the sliced WCS out without resorting to manually writing FITS header keywords one by one), but Patrick's code can be considered as a last-resort hack-fix.

# Create wcs dictionary wcs_dict extracted from original JWST cube:
with datamodels.open(miridir + fname) as mc:
    wcs_dict_2d = {"CTYPE1": mc.meta.wcsinfo.ctype2,
                   "CTYPE2": mc.meta.wcsinfo.ctype1,
                   "CRVAL1": mc.meta.wcsinfo.crval2,
                   "CRVAL2": mc.meta.wcsinfo.crval1,
                   "CDELT1": mc.meta.wcsinfo.cdelt2,
                   "CDELT2": mc.meta.wcsinfo.cdelt1,
                   "CRPIX1": mc.meta.wcsinfo.crpix2,
                   "CRPIX2": mc.meta.wcsinfo.crpix1}
w = fitswcs.WCS(wcs_dict_2d)
header = w.to_header()
data = np.flipud(np.swapaxes(h2_flux, 0, 1))
hdu = fits.PrimaryHDU(data, header=header)
hdul = fits.HDUList([hdu])
hdul.writeto('h2s2_model_totalflux.fits', overwrite=True)

🐱


DISCLAIMER: This issue was autocreated by the Jdaviz Issue Creation Bot on behalf of the reporter. If any information is incorrect, please contact Duy Nguyen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cubeviz feature Feature request
Projects
None yet
2 participants