gbrammer / grizli

Grizli: The "Grism redshift and line" analysis software
MIT License
68 stars 51 forks source link

Propagate WCS alignment to `gwcs` keywords #81

Open gbrammer opened 2 years ago

gbrammer commented 2 years ago

The alignment scripts in prep now appear to work for the SIP headers generated for JWST exposures, but the alignment updates (shifts, rotation, scale) aren't propagated to the keywords that are read when running the assignWCS pipeline step. These seem to be RA_REF, DEC_REF and ROLL_REF / PA_V3 in the SCI extension of the FITS files. It's not necessarily true that the REF position is the same as the SIP CRPIX pixel, so the shifts and rotation derived to align the SIP headers may not necessarily be the same for gwcs, depending on the order of operations.

gbrammer commented 2 years ago

This is implemented in jwst_utils.match_gwcs_to_sip, but isn't yet run in the pipeline.

jdavies-st commented 2 years ago

You can also use the tweakwcs package directly with the GWCS objects for the JWST data without using SIP FITS WCS approximations at all. I.e. tweak the GWCS objects directly to get alignment.

https://tweakwcs.readthedocs.io/en/latest/index.html

The tweakwcs package is actually what is running under-the-hood in jwst.tweakreg.

gbrammer commented 2 years ago

Thanks @jdavies-st. I agree, but the reason to implement things this way in grizli with the SIP headers is so that I can make consistent WCS between HST and JWST instruments and use the same (old) low-level drizzle code with both of them. I can generate SIP headers with forward/reverse transformations that agree with the GWCS objects to a small fraction of a pixel, though this required a bit of extra work beyond the existing gwcs method to generate the SIP WCS.

jdavies-st commented 2 years ago

Cool. This might be something you can outsource to jwst.tweakreg, as it also (after tweaking), re-fits the SIP approximation so it resembles HST data.

Or if you don't like the SIP fitting or tweaking currently in jwst.tweakreg, you could keep it internal in grizli and use your own SIP approximation, i.e. in grizli use tweakwcs to do the JWST tweaking, then do your own SIP fitting afterwards.

Btw, if you find that your SIP fitting works better (or is more reliable) than that in the JWST pipeline, then you may want to push those changes or fixes upstream to jwst package. Would be great to get the best versions of the algorithms used consistently across both packages. 👍

gbrammer commented 2 years ago

Agreed. I'll look into the jwst.tweakreg version to see if it's better than what I was testing last summer. I'm sorry to admit I generally haven't updated my jwst module for quite some time, trying to leave well enough alone, but some of these things might be fixed by now.