astropy / specreduce

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

FitTrace should set bin to NaN when a fully masked bin is encountered #206

Closed cshanahan1 closed 7 months ago

cshanahan1 commented 8 months ago

When FitTrace encounters a fully masked bin (which can also be a fully masked column, if nbins=ncols) one of three things can happen depending on choice of peak_method:

  1. If peak_method is gaussian, the entire fit will fail. If the bin peak were set to nan instead of failing, the rest of the bins could be fit and the fully masked bins could be filtered out of the final fit to bin peaks for the trace.
  2. if peak_method is max, the peak for the fully masked bin will always be 0. This biases the overall fit for the trace, and if they were instead set to nan they could be masked for the final fit.
  3. if peak_method is centroid, the peak for the fully masked bin will always be the number of rows in the image because it is trying to interpolate between nans.

In all three of these cases, the final fit trace for these fully masked bins will have a final value using the all-bin fit, but the fit to the bin peaks itself is biased when there are 0s or 200s (for a 200x100 image for example). Additionally, the total failure for fully masked bins when using gaussian for the peak method can be avoided if that bin is just excluded from the final fit.