diff --git a/Framework/PythonInterface/plugins/algorithms/FitIncidentSpectrum.py b/Framework/PythonInterface/plugins/algorithms/FitIncidentSpectrum.py index 8d89e3c06fd2d221c28260b6ef3eb22639d0a3c6..67fd9758ca6c04227ff1d47f7b8876b00f034cc1 100644 --- a/Framework/PythonInterface/plugins/algorithms/FitIncidentSpectrum.py +++ b/Framework/PythonInterface/plugins/algorithms/FitIncidentSpectrum.py @@ -45,7 +45,7 @@ class FitIncidentSpectrum(PythonAlgorithm): doc='Output workspace containing the fit and it\'s first derivative.') self.declareProperty( - name='SpectrumIndex', + name='WorkspaceIndex', defaultValue=0, doc='Workspace index of the spectra to be fitted (Defaults to the first index.)') @@ -72,7 +72,7 @@ class FitIncidentSpectrum(PythonAlgorithm): def _setup(self): self._input_ws = self.getProperty('InputWorkspace').value self._output_ws = self.getProperty('OutputWorkspace').valueAsStr - self._incident_index = self.getProperty('SpectrumIndex').value + self._incident_index = self.getProperty('WorkspaceIndex').value self._binning_for_calc = self.getProperty('BinningForCalc').value self._binning_for_fit = self.getProperty('BinningForFit').value self._fit_spectrum_with = self.getProperty('FitSpectrumWith').value @@ -89,19 +89,19 @@ class FitIncidentSpectrum(PythonAlgorithm): y_fit = np.array(self._input_ws.readY(self._incident_index)) else: rebinned = Rebin( - self._input_ws, + InputWorkspace=self._input_ws, Params=self._binning_for_fit, - PreserveEvents=True, - StoreInADS=False) + PreserveEvents=True) x_fit = np.array(rebinned.readX(self._incident_index)) y_fit = np.array(rebinned.readY(self._incident_index)) - + rebin_norm = x.size/x_fit.size + x_bin_centers = 0.5 * (x[:-1] + x[1:]) if len(x_fit) != len(y_fit): - x_fit = x_fit[:-1] + x_fit = 0.5*(x_fit[:-1] + x_fit[1:]) if self._fit_spectrum_with == 'CubicSpline': # Fit using cubic spline - fit, fit_prime = self.fit_cubic_spline(x_fit, y_fit, x[:-1], s=1e7) + fit, fit_prime = self.fit_cubic_spline(x_fit, y_fit, x_bin_centers, s=1e7) elif self._fit_spectrum_with == 'CubicSplineViaMantid': # Fit using cubic spline via Mantid fit, fit_prime = self.fit_cubic_spline_via_mantid_spline_smoothing( @@ -112,13 +112,13 @@ class FitIncidentSpectrum(PythonAlgorithm): MaxNumberOfBreaks=0) elif self._fit_spectrum_with == 'GaussConvCubicSpline': # Fit using Gauss conv cubic spline - fit, fit_prime = self.fit_cubic_spline_with_gauss_conv(x_fit, y_fit, x[:-1], sigma=0.5) + fit, fit_prime = self.fit_cubic_spline_with_gauss_conv(x_fit, y_fit, x_bin_centers, sigma=0.5) # Create output workspace unit = self._input_ws.getAxis(0).getUnit().unitID() output_workspace = CreateWorkspace( DataX=x, - DataY=np.append(fit, fit_prime), + DataY=np.append(fit, fit_prime)/rebin_norm, UnitX=unit, NSpec=2, Distribution=False, @@ -126,7 +126,7 @@ class FitIncidentSpectrum(PythonAlgorithm): StoreInADS=False) self.setProperty("OutputWorkspace", output_workspace) - def fit_cubic_spline_with_gauss_conv(self, x_fit, y_fit, x, n_gouss=39, sigma=3): + def fit_cubic_spline_with_gauss_conv(self, x_fit, y_fit, x, n_gouss=39, sigma=3.0): # Fit with Cubic Spline using a Gaussian Convolution to get weights def moving_average(y, n=n_gouss, sig=sigma): b = signal.gaussian(n, sig) diff --git a/docs/source/algorithms/FitIncidentSpectrum-v1.rst b/docs/source/algorithms/FitIncidentSpectrum-v1.rst index 3239be46aa8a989338a19c20bf464582374bfc24..38a54e97d9eed5abf084bfb7314a2ccee3846f34 100644 --- a/docs/source/algorithms/FitIncidentSpectrum-v1.rst +++ b/docs/source/algorithms/FitIncidentSpectrum-v1.rst @@ -102,10 +102,10 @@ Output: .. testoutput:: ExFitIncidentSpectrum - [ 5328.83700775 2330.08408285 1600.78200105 2543.59379589 3249.78956903 - 2797.87138465 2050.3366076 1417.4868309 965.23854845 659.79544224 - 456.54322031 320.88688262 229.29830975 166.5536716 122.89703604 - 92.0419568 69.89199835 53.75902111 41.84355559] + [ 3318.3489535 1760.07570573 1901.11829551 3081.98511847 3110.03374921 + 2423.17832412 1711.216875 1170.12096584 797.13759356 547.91281905 + 381.9735739 270.66392746 195.01094402 142.79582704 106.17020879 + 80.07657305 61.2047398 47.35976442] References ------------