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

JP-3753: Refactor extract1d #8961

Merged
merged 61 commits into from
Dec 12, 2024
Merged

Conversation

melanieclarke
Copy link
Collaborator

@melanieclarke melanieclarke commented Nov 14, 2024

Resolves JP-3753
Resolves JP-3813
Partially addresses JP-3432

Significant refactor for extract1d, to improve code organization, maintainability, and efficiency, as well as set up for PSF-based extraction, to be added in the future.

Tasks

  • request a review from someone specific, to avoid making the maintainers review every PR
  • add a build milestone, i.e. Build 11.3 (use the latest build if not sure)
  • Does this PR change user-facing code / API? (if not, label with no-changelog-entry-needed)
    • write news fragment(s) in changes/: echo "changed something" > changes/<PR#>.<changetype>.rst (see below for change types)
    • update or add relevant tests
    • update relevant docstrings and / or docs/ page
    • start a regression test and include a link to the running job (click here for instructions)
      • Do truth files need to be updated ("okified")?
        • after the reviewer has approved these changes, run okify_regtests to update the truth files
  • if a JIRA ticket exists, make sure it is resolved properly
news fragment change types...
  • changes/<PR#>.general.rst: infrastructure or miscellaneous change
  • changes/<PR#>.docs.rst
  • changes/<PR#>.stpipe.rst
  • changes/<PR#>.datamodels.rst
  • changes/<PR#>.scripts.rst
  • changes/<PR#>.fits_generator.rst
  • changes/<PR#>.set_telescope_pointing.rst
  • changes/<PR#>.pipeline.rst

stage 1

  • changes/<PR#>.group_scale.rst
  • changes/<PR#>.dq_init.rst
  • changes/<PR#>.emicorr.rst
  • changes/<PR#>.saturation.rst
  • changes/<PR#>.ipc.rst
  • changes/<PR#>.firstframe.rst
  • changes/<PR#>.lastframe.rst
  • changes/<PR#>.reset.rst
  • changes/<PR#>.superbias.rst
  • changes/<PR#>.refpix.rst
  • changes/<PR#>.linearity.rst
  • changes/<PR#>.rscd.rst
  • changes/<PR#>.persistence.rst
  • changes/<PR#>.dark_current.rst
  • changes/<PR#>.charge_migration.rst
  • changes/<PR#>.jump.rst
  • changes/<PR#>.clean_flicker_noise.rst
  • changes/<PR#>.ramp_fitting.rst
  • changes/<PR#>.gain_scale.rst

stage 2

  • changes/<PR#>.assign_wcs.rst
  • changes/<PR#>.badpix_selfcal.rst
  • changes/<PR#>.msaflagopen.rst
  • changes/<PR#>.nsclean.rst
  • changes/<PR#>.imprint.rst
  • changes/<PR#>.background.rst
  • changes/<PR#>.extract_2d.rst
  • changes/<PR#>.master_background.rst
  • changes/<PR#>.wavecorr.rst
  • changes/<PR#>.srctype.rst
  • changes/<PR#>.straylight.rst
  • changes/<PR#>.wfss_contam.rst
  • changes/<PR#>.flatfield.rst
  • changes/<PR#>.fringe.rst
  • changes/<PR#>.pathloss.rst
  • changes/<PR#>.barshadow.rst
  • changes/<PR#>.photom.rst
  • changes/<PR#>.pixel_replace.rst
  • changes/<PR#>.resample_spec.rst
  • changes/<PR#>.residual_fringe.rst
  • changes/<PR#>.cube_build.rst
  • changes/<PR#>.extract_1d.rst
  • changes/<PR#>.resample.rst

stage 3

  • changes/<PR#>.assign_mtwcs.rst
  • changes/<PR#>.mrs_imatch.rst
  • changes/<PR#>.tweakreg.rst
  • changes/<PR#>.skymatch.rst
  • changes/<PR#>.exp_to_source.rst
  • changes/<PR#>.outlier_detection.rst
  • changes/<PR#>.tso_photometry.rst
  • changes/<PR#>.stack_refs.rst
  • changes/<PR#>.align_refs.rst
  • changes/<PR#>.klip.rst
  • changes/<PR#>.spectral_leak.rst
  • changes/<PR#>.source_catalog.rst
  • changes/<PR#>.combine_1d.rst
  • changes/<PR#>.ami.rst

other

  • changes/<PR#>.wfs_combine.rst
  • changes/<PR#>.white_light.rst
  • changes/<PR#>.cube_skymatch.rst
  • changes/<PR#>.engdb_tools.rst
  • changes/<PR#>.guider_cds.rst

Copy link

codecov bot commented Nov 14, 2024

Codecov Report

Attention: Patch coverage is 95.06579% with 15 lines in your changes missing coverage. Please review.

Project coverage is 66.76%. Comparing base (e38bf84) to head (67bef53).
Report is 65 commits behind head on main.

Files with missing lines Patch % Lines
jwst/extract_1d/extract_1d_step.py 88.69% 13 Missing ⚠️
jwst/extract_1d/ifu.py 94.11% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8961      +/-   ##
==========================================
+ Coverage   64.56%   66.76%   +2.20%     
==========================================
  Files         375      375              
  Lines       38890    37948     -942     
==========================================
+ Hits        25109    25336     +227     
+ Misses      13781    12612    -1169     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@melanieclarke
Copy link
Collaborator Author

melanieclarke commented Nov 15, 2024

Initial regression test run here:
https://github.com/spacetelescope/RegressionTests/actions/runs/11846882332
Total test time is about 15 minutes shorter than an equivalent run on main.

There are differences in every x1d and x1dints product, but they are all minor:

  • DQ array is now updated to set DO_NOT_USE where output flux is NaN. The previous version was not setting DQ in a useful way.
  • Flux and background errors are different for apertures that include partial pixels. This is because the variance propagation in the current version is incorrect: variances in partial pixels are currently weighted by the pixel fraction, like the science data is, but they should be weighted by pixel fraction squared. The weights are fixed in this version.
  • In x1dints files, extraction start/stop values are now added to the headers for spectra from all integrations, not just the first integration.
  • Left and right extraction limit values are now directly set from the aperture edges, where they first go to zero, instead of from the input extraction parameters. This makes a one pixel difference to the MIRI LRS slitless EXTRYSTR/EXTRYSTP values (test_miri_lrs_slitless_tso_spec2[x1dints]).
  • Approximate extraction start/stop values are added to the headers for spectra extracted with polynomial src_coeff parameters. Before, there was no information about the extraction location in this case (test_nirspec_bots_custom_extraction).

This small change also appears in these results (attempt 1), but probably shouldn't:

  • Background values are usually zero if there is no background data, but they are now sometimes NaN at the edges of spectra, where they used to be zero.

I will modify the code to make sure all background values are finite. Test attempt 2 at the same link above incorporates this change.

Copy link
Collaborator Author

@melanieclarke melanieclarke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am self-reviewing this PR to add some annotations and point out a few changes to specific people. I'm hoping that will make this large PR easier to review. Please let me know if there's anything else I can do to assist or clarify.

jwst/datamodels/container.py Show resolved Hide resolved
Comment on lines +86 to +88
Note that the pipeline takes input start/stop values from the reference files to be
zero-indexed positions, but all extraction values are recorded in the headers as one-indexed
values, following FITS header conventions.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note added to document that FITS header values are 1 off from input and logged start/stop values.

Comment on lines +131 to +132
The DQ array is set to DO_NOT_USE for pixels with NaN flux values and zero
otherwise.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note added for DQ handling change.

Comment on lines +284 to +287
Please note that this is different from the convention used for the cross-dispersion
start/stop values, which are expected to be inclusive index values. For the example here,
for horizontal dispersion, `ystart = 325`, `ystop = 335` is equivalent
to `src_coeff = [[324.5],[335.5]]`. To include half a pixel more at the top
and bottom of the aperture, `ystart = 324.5`, `ystop = 335.5` is equivalent
to `src_coeff = [[324],[336]]`.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note added to clarify the interpretation difference between start/stop values and polynomial coefficients.

(in microns) or pixel number (pixels in the dispersion direction, with respect to
the input 2D slit image), which is specified by the parameter ``independent_var``.
The default is "pixel". The values of these polynomial functions are pixel numbers in the
direction perpendicular to dispersion.

.. _extract-1d-for-ifu:

Extraction for 3D IFU Data
Copy link
Collaborator Author

@melanieclarke melanieclarke Dec 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation changes for IFU extraction in this file are for style only.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes in this file are just to remove the image-type reference file, which is no longer supported. Only ASDF reference files are now supported for IFU extractions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file adds/relocates some test fixtures for mock data that can pass through various parts of the extraction routines.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file adds complete unit test coverage for the jwst.extract_1d.extract module.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file now includes complete statement coverage for the extract_1d_step interface: all supported modes are tested for basic step completion. NIRISS SOSS takes too long to complete, so it is marked as slow - it will not run with basic CI tests. It will run with the regression tests.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a new regression test, added to exercise aperture definition via source coefficients. Truth data on artifactory was generated with the main branch, so any diffs are due to the refactoring in this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants