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

Add despike_jacobian option for adaptive resampling #366

Merged
merged 1 commit into from
Jun 16, 2023

Conversation

svank
Copy link
Contributor

@svank svank commented May 25, 2023

This adds an option to smooth over numerical quirkiness when, for example, the longitude wraps around in an all-sky map. The quirk occurs when computing the Jacobian, which is d(input-image pixel) / d(output-image pixel). This is done by finite differences, so when the input coordinates jump from one side of the map to the other, the Jacobian comes out extremely large, despite the actual transformation being unremarkable at that location. The new option looks for outlier Jacobian values, measured relative to a 3x3 local neighborhood, and replaces those outliers with a mean of the non-outlier values in the neighborhood.

Before this PR, the extremely-large Jacobian would cause the input-image region that is to be sampled to be extremely large---larger than a safety-valve threshold in the code that just outputs a nan for that output pixel. This caused a band of nans near the wrap-point's location in the output image. With this change, that seam is handled correctly.

Looks like this might close #195.

starfield_sample, _ = reproject.reproject_adaptive(
    (all_sky_map, all_sky_wcs), data_wcs, data.shape,
    x_cyclic=True, despike_jacobian=False)
starfield_sample_despiked, _ = reproject.reproject_adaptive(
    (all_sky_map, all_sky_wcs), data_wcs, data.shape,
    x_cyclic=True, despike_jacobian=True)

plt.figure(figsize=(10,5))
plt.subplot(121, projection=data_wcs)
plt.imshow(np.isnan(starfield_sample))
plt.title("np.isnan(starfield_sample)")

plt.subplot(122, projection=data_wcs)
plt.imshow(np.isnan(starfield_sample_despiked))
plt.title("np.isnan(starfield_sample_despiked)")

image

@codecov
Copy link

codecov bot commented May 25, 2023

Codecov Report

Merging #366 (4ab3b3a) into main (8ea36e7) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main     #366   +/-   ##
=======================================
  Coverage   92.50%   92.50%           
=======================================
  Files          24       24           
  Lines         840      840           
=======================================
  Hits          777      777           
  Misses         63       63           
Impacted Files Coverage Δ
reproject/adaptive/core.py 97.77% <ø> (ø)
reproject/adaptive/high_level.py 100.00% <ø> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Member

@astrofrog astrofrog left a comment

Choose a reason for hiding this comment

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

Looks great, thanks!

@astrofrog astrofrog merged commit 4a82007 into astropy:main Jun 16, 2023
@svank svank deleted the jacobians branch June 23, 2023 21:27
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.

Fix edge effects in reproject_adaptive
2 participants