From 18f625d6b5994ae93a72edc42a121d44e8f77e7f Mon Sep 17 00:00:00 2001 From: Alfredo Mejia-Narvaez Date: Tue, 12 Nov 2024 20:03:48 -0300 Subject: [PATCH] copying arrays to avoid side effects on gaussian fitting --- python/lvmdrp/core/spectrum1d.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/python/lvmdrp/core/spectrum1d.py b/python/lvmdrp/core/spectrum1d.py index 3928d2c7..1bc5d68e 100644 --- a/python/lvmdrp/core/spectrum1d.py +++ b/python/lvmdrp/core/spectrum1d.py @@ -3350,10 +3350,16 @@ def fitSepGauss( fit_bg=True, warning=False, ): - error = self._error if self._error is not None else numpy.ones(self._dim, dtype=numpy.float32) - mask = self._mask if self._mask is not None else numpy.zeros(self._dim, dtype=bool) - error[mask] = numpy.inf + # copy main arrays to avoid side effects data = self._data.copy() + error = self._error.copy() if self._error is not None else numpy.ones(self._dim, dtype=numpy.float32) + mask = self._mask.copy() if self._mask is not None else numpy.zeros(self._dim, dtype=bool) + + # update mask to account for unmasked invalid pixels + # mask |= (~numpy.isfinite(data) | ~numpy.isfinite(error)) + + # reset bad pixels in data and error + error[mask] = numpy.inf data[mask] = 0.0 flux = numpy.ones(len(cent_guess)) * numpy.nan