spacetelescope / stcal

https://stcal.readthedocs.io/en/latest/
Other
10 stars 32 forks source link

HLA-1096: Added reproject and calculate_pixmap functions with high-level WCS #204

Closed s-goldman closed 1 year ago

s-goldman commented 1 year ago

Resolves HLA-1096

This PR adds the reproject and calculate_pixmap functions to the codebase. This code was based on a similar function for JWST. A main difference between the two is that this code assumes that we are using the high-level WCS API. Several unit tests are also added for the case of inputted strings, array, as well as an expected failure.

Checklist

codecov[bot] commented 1 year ago

Codecov Report

Patch coverage is 91.95% of modified lines.

Files Changed Coverage
src/stcal/alignment/util.py 83.72%
src/stcal/alignment/resample_utils.py 100.00%
tests/test_alignment.py 100.00%

:loudspeaker: Thoughts on this report? Let us know!.

s-goldman commented 1 year ago

I still need to test if calc_pixmap works with the fits high-level WCS.

s-goldman commented 1 year ago

@nden

Based off the logic of jwst.resample.calc_gwcs_pixmap(), stcal.alignment.resample_utils.calculate_pixmap() results in an array of shape (1, 1, NNNN).

I just wanted to make sure that this was the desired result, the jwst docs are a little unclear as to what is expected.

nden commented 1 year ago

@nden

Based off the logic of jwst.resample.calc_gwcs_pixmap(), stcal.alignment.resample_utils.calculate_pixmap() results in an array of shape (1, 1, NNNN).

The output array shape should be (xdim, ydim, 2). Is the shape above the result of an input "image" with one pixel? It's worth understanding why the shape is such as this is critical for understanding how drizzle works.

s-goldman commented 1 year ago

@nden Based off the logic of jwst.resample.calc_gwcs_pixmap(), stcal.alignment.resample_utils.calculate_pixmap() results in an array of shape (1, 1, NNNN).

The output array shape should be (xdim, ydim, 2). Is the shape above the result of an input "image" with one pixel? It's worth understanding why the shape is such as this is critical for understanding how drizzle works.

I was able to confirm that reproject is working as intended.

calculate_pixmap() now produces a shape of (xdim, ydim, 2), still confirming whether the values are what they are suppose to be.

s-goldman commented 1 year ago

A problem that I am struggling with is that I don't really understand what the desired output is. The JWST pipeline function calc_gwcs_pixmap docstrings says "Return a pixel grid map from input frame to output frame." This PR effectively produces a sequential set of pixel pairs, but I don't know if that is what we are looking for, and if that is the desired grid map. For example, using this function on two HST DRC images results in a grid with the following pairs.

Image 1: WCS Number of WCS axes: 2 CTYPE : 'RA---TAN' 'DEC--TAN'
CRVAL : 295.4878199441331 16.74436128476337
CRPIX : 517.5 546.0
CD1_1 CD1_2 : 7.72844666630127e-06 7.8353921743594e-06
CD2_1 CD2_2 : 7.8353921743594e-06 -7.7284466663012e-06
NAXIS : 1035 1092

Figure_0 Figure0_img

Image 2: WCS Number of WCS axes: 2 CTYPE : 'RA---TAN' 'DEC--TAN'
CRVAL : 295.4960551343897 16.73669900709708
CRPIX : 2065.0 2194.5
CD1_1 CD1_2 : 7.72774655855261e-06 7.83608266461336e-06
CD2_1 CD2_2 : 7.83608266461336e-06 -7.7277465585526e-06
NAXIS : 4130 4389

Figure_1 Figure1_img

PIXMAP output:

array([[[1540.16044947, 649.3685476 ], [1541.1604495 , 649.36867835], [1542.16044953, 649.3688091 ], ..., [2629.16048207, 649.51093258], [2630.1604821 , 649.51106333], [2631.16048213, 649.51119408]],

   [[1540.16031874,  650.36854767],
    [1541.16031877,  650.36867842],
    [1542.1603188 ,  650.36880917],
    ...,
    [2629.1603513 ,  650.51093265],
    [2630.16035133,  650.5110634 ],
    [2631.16035136,  650.51119414]],

   [[1540.16018801,  651.36854774],
    [1541.16018804,  651.36867849],
    [1542.16018807,  651.36880924],
    ...,
    [2629.16022054,  651.51093272],
    [2630.16022057,  651.51106347],
    [2631.16022059,  651.51119421]],

   ...,

   [[1540.02553724, 1681.36857915],
    [1541.02553723, 1681.36870989],
    [1542.02553722, 1681.36884064],
    ...,
    [2629.02552842, 1681.51096381],
    [2630.02552841, 1681.51109455],
    [2631.0255284 , 1681.5112253 ]],

   [[1540.0254065 , 1682.36857914],
    [1541.0254065 , 1682.36870989],
    [1542.02540649, 1682.36884063],
    ...,
    [2629.02539765, 1682.5109638 ],
    [2630.02539764, 1682.51109455],
    [2631.02539763, 1682.51122529]],

   [[1540.02527578, 1683.36857913],
    [1541.02527577, 1683.36870988],
    [1542.02527576, 1683.36884063],
    ...,
    [2629.02526688, 1683.51096379],
    [2630.02526687, 1683.51109454],
    [2631.02526686, 1683.51122529]]])
nden commented 1 year ago

style check is failing

nden commented 1 year ago

RTD does not build. @s-goldman Can you rebase on master?

s-goldman commented 1 year ago

RTD does not build. @s-goldman Can you rebase on master?

I am using mairan's branch stcal-alignment as my base, so it may be easier to merge with stcal-alignment and then have Mairan update his branch before merging.