parameters: (self, in_wks, wks_index, peaks, peaks_table_name)
return_statement: return fitted_peaks
docstring: This method is the core of EnggFitPeaks. It tries to fit as many peaks as there are in the list of
          expected peaks passed to the algorithm. This is a single peak fitting, in the sense that peaks
          are fitted separately, one at a time.
  
          The parameters from the (Gaussian) peaks fitted by FindPeaks elsewhere (before calling this method)
          are used as initial guesses.
  
          @param in_wks :: input workspace with spectra for fitting
          @param wks_index :: workspace index of the spectrum where the given peaks should be fitted
          @param peaks :: tuple made of two lists: found_peaks (peaks found by FindPeaks or similar
                          algorithm), and expected_peaks_dsp (expected peaks given as input to this algorithm
                          (in dSpacing units)
          @param peaks_table_name :: name of an (output) table with peaks parameters. If empty, the table is anonymous
  
          @returns a table with parameters for every fitted peak.
docstring_summary: This method is the core of EnggFitPeaks. It tries to fit as many peaks as there are in the list of
          expected peaks passed to the algorithm. This is a single peak fitting, in the sense that peaks
          are fitted separately, one at a time.
docstring_tokens: This method is the core of EnggFitPeaks . It tries to fit as many peaks as there are in the list of expected peaks passed to the algorithm . This is a single peak fitting in the sense that peaks are fitted separately one at a time .
function: def _fit_all_peaks(self, in_wks, wks_index, peaks, peaks_table_name):
          """
          This method is the core of EnggFitPeaks. It tries to fit as many peaks as there are in the list of
          expected peaks passed to the algorithm. This is a single peak fitting, in the sense that peaks
          are fitted separately, one at a time.
  
          The parameters from the (Gaussian) peaks fitted by FindPeaks elsewhere (before calling this method)
          are used as initial guesses.
  
          @param in_wks :: input workspace with spectra for fitting
          @param wks_index :: workspace index of the spectrum where the given peaks should be fitted
          @param peaks :: tuple made of two lists: found_peaks (peaks found by FindPeaks or similar
                          algorithm), and expected_peaks_dsp (expected peaks given as input to this algorithm
                          (in dSpacing units)
          @param peaks_table_name :: name of an (output) table with peaks parameters. If empty, the table is anonymous
  
          @returns a table with parameters for every fitted peak.
  
          """
  
          if self._expected_peaks_are_in_tof:
              peaks = (peaks[0], self._expected_peaks_in_d(peaks[1], in_wks))
  
          found_peaks = peaks[0]
          fitted_peaks = self._create_fitted_peaks_table(peaks_table_name)
  
          prog = Progress(self, start=0, end=1, nreports=found_peaks.rowCount())
  
          for i in range(found_peaks.rowCount()):
              prog.report('Fitting peak number ' + str(i + 1))
  
              row = found_peaks.row(i)
              # Peak parameters estimated by FindPeaks
              initial_params = (row['centre'], row['width'], row['height'])
              # Oh oh, this actually happens sometimes for some spectra of the system test dataset
              # and it should be clarified when the role of FindPeaks etc. is fixed (trac ticket #10907)
              width = initial_params[2]
              if width <= 0.:
                  failure_msg = ("Cannot fit a peak with these initial parameters from FindPeaks, center: %s "
                                 ", width: %s, height: %s" % (initial_params[0], width, initial_params[1]))
                  self.log().notice(f'For workspace index {wks_index} a peak that is in the list of expected peaks and '
                                    f'was found by FindPeaks has not been fitted correctly. It will be ignored. '
                                    f'Expected dSpacing: {peaks[1][i]}. Details: {failure_msg}.')
                  continue
  
              try:
                  param_table, chi_over_dof = self._fit_single_peak(peaks[1][i], initial_params, in_wks, wks_index)
              except RuntimeError:
                  self.log().warning("Problem found when trying to fit a peak centered at {0} (dSpacing), "
                                     "for which the initial guess from FindPeaks is at {1} (ToF). Single "
                                     "peak fitting failed. Skipping this peak."
                                     .format(peaks[1][i], initial_params[0]))
                  continue
  
              fitted_params = {}
  
              fitted_params['dSpacing'] = peaks[1][i]
              fitted_params['Chi'] = chi_over_dof
              self._add_parameters_to_map(fitted_params, param_table)
              if self._peak_is_acceptable(fitted_params, in_wks, wks_index):
                  fitted_peaks.addRow(fitted_params)
              else:
                  self.log().notice("Discarding peak found with wrong center and/or excessive or suspicious "
                                    "error estimate in the center estimate: {0} (ToF) ({1}, dSpacing), "
                                    "with error: {2}, for dSpacing {3}".
                                    format(fitted_params['X0'], peaks[1][i],
                                           fitted_params['X0_Err'], fitted_params['dSpacing']))
  
          # Check if we were able to really fit any peak
          if 0 == fitted_peaks.rowCount():
              failure_msg = ("Could find " + str(len(found_peaks)) + " peaks using the algorithm FindPeaks but "
                             + "then it was not possible to fit any peak starting from these peaks found and using '"
                             + self.PEAK_TYPE + "' as peak function.")
              self.log().warning('Could not fit any peak. Please check the list of expected peaks, as it does not '
                                 'seem to be appropriate for the workspace given. More details: ' + failure_msg)
  
              raise RuntimeError('Could not fit any peak.  Failed to fit peaks with peak type '
                                 + self.PEAK_TYPE + ' even though FindPeaks found ' + str(found_peaks.rowCount())
                                 + ' peaks in principle. See the logs for further details.')
  
          self.log().information("Fitted {0} peaks in total.".format(fitted_peaks.rowCount()))
  
          return fitted_peaks
function_tokens: def _fit_all_peaks ( self , in_wks , wks_index , peaks , peaks_table_name ) : if self . _expected_peaks_are_in_tof : peaks = ( peaks [ 0 ] , self . _expected_peaks_in_d ( peaks [ 1 ] , in_wks ) ) found_peaks = peaks [ 0 ] fitted_peaks = self . _create_fitted_peaks_table ( peaks_table_name ) prog = Progress ( self , start = 0 , end = 1 , nreports = found_peaks . rowCount ( ) ) for i in range ( found_peaks . rowCount ( ) ) : prog . report ( 'Fitting peak number ' + str ( i + 1 ) ) row = found_peaks . row ( i ) # Peak parameters estimated by FindPeaks initial_params = ( row [ 'centre' ] , row [ 'width' ] , row [ 'height' ] ) # Oh oh, this actually happens sometimes for some spectra of the system test dataset # and it should be clarified when the role of FindPeaks etc. is fixed (trac ticket #10907) width = initial_params [ 2 ] if width <= 0. : failure_msg = ( "Cannot fit a peak with these initial parameters from FindPeaks, center: %s " ", width: %s, height: %s" % ( initial_params [ 0 ] , width , initial_params [ 1 ] ) ) self . log ( ) . notice ( f'For workspace index {wks_index} a peak that is in the list of expected peaks and ' f'was found by FindPeaks has not been fitted correctly. It will be ignored. ' f'Expected dSpacing: {peaks[1][i]}. Details: {failure_msg}.' ) continue try : param_table , chi_over_dof = self . _fit_single_peak ( peaks [ 1 ] [ i ] , initial_params , in_wks , wks_index ) except RuntimeError : self . log ( ) . warning ( "Problem found when trying to fit a peak centered at {0} (dSpacing), " "for which the initial guess from FindPeaks is at {1} (ToF). Single " "peak fitting failed. Skipping this peak." . format ( peaks [ 1 ] [ i ] , initial_params [ 0 ] ) ) continue fitted_params = { } fitted_params [ 'dSpacing' ] = peaks [ 1 ] [ i ] fitted_params [ 'Chi' ] = chi_over_dof self . _add_parameters_to_map ( fitted_params , param_table ) if self . _peak_is_acceptable ( fitted_params , in_wks , wks_index ) : fitted_peaks . addRow ( fitted_params ) else : self . log ( ) . notice ( "Discarding peak found with wrong center and/or excessive or suspicious " "error estimate in the center estimate: {0} (ToF) ({1}, dSpacing), " "with error: {2}, for dSpacing {3}" . format ( fitted_params [ 'X0' ] , peaks [ 1 ] [ i ] , fitted_params [ 'X0_Err' ] , fitted_params [ 'dSpacing' ] ) ) # Check if we were able to really fit any peak if 0 == fitted_peaks . rowCount ( ) : failure_msg = ( "Could find " + str ( len ( found_peaks ) ) + " peaks using the algorithm FindPeaks but " + "then it was not possible to fit any peak starting from these peaks found and using '" + self . PEAK_TYPE + "' as peak function." ) self . log ( ) . warning ( 'Could not fit any peak. Please check the list of expected peaks, as it does not ' 'seem to be appropriate for the workspace given. More details: ' + failure_msg ) raise RuntimeError ( 'Could not fit any peak.  Failed to fit peaks with peak type ' + self . PEAK_TYPE + ' even though FindPeaks found ' + str ( found_peaks . rowCount ( ) ) + ' peaks in principle. See the logs for further details.' ) self . log ( ) . information ( "Fitted {0} peaks in total." . format ( fitted_peaks . rowCount ( ) ) ) return fitted_peaks