Skip to content

Pass down the same KLIP parameters in contrast analysis - #302

Open
kglidic wants to merge 15 commits into
developfrom
fix_annuli_spacing
Open

kglidic wants to merge 15 commits into
developfrom
fix_annuli_spacing

Conversation

@kglidic

@kglidic kglidic commented Jul 14, 2026 •

Copy link
Copy Markdown
Collaborator

JWSTData, the pyKLIP instrument class used for JWST observations, accepts several parameters, including filepaths, psflib_filepaths, center_keywords, center_include_offset, and highpass. In run_obs(), the dataset is initialized as:

dataset = JWSTData(
    filepaths,
    psflib_filepaths,
    highpass=kwargs_temp['highpass'],
    center_include_offset=False,
    center_keywords=['STARCENX', 'STARCENY']
)

dataset.IWA = kwargs['IWA']

JWSTData assigns a default value for IWA, but run_obs() overwrites this with the user-specified value, defaulting to 1.0 if none is provided.

Currently, this JWSTData configuration is not fully propagated to downstream contrast-analysis routines. For example, calibrate_contrast() and extract_companions() initialized the dataset with only:

pyklip_dataset = JWSTData(filepaths, psflib_filepaths) and
dataset = JWSTData(filepaths, psflib_filepaths, highpass=highpass)

This PR updates these routines so that the downstream JWSTData instances use the same highpass, center_include_offset, center_keywords, and IWA values as the original dataset created in run_obs(). The IWA and HIGHPASS values are also now tracked in the spaceKLIP database and written to the FITS headers.

This PR also adds support for the annuli_spacing parameter in run_obs(). This controls how the KLIP subtraction annuli are distributed radially and can be set to 'constant', 'log', or 'linear'. Previously, annuli_spacing could not be passed through run_obs(), so pyKLIP always used its default 'constant' spacing. The selected value is now stored in the spaceKLIP database as ANNSPACE, and used in downstream routines calibrate_contrast() and extract_companions().

The slides attached to this PR compare the Stage 3 PSF-subtracted products with products generated during contrast analysis after injecting a zero-flux companion. Since a zero-flux injection should leave the data unchanged, we should see no differences when comparing the klipped products. The comparisons include ADI, RDI, and ADI+RDI reductions for both the NIRCam and MIRI demo datasets. The "After" images in the slides show that the same KLIP parameters are now getting passed downstream.
klip_before_after.pptx

When comparing the extract_companions() results from the current develop branch with those produced using the fixes in this PR (using the same set up as in the tutorial notebooks), the best-fit companion parameters show small differences. Across the fitted parameters, the median percent difference is ~ 0.025% for NIRCam and 0.43% for MIRI params. The largest percent differences are generally associated with the uncertainty (*_ERR) values.

This should address the concerns brought up in the following other issues: #148 and #305

This PR also includes a small edit to plotting.py, since get_fits_wcs has been deprecated in stdatamodels. This update is needed for the plotting routines used in the tutorials to run.

@kglidic
kglidic marked this pull request as ready for review August 13, 2026 18:31
@kglidic kglidic changed the title Fix annuli spacing Pass down the same KLIP parameters in contrast analysis Aug 26, 2026
@AarynnCarter

Copy link
Copy Markdown
Collaborator

Hey Kayli,

This looks great - thanks for taking a look! My only major comment is that we're sort of jumping over ourselves to assign the IWA value. If you look at the pyKLIP for JWSTData here:

https://github.com/semaphoreP/pyklip/blob/5f6289093d20d41950095eedffd1b3ab2fb9db1a/pyklip/instruments/JWST.py#L290

You'll see that we have an automatic calculation for the IWA based on the wavelength and mode being used, and we don't want to replace it entirely with a separate hardcoded value in spaceKLIP. Instead, I'd suggest we leave the IWA as is unless the user provides a value. Perhaps we could have an 'auto' setting that is the default which runs through pyKLIP, but if the code sees a float or an integer there then it knows it needs to replace the default pyKLIP value?

The other alternative is we edit pyKLIP and pull the IWA out entirely, but I think there's some value to keeping it in there.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants