From 25814d360404a1da97f201118f301e263a672d97 Mon Sep 17 00:00:00 2001 From: Patrick Avery Date: Mon, 18 Sep 2023 14:48:00 -0500 Subject: [PATCH] Update bkg_coef array when degree changes Signed-off-by: Patrick Avery --- hexrd/wppf/WPPF.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/hexrd/wppf/WPPF.py b/hexrd/wppf/WPPF.py index 0d45ac288..a1d1ddbb4 100644 --- a/hexrd/wppf/WPPF.py +++ b/hexrd/wppf/WPPF.py @@ -273,6 +273,23 @@ def initialize_bkg(self): ) self._background.append(Spectrum(x=self._tth_list[i], y=yy)) + @property + def bkgmethod(self): + return self._bkgmethod + + @bkgmethod.setter + def bkgmethod(self, v): + self._bkgmethod = v + if "chebyshev" in v and hasattr(self, 'bkg_coef'): + degree = v["chebyshev"] + # In case the degree has changed, slice off any extra at the end, + # and in case it is less, pad with zeros. + if len(self.bkg_coef) > degree + 1: + self.bkg_coef = self.bkg_coef[:degree + 1] + elif len(self.bkg_coef) < degree + 1: + pad_width = (0, degree + 1 - len(self.bkg_coef)) + self.bkg_coef = np.pad(self.bkg_coef, pad_width) + def chebyshevfit(self): """ 03/08/2021 SS spectrum_expt is a list now. accounting @@ -1763,6 +1780,23 @@ def initialize_bkg(self): ) self._background.append(Spectrum(x=self._tth_list[i], y=yy)) + @property + def bkgmethod(self): + return self._bkgmethod + + @bkgmethod.setter + def bkgmethod(self, v): + self._bkgmethod = v + if "chebyshev" in v and hasattr(self, 'bkg_coef'): + degree = v["chebyshev"] + # In case the degree has changed, slice off any extra at the end, + # and in case it is less, pad with zeros. + if len(self.bkg_coef) > degree + 1: + self.bkg_coef = self.bkg_coef[:degree + 1] + elif len(self.bkg_coef) < degree + 1: + pad_width = (0, degree + 1 - len(self.bkg_coef)) + self.bkg_coef = np.pad(self.bkg_coef, pad_width) + def chebyshevfit(self): """ 03/08/2021 SS spectrum_expt is a list now. accounting