astropy / specreduce

Tools for the reduction of spectroscopic observations from Optical and NIR instruments
https://specreduce.readthedocs.io
61 stars 38 forks source link

Issue with masked and NaN values in FitTrace #183

Closed cshanahan1 closed 10 months ago

cshanahan1 commented 1 year ago

This issue relates to the use of masks in FitTrace - both masks on input NDData, or masks generated within FitTrace from NaNs in the data itself.

The first case is when a data array with 'masked' values set to NaN is passed in:

from specreduce.tracing import FitTrace dat = fits.getdata('legac_M1_v3.11_spec2d_126153.fits') dat[39:41, :] = np.nan # set some NaNs in data along the trace fit_trace = FitTrace(dat) # no mask, but non finite values in image

This produces an individual warning for each column (in this case, 6165 messages): UserWarning: All pixels in bin 6160 are masked. Falling to trace value from all-bin fit.

But the trace fit proceeds. Below is the image, the white pixels are those set in the image to NaN, and the blue line is the fit trace:

Screen Shot 2023-08-08 at 4 24 58 PM

When this same data is passed in to FitTrace but a mask of those same pixels is also supplied, an error is raised:

mask = np.ones(dat.shape) mask[39:41, :] = 0 # mask along the entire trace nddat = NDData(data=dat, mask=mask, unit=u.DN) fit_trace = FitTrace(nddat) # passing the mask as well as image with NaN values

raises

ValueError: image is fully masked. Check for invalid values