Exemplo n.º 1
0
def has_valid_columns(table: TableWorkspace, table_type='calibration') -> bool:
    """
    Check if table column names are valid Corelli calibration tables
    """
    names_expected = {
        'calibration': ['Detector ID', 'Detector Y Coordinate'],
        'mask': ['Detector ID']
    }
    names = table.getColumnNames()
    if names != names_expected[table_type]:
        return False

    return True
Exemplo n.º 2
0
    def test_pickle_table_workspace(self):
        from mantid.kernel import V3D
        import pickle

        table = TableWorkspace()
        table.addColumn(type="int",name="index")
        table.addColumn(type="str",name="value")
        table.addColumn(type="V3D",name="position")

        values = (1, '10', V3D(0, 0, 1))
        table.addRow(values)
        values = (2, '100', V3D(1, 0, 0))
        table.addRow(values)

        p = pickle.dumps(table)
        table2 = pickle.loads(p)
        self.assertEqual(table.toDict(), table2.toDict())

        # Can we add it to the ADS
        name = "test_pickle_table_workspace"
        AnalysisDataService.add(name, table2)
        self.assertTrue(name in AnalysisDataService)
        AnalysisDataService.remove(name)
Exemplo n.º 3
0
    def _extract_tofs(self, table_tofs: TableWorkspace) -> np.ndarray:
        r"""
        Extract the columns of the input table containing the peak centers, sorted by increasing value
        of the peak center in d-spacing units

        :param table_tofs: table of peak centers, in TOF units
        :return array of shape (detector_count, peak_count)
        """
        # the title for the columns containing the peak centers begin with '@'
        indexes_and_titles = [
            (index, title)
            for index, title in enumerate(table_tofs.getColumnNames())
            if '@' in title
        ]
        column_indexes, titles = list(zip(*indexes_and_titles))
        peak_tofs = np.array([table_tofs.column(i) for i in column_indexes
                              ])  # shape = (peak_count, detector_count)
        peak_centers = np.array(
            [float(title.replace('@', '')) for title in titles])
        permutation = np.argsort(
            peak_centers)  # reorder of indices guarantee increase in d-spacing
        peak_tofs = peak_tofs[permutation]  # sort by increasing d-spacing
        return np.transpose(peak_tofs)  # shape = (detector_count, peak_count)
Exemplo n.º 4
0
 def test_tableworkspace_is_constructible(self):
     table = TableWorkspace()
     self.assertTrue(isinstance(table, ITableWorkspace))
Exemplo n.º 5
0
    def test_pickle_table_workspace(self):
        from mantid.kernel import V3D
        import pickle

        table = TableWorkspace()
        table.addColumn(type="int", name="index")
        table.addColumn(type="str", name="value")
        table.addColumn(type="V3D", name="position")

        values = (1, '10', V3D(0, 0, 1))
        table.addRow(values)
        values = (2, '100', V3D(1, 0, 0))
        table.addRow(values)

        p = pickle.dumps(table)
        table2 = pickle.loads(p)
        self.assertEqual(table.toDict(), table2.toDict())

        # Can we add it to the ADS
        name = "test_pickle_table_workspace"
        AnalysisDataService.add(name, table2)
        self.assertTrue(name in AnalysisDataService)
        AnalysisDataService.remove(name)