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
Simplify ResampleStep output_wcs interface #7971
base: master
Are you sure you want to change the base?
Simplify ResampleStep output_wcs interface #7971
Conversation
Thanks for providing the example in the description of this PR. It has brought to my attention the usage of It appears that to retain the functionality in your example the resample step will need to be updated to use stdatamodels to open the file (which now supports AsdfInFits). I suspect this was not caught until now as the existing test uses an asdf file (instead of an AsdfInFits file) to supply the wcs. The changes in this PR to handle |
Ah, thanks @braingram. I will open with Any idea what sort of exception will be raised in the future in asdf if I try to open a FITS file with |
Using The error raised when a fits file is passed to
|
Now fixed in 2e8afbd Oh, and I see the |
Codecov ReportAll modified lines are covered by tests ✅
📢 Thoughts on this report? Let us know!. |
Thanks! Regression tests run with no errors: |
Actually, originally when I implemented this parameter, One thing that worries me is that it allows users to easily provide any data model as |
with asdf.open(input_wcs_file) as af: | ||
wcs = deepcopy(af.tree["wcs"]) | ||
except (KeyError, ValueError): | ||
# File is ImageModel or SlitModel with the wcs under meta |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be a SlitModel
in a ResampleStep
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Theoretically yes, but practically I think it will always be ImageModel
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is also called by ResampleSpecStep
, right?
Does passing an external WCS to spectral observations work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is also called by
ResampleSpecStep
, right? Does passing an external WCS to spectral observations work?
It should.
I do not think there is a test that actually uses an external reference WCS. |
Co-authored-by: Mihai Cara <mcara@users.noreply.github.com>
Right, just the unit test does, which I updated (perhaps not optimally). |
try: | ||
# File is ASDF file with a top-level wcs in the tree | ||
with asdf.open(input_wcs_file) as af: | ||
wcs = deepcopy(af.tree["wcs"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be too much burden to require the wcs
attribute in an asdf file to be under meta
as well, to make it uniform? An argument for this is that this pipeline is supposed to work equivalently with asdf files, so it's conceivable some time in the future the reference file will be an i2d.asdf
file with the wcs under model.meta.wcs
.
I think the uniformity of the file structure may help users, though if it's considered too much of a burden, I'd be OK with the current proposal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that would be an API change, as up to this point it's been required to be at the top level. I.e. this PR doesn't change that. I do know there's existing analysis code in the wild (ERO CEERS code on github) that specifically uses this functionality.
Agree it would be good to have consistency. Maybe better to move wcs
out of meta
instead, something we've talked about off and on before.
with asdf.open(input_wcs_file) as af: | ||
wcs = deepcopy(af.tree["wcs"]) | ||
except (KeyError, ValueError): | ||
# File is ImageModel or SlitModel with the wcs under meta |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is also called by ResampleSpecStep
, right?
Does passing an external WCS to spectral observations work?
with datamodels.open(input_wcs_file) as model: | ||
wcs = deepcopy(model.meta.wcs) | ||
if not output_shape: | ||
output_shape = model.data.shape[::-1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm reading this correctly, it means that if an external reference file is provided the data shape takes precedence to the bounding box of the WCS (assuming it exists too). Is this the correct decision? It seems to me the bounding_box should take precedence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not part of this PR but the line below (line 189) seems wrong, especially when wcs is None
I think another reason for not allowing FITS as reference files is that users may try to use the same reference files from I think this PR has a potential to open a lot of issues later unless everything is well documented and there are checks in the code to provide meaningful error messages for unsupported situations. Saving a WCS to a file is not very difficult: from jwst.datamodels import ImageModel
import asdf
im = ImageModel('resampled_i2d.fits')
af = asdf.AsdfFile({'wcs': im.meta.wcs})
af.write_to('ref_wcs.asdf')
# or
# asdf.AsdfFile({'wcs': ImageModel('resampled_i2d.fits').meta.wcs}).write_to('ref_wcs.asdf') |
This PR simplifies the interface to match a resampled output grid to an existing image in
ResampleStep
. Currently, one needs to do something like the following to resample data onto the same output grid as an existing reference mosaic:This PR improves the interface by not needing one to extract the wcs from the reference mosaic or figure out its data shape. Instead, just pass the reference mosaic itself as the output wcs:
I have also updated the
ResampleStep.spec
comments as these are not comments for use by developers, but are the documentation to thestrun
command line interface.Checklist for maintainers
CHANGES.rst
within the relevant release sectionHow to run regression tests on a PR