parameters: (self,
                                    peak_centers_in_tof: Union[str, TableWorkspace],
                                    workspace_with_instrument: Union[str, Workspace],
                                    output_workspace: str,
                                    grouping_workspace: Union[str, WorkspaceGroup],
                                    deviation_params: List[float] = [-0.1, 0.0001, 0.1],
                                    percent_deviations: bool = False)
docstring: r"""
          Find deviations of the fitted peak centers with respect to the reference values,
          in d-spacing units. Histogram these deviations for all peaks found on each bank
  
          @param peak_centers_in_tof: table containing the centers of the fitted peaks found
              on each pixel, in TOF units
          @param workspace_with_instrument: any workspace whose embedded instrument will
              be used to calculate the DIFC values per pixel
          @param output_workspace: workspace containing the histograms of peak deviations per bank
          @param grouping_workspace: workspace assigning group ID's (bank numbers) to each pixel
          @param deviation_params: a triad of first histogram boundary, bin width, and
              last histogram boundary, in Angstroms
          @param percent_deviations: each deviation from the reference d-spacing will be divided by the
              d-spacing value and multiplied by 100. Adjust `deviation_params` accordinggly
docstring_summary: r"""
          Find deviations of the fitted peak centers with respect to the reference values,
          in d-spacing units. Histogram these deviations for all peaks found on each bank
docstring_tokens: r Find deviations of the fitted peak centers with respect to the reference values in d - spacing units . Histogram these deviations for all peaks found on each bank
function: def histogram_peak_deviations(self,
                                    peak_centers_in_tof: Union[str, TableWorkspace],
                                    workspace_with_instrument: Union[str, Workspace],
                                    output_workspace: str,
                                    grouping_workspace: Union[str, WorkspaceGroup],
                                    deviation_params: List[float] = [-0.1, 0.0001, 0.1],
                                    percent_deviations: bool = False):
          r"""
          Find deviations of the fitted peak centers with respect to the reference values,
          in d-spacing units. Histogram these deviations for all peaks found on each bank
  
          @param peak_centers_in_tof: table containing the centers of the fitted peaks found
              on each pixel, in TOF units
          @param workspace_with_instrument: any workspace whose embedded instrument will
              be used to calculate the DIFC values per pixel
          @param output_workspace: workspace containing the histograms of peak deviations per bank
          @param grouping_workspace: workspace assigning group ID's (bank numbers) to each pixel
          @param deviation_params: a triad of first histogram boundary, bin width, and
              last histogram boundary, in Angstroms
          @param percent_deviations: each deviation from the reference d-spacing will be divided by the
              d-spacing value and multiplied by 100. Adjust `deviation_params` accordinggly
          """
          # Find DIFC values using the geometry of the instrument embedded in `workspace_with_instrument`
          difc_workspace = self.temp_ws()  # we need a temporary workspace
          CalculateDIFC(workspace_with_instrument, OutputWorkspace=difc_workspace)
          difc_values = mtd[difc_workspace].extractY().flatten()
  
          # Save the contents of the table to a python dictionary which we can overwrite easily
          tof_table = mtd[str(peak_centers_in_tof)]
          tof_dict = tof_table.toDict()  # the table as a data structure we can modify
  
          # Calculate the peak deviations with respect to the reference peak centers, in d-spacing or percent units
          column_names = tof_table.getColumnNames()
          column_peaks = [name for name in column_names if '@' in name]  # column containing the peak centers
          for column in column_peaks:
              dspacing_reference = float(column.replace('@', ''))  # the column name has the reference peak center
              # peak deviations, in d-spacing units, that we use to overwrite tof_dic
              tof_dict[column] = np.array(tof_dict[column]) / difc_values - dspacing_reference
              # switch to percent deviations if so required
              if percent_deviations is True:
                  tof_dict[column] *= 100 / dspacing_reference
              tof_dict[column] = tof_dict[column].tolist() # cast to list
  
          # Extract the group ID's, which typically corresponds to bank numbers
          # grouping_workspace_y contain the group ID (bank number) of each pixel
          grouping_workspace_y = [int(n) for n in mtd[str(grouping_workspace)].extractY().flatten()]
          group_ids = sorted(list(set(grouping_workspace_y)))  # list of group ID's (bank numbers)
  
          # List all the peak deviations within a group (bank)
          deviations_in_group = {group_id: [] for group_id in group_ids}
          for row_index in range(tof_table.rowCount()):  # iterate over each pixel
              group_id = grouping_workspace_y[row_index]  # group ID (bank number) of the current pixel
              # find the peak deviations for all peaks that were found in the current pixel
              deviations_in_pixel = np.array([tof_dict[column][row_index] for column in column_peaks])
              # `nan` is assigned to listed peaks missing in the current pixel. We must get rid of them
              deviations_in_group[group_id].extend(deviations_in_pixel[~np.isnan(deviations_in_pixel)].tolist())
  
          # Histogram the deviations for all pixels within a group (bank)
          start, step, stop = deviation_params  # start and stop are first and last histogram boundaries
          bins = np.arange(start, stop + step / 2, step)
          histograms = dict()  # one histogram per group ID (bank)
          histogram_empty = np.zeros(len(bins) - 1)  # this for banks with no peaks, for instance, for masked banks
          for group_id, deviations in deviations_in_group.items():
              if len(deviations) == 0:  # no peaks in the group (bank), thus no deviations
                  histogram = histogram_empty
              else:
                  histogram = np.histogram(deviations, bins)[0]
              histograms[group_id] = histogram
  
          # Create a workspace with the histograms
          spectra = spectra = np.array(list(histograms.values())).flatten()  # single list needed
          unit_x = 'dSpacing' if percent_deviations is False else 'Empty'
          title_prefix = 'Peak ' if percent_deviations is False else 'Percent peak '
          CreateWorkspace(DataX=bins, DataY=spectra, NSpec=len(group_ids), UnitX=unit_x,
                          WorkspaceTitle=title_prefix + 'Peak deviations per pixel group',
                          OutputWorkspace=output_workspace)
          insert_bank_numbers(output_workspace, grouping_workspace)
function_tokens: def histogram_peak_deviations ( self , peak_centers_in_tof : Union [ str , TableWorkspace ] , workspace_with_instrument : Union [ str , Workspace ] , output_workspace : str , grouping_workspace : Union [ str , WorkspaceGroup ] , deviation_params : List [ float ] = [ - 0.1 , 0.0001 , 0.1 ] , percent_deviations : bool = False ) : # Find DIFC values using the geometry of the instrument embedded in `workspace_with_instrument` difc_workspace = self . temp_ws ( ) # we need a temporary workspace CalculateDIFC ( workspace_with_instrument , OutputWorkspace = difc_workspace ) difc_values = mtd [ difc_workspace ] . extractY ( ) . flatten ( ) # Save the contents of the table to a python dictionary which we can overwrite easily tof_table = mtd [ str ( peak_centers_in_tof ) ] tof_dict = tof_table . toDict ( ) # the table as a data structure we can modify # Calculate the peak deviations with respect to the reference peak centers, in d-spacing or percent units column_names = tof_table . getColumnNames ( ) column_peaks = [ name for name in column_names if '@' in name ] # column containing the peak centers for column in column_peaks : dspacing_reference = float ( column . replace ( '@' , '' ) ) # the column name has the reference peak center # peak deviations, in d-spacing units, that we use to overwrite tof_dic tof_dict [ column ] = np . array ( tof_dict [ column ] ) / difc_values - dspacing_reference # switch to percent deviations if so required if percent_deviations is True : tof_dict [ column ] *= 100 / dspacing_reference tof_dict [ column ] = tof_dict [ column ] . tolist ( ) # cast to list # Extract the group ID's, which typically corresponds to bank numbers # grouping_workspace_y contain the group ID (bank number) of each pixel grouping_workspace_y = [ int ( n ) for n in mtd [ str ( grouping_workspace ) ] . extractY ( ) . flatten ( ) ] group_ids = sorted ( list ( set ( grouping_workspace_y ) ) ) # list of group ID's (bank numbers) # List all the peak deviations within a group (bank) deviations_in_group = { group_id : [ ] for group_id in group_ids } for row_index in range ( tof_table . rowCount ( ) ) : # iterate over each pixel group_id = grouping_workspace_y [ row_index ] # group ID (bank number) of the current pixel # find the peak deviations for all peaks that were found in the current pixel deviations_in_pixel = np . array ( [ tof_dict [ column ] [ row_index ] for column in column_peaks ] ) # `nan` is assigned to listed peaks missing in the current pixel. We must get rid of them deviations_in_group [ group_id ] . extend ( deviations_in_pixel [ ~ np . isnan ( deviations_in_pixel ) ] . tolist ( ) ) # Histogram the deviations for all pixels within a group (bank) start , step , stop = deviation_params # start and stop are first and last histogram boundaries bins = np . arange ( start , stop + step / 2 , step ) histograms = dict ( ) # one histogram per group ID (bank) histogram_empty = np . zeros ( len ( bins ) - 1 ) # this for banks with no peaks, for instance, for masked banks for group_id , deviations in deviations_in_group . items ( ) : if len ( deviations ) == 0 : # no peaks in the group (bank), thus no deviations histogram = histogram_empty else : histogram = np . histogram ( deviations , bins ) [ 0 ] histograms [ group_id ] = histogram # Create a workspace with the histograms spectra = spectra = np . array ( list ( histograms . values ( ) ) ) . flatten ( ) # single list needed unit_x = 'dSpacing' if percent_deviations is False else 'Empty' title_prefix = 'Peak ' if percent_deviations is False else 'Percent peak ' CreateWorkspace ( DataX = bins , DataY = spectra , NSpec = len ( group_ids ) , UnitX = unit_x , WorkspaceTitle = title_prefix + 'Peak deviations per pixel group' , OutputWorkspace = output_workspace ) insert_bank_numbers ( output_workspace , grouping_workspace )