Example #1
0
    def _test_helper_scale_large_intensities(self, output_format, file_name):
        # Arrange
        DeleteTableRows(TableWorkspace=self._workspace, Rows=f'1-{self._workspace.getNumberPeaks()-1}')  # only first pk
        self._workspace.getPeak(0).setIntensity(2.5E8)

        # Act
        SaveReflections(InputWorkspace=self._workspace, Filename=file_name, Format=output_format)

        # Read lines from file to be asserted in individual tests
        with open(file_name, 'r') as actual_file:
            lines = actual_file.readlines()

        return lines
Example #2
0
    def action_delete_row(self):
        selection_model = self.view.selectionModel()
        if not selection_model.hasSelection():
            show_no_selection_to_copy_toast()
            return

        selected_rows = selection_model.selectedRows()
        selected_rows_list = [index.row() for index in selected_rows]
        selected_rows_str = ",".join([str(row) for row in selected_rows_list])

        DeleteTableRows(self.model.ws, selected_rows_str)
        # Reverse the list so that we delete in order from bottom -> top
        # this prevents the row index from shifting up when deleting rows above
        for row in reversed(selected_rows_list):
            self.view.removeRow(row)
Example #3
0
    def test_save_fullprof_format_constant_wavelength(self):
        # Arrange
        # leave only one peak (therefore a single wavelength in table)
        DeleteTableRows(TableWorkspace=self._workspace, Rows=f'1-{self._workspace.getNumberPeaks() - 1:.0f}')
        file_name = os.path.join(self._test_dir, "test_fullprof_cw.hkl")
        output_format = "Fullprof"

        # Act
        SaveReflections(InputWorkspace=self._workspace, Filename=file_name, Format=output_format)

        # Assert
        wavelength = 0
        with open(file_name, 'r') as file:
            file.readline()  # skip
            file.readline()  # skip
            wavelength = float(file.readline().lstrip().split(' ')[0])
        self.assertAlmostEqual(wavelength, self._workspace.getPeak(0).getWavelength(), delta=1e-4)
Example #4
0
def purge_table(workspace: WorkspaceTypes, calibration_table: TableWorkspace,
                tubes_fit_success: np.ndarray,  output_table: str = None) -> None:
    r"""
    Remove the detectorID's corresponding to the failing tubes from the calibration table

    Assumptions:
    - Each tube has PIXELS_PER_TUBE number of pixels
    - detector ID's in the calibration table are sorted according to tube number

    :param workspace: input Workspace2D containing total neutron counts per pixel
    :param calibration_table: input TableWorkspace containing one column for detector ID and one column
    for its calibrated Y coordinates, in meters
    :param tubes_fit_success: array of booleans of length TUBES_IN_BANK. `False` if a tube was unsuccessfully fitted.
    :param output_table: name of the purged table. If `None`, the input `calibration_table` is purged.
    """
    # validate input arguments
    if False not in tubes_fit_success:
        return  # nothing to do
    # validate the input workspace
    message = f'Cannot process workspace {workspace}. Pass the name of an existing workspace or a workspace handle'
    assert isinstance(workspace, (str, Workspace2D)), message
    workspace_name = str(workspace)
    assert AnalysisDataService.doesExist(workspace_name), f'Input workspace {workspace_name} does not exists'
    # validate the input calibraton table
    message = f'Cannot process table {calibration_table}. Pass the name of an existing TableWorkspace' \
              ' or a TableWorkspace handle'
    assert isinstance(calibration_table, (str, TableWorkspace)), message
    assert AnalysisDataService.doesExist(str(calibration_table)), f'Input table {calibration_table} does not exists'
    if output_table is not None:
        CloneWorkspace(InputWorkspace=calibration_table, OutputWorkspace=output_table)
    else:
        output_table = str(calibration_table)
    tube_fail_indexes = np.where(tubes_fit_success == False)[0]  # noqa E712 indexes of tubes unsuccessfully fitted
    row_indexes_of_first_tube = np.arange(PIXELS_PER_TUBE)  # 0, 1, ... 255
    fail_rows = [row_indexes_of_first_tube + (i * PIXELS_PER_TUBE) for i in tube_fail_indexes]
    fail_rows = np.array(fail_rows, dtype=int).flatten().tolist()
    DeleteTableRows(output_table, fail_rows)
Example #5
0
 def remove_log_rows(self, row_numbers):
     DeleteTableRows(TableWorkspace=self._log_workspaces, Rows=list(row_numbers))
     self.update_log_group_name()
Example #6
0
 def delete_rows(self, selected_rows):
     DeleteTableRows(self.ws, selected_rows)
Example #7
0
 def delete_rows(self, selected_rows):
     from mantid.simpleapi import DeleteTableRows
     DeleteTableRows(self.ws, selected_rows)