spacetelescope / jwst

Python library for science observations from the James Webb Space Telescope
https://jwst-pipeline.readthedocs.io/en/latest/
Other
557 stars 164 forks source link

WCS transform doesn't round trip correctly in NIRCam grism TSO data #6730

Open stscijgbot-jp opened 2 years ago

stscijgbot-jp commented 2 years ago

Issue JP-2518 was created on JIRA by Bryan Hilbert:

I have been attempting to use the WCS to transform between coordinate systems in a NIRCam TSGRISM file. This is a simulated image that I ran through the pipeline in order to produce a calints product. When I start with a detector (x, y) position and transform to (RA, Dec, wavelength, order), and then translate the (wavelength, order) back to (x, y), I get a different location on the detector. I understand why the returned y position is always 34, since the trace in NIRCam TSGRISM data is always in row 34. But the returned x position is off by 1 from the input x position. Perhaps there is an indexing error somewhere? The distortion reference file used is the most recent, and has been shown to round trip correctly when used with NRC_IMAGE data.

from jwst import datamodels
file = 'jw88888001001_01101_00002-seg004_mod_nrca5_calints.fits'
model = datamodels.open(file)
detector_to_world = model.meta.wcs.get_transform('grism_detector', 'world')
world_to_detector = model.meta.wcs.get_transform('world', 'grism_detector')

detector_to_world(1024, 35)
Out[7]: (66.3708793654544, -30.600432289114096, 4.009287999972251, 1.0)

world_to_detector(4.009287999972251, 1.0)
Out[8]: (1023.003125201623, 33.996939314725864)

detector_to_world(1000, 31)
Out[13]: (66.3708793654544, -30.600432289114096, 3.985191999972259, 1.0)

world_to_detector(3.985191999972259, 1.0)
Out[14]: (999.0031252016232, 33.996939314725864)
stscijgbot-jp commented 1 year ago

Comment by Bryan Hilbert on JIRA:

Alicia Canipe has found that the error is also present when using 1.4.3dev version of the pipeline.

stscijgbot-jp commented 1 year ago

Comment by Nadia Dencheva on JIRA:

I am seeing the same problem with the new transforms in CRDS TEST and jwst in master

('1.10.2.dev44+g21c7b517a.d20230607').


In [77]: w.invert(3.994, 1)
Out[77]: (1013.7891919682044, 12.004197136997547)

In [78]: w(1013.7891919682044, 12.004197136997547)
Out[78]: (66.37083990211045, -30.600464677806144, 3.9911464686657685, 1.0)

In [79]: w.invert(3.9911464686657685, 1.0)
Out[79]: (1010.8598389755889, 12.009597229271925) ```
A difference of 0.00285 um in wavelength results in 3 pixels difference in grism detector coordinates. 
stscijgbot-jp commented 5 months ago

Comment by David Law on JIRA:

Bryan Hilbert Looks like I'm still seeing some similar issues, so I presume this is still a problem?

stscijgbot-jp commented 5 months ago

Comment by Bryan Hilbert on JIRA:

I tested this with the latest reference file (jwst_nircam_specwcs_0176.asdf), and I am still seeing some strange results.

from jwst import datamodels file = 'jw01068007001_03103_00001-seg001_nrcalong_assignwcsstep.fits' m = datamodels.open(file) m.meta.wcs.available_frames

Out[13]: ['grism_detector', 'direct_image', 'v2v3', 'v2v3vacorr', 'world']

grism2world = m.meta.wcs.get_transform('grism_detector', 'world') world2grism = m.meta.wcs.get_transform('world', 'grism_detector') direct2world = m.meta.wcs.get_transform('direct_image', 'world') world2direct = m.meta.wcs.get_transform('world', 'direct_image') direct2grism = m.meta.wcs.get_transform('direct_image', 'grism_detector') grism2direct = m.meta.wcs.get_transform('grism_detector', 'direct_image')

############################################## Check if the overall direct image -> world -> direct image round trips

world2direct(280.61482770168766, -8.401316189432961) (1580.5585748341891, 32.56682167139434, 280.61482770168766, -8.401316189432961)

direct2world(1580.5585748341891, 32.56682167139434, 3.3896682214197296, 1) (280.61486709769827, -8.40129540002189, 3.3896682214197296, 1.0)

Check the difference

(280.61486709769827 - 280.61482770168766) 3600. Out[81]: 0.14182563818394556 (-8.401316189432961+8.40129540002189) 3600 Out[80]: -0.07484187985511426 round trip is off by ~2 1/3 pixels in RA and just over 1 pixel in Dec ###############################################

############################################ Check if the direct image -> grism detector ->direct image round trips

direct2grism(1024, 56, 3.0, 1) Out[59]: (64.93806914639413, 34.21369687434901, 1.0) grism2direct(64.93806914639413, 34.21369687434901, 1.) Out[64]: (1581.0, 35.0, 2.4604435115959316, 1.0)

Am I using this wrong? This is far from round tripping correctly ############################################

############################################ Now let’s check the grism_detector -> world -> grism_detector round trip

grism2world(1024, 34, 1) Out[77]: (280.61482770168766, -8.401316189432961, 3.3896682214197296, 1.0) world2grism(3.3896682214197296, 1.0) Out[78]: (1023.5438291000191, 10.866191827996342, 1.0)

This is off by a little under half a pixel in x, and is not remotely close in y. Maybe that’s because the wavelength has (virtually) no y-dependence? #############################################

stscijgbot-jp commented 5 months ago

Comment by Bryan Hilbert on JIRA:

Hmm. I ran set_telescope_pointing.py on this file before running assign_wcs. But the latest SIAF updates are more recent than the reference file. Maybe that has something to do with it?