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

Ensure reproject_and_coadd handles bg-matching with one input image #412

Merged
merged 1 commit into from
Nov 21, 2023

Conversation

svank
Copy link
Contributor

@svank svank commented Nov 20, 2023

I'm using reproject_and_coadd in a loop---in some iterations, there's only one input image (while in others, there are multiple). When I set match_background=True, I get some warnings and the whole output image is nan. Maybe this indicates a deeper problem in the background-matching code, but as a workaround, we can just not do the bg-matching if there's only a single input image, to work around this bug and avoid some extra work.

import numpy as np
import reproject
import reproject.mosaicking
import matplotlib.pyplot as plt
from astropy.wcs import WCS

data = np.ones((100, 100))
data[::5] = 2
wcs_in = WCS(naxis=2)
wcs_in.wcs.ctype = 'RA---TAN', 'DEC--TAN'
wcs_in.wcs.crpix = 50, 50
wcs_in.wcs.crval = 0, 0
wcs_in.wcs.cdelt = .1, .1

wcs_out = wcs_in.deepcopy()

reprojected, footprint = reproject.mosaicking.reproject_and_coadd(
    [(data, wcs_in)], wcs_out, data.shape,
    reproject_function=reproject.reproject_adaptive, match_background=True)
/home/svankooten/.anaconda/envs/sunpy-dev/lib/python3.11/site-packages/numpy/core/fromnumeric.py:3464: RuntimeWarning: Mean of empty slice.
  return _methods._mean(a, axis=axis, dtype=dtype,
/home/svankooten/.anaconda/envs/sunpy-dev/lib/python3.11/site-packages/numpy/core/_methods.py:192: RuntimeWarning: invalid value encountered in scalar divide
  ret = ret.dtype.type(ret / rcount)
/home/svankooten/Documents/Research/reproject_dev/reproject/reproject/mosaicking/background.py:132: RuntimeWarning: Mean of empty slice
  corrections -= np.nanmean(corrections)
np.all(np.isnan(reprojected)) # Output: True

Copy link

codecov bot commented Nov 20, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (a02c082) 93.62% compared to head (6d5d4be) 93.62%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #412   +/-   ##
=======================================
  Coverage   93.62%   93.62%           
=======================================
  Files          25       25           
  Lines         894      894           
=======================================
  Hits          837      837           
  Misses         57       57           

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

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 good to me! Background matching should be a noop with one image so this is the right fix.

@astrofrog
Copy link
Member

Failures are unrelated

@astrofrog astrofrog merged commit b07fef5 into astropy:main Nov 21, 2023
6 of 23 checks passed
@svank svank deleted the match-background-one-image branch November 27, 2023 18:39
@astrofrog astrofrog added the bug label Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants