astropy / reproject

Python-based Astronomical image reprojection :milky_way: - maintainer @astrofrog
https://reproject.readthedocs.io
BSD 3-Clause "New" or "Revised" License
105 stars 64 forks source link

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

Closed svank closed 7 months ago

svank commented 7 months ago

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
codecov[bot] commented 7 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

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

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

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

astrofrog commented 7 months ago

Failures are unrelated