Skip to content

JP-4446: Save wfss_contam dispersion calculation as pixel dispersion tables - #11090

Draft
emolter wants to merge 16 commits into
spacetelescope:mainfrom
emolter:JP-4446
Draft

emolter wants to merge 16 commits into
spacetelescope:mainfrom
emolter:JP-4446

Conversation

@emolter

@emolter emolter commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

Resolves JP-4446

Description

The primary aim of this PR is to permit saving and loading the geometric part of the dispersion calculation to/from disk as a pixel dispersion table (PDT). This is helpful for users for three reasons:

  1. Reduce runtime for users that want to experiment with flux modeling parameters in the step, since they will run the step multiple times.
  2. Reduce runtime for a near-future restructure of the WFSS spec2pipeline where aspects of wfss_contam need to be run both before and after background subtraction. (The internals of the refactor should also make this future split easier.)
  3. Enable outside-pipeline flux modeling workflows to avoid starting from scratch

The plan is NOT to enable this in operations, at least for now.

Please see the documentation updates for more details on the PDT file format and the new step-level parameters.

Secondary changes

A few other changes rode along here:

  • Renamed the old TracePDT to DispersionTransformInterpolator, to disambiguate this interpolation function (which is similar to but not exactly a PDT) from the real PDT that we are not saving
  • Changed the way chunking works. Now instead of every chunk (except the last) being exactly max_pixels_per_chunk in size, sources are now only ever split between chunks if they themselves contain more than max_pixels_per_chunk pixels. Multiple sources can still live within one chunk as long as their total size is smaller than max_pixels_per_chunk. This makes it much easier to parallelize PDT save/load while keeping files organized sensibly. It also means that in general more chunks are created, but this effect is mostly unimportant in practice.

Runtime Profiling

Total runtime of WfssContamStep based on cProfile for jw04043001001_02101_00001_nrcblong, where we're just requesting a flat flux model and running on a single core:

  • main branch: 229s
  • creating PDT from scratch and saving: 257s, of which 25s is in write_pdt_to_files which makes sense
  • reusing PDT from file: 90s, of which 17s is in _open_asdf

Note that the save/load operations are located within the multiprocessing context, i.e., they run in parallel if max_cores > 1, so the runtime hit is not so severe in that case.

The refactor also made the code slightly faster in the case that polynomial fitting was requested. The main reason for this is that the basis models are now evaluated on the wavelengths once and then their values are indexed according to the wavelength_index that we already have to compute, as opposed to evaluating the models on every redundant per-dispersed-pixel wavelength. For the same dataset requesting polyfit_degree=3, this saves ~60s when run on a single core (less impact on wall clock time with more cores).

Tasks

  • If you have a specific reviewer in mind, tag them.
  • add a build milestone, i.e. Build 12.0 (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 changelog readme for instructions)
      • if your change breaks step-level or public API (as defined in the docs), also add a changes/<PR#>.breaking.rst news fragment
    • 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

Generative AI Usage Disclosure

GenAI tools were used fairly extensively in preparation of this PR (Claude Sonnet 5 via GitHub Copilot). Specifically:

  • suggest and implement validation checks during read/write
  • suggest ideas for the manifest file
  • generate two new unit tests (still evaluated/modified by me)

@emolter

emolter commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator Author

@codecov

codecov Bot commented Dec 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.58824% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.63%. Comparing base (e644832) to head (e41f06f).

Files with missing lines Patch % Lines
jwst/wfss_contam/observations.py 93.49% 8 Missing ⚠️
jwst/wfss_contam/disperse.py 97.70% 2 Missing ⚠️
jwst/wfss_contam/pdt_fileio.py 97.91% 1 Missing ⚠️
jwst/wfss_contam/wfss_contam.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #11090      +/-   ##
==========================================
+ Coverage   88.59%   88.63%   +0.04%     
==========================================
  Files         384      385       +1     
  Lines       41559    41706     +147     
==========================================
+ Hits        36819    36966     +147     
  Misses       4740     4740              

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant