当前位置: 首页>>代码示例>>Python>>正文


Python SANSUtility类代码示例

本文整理汇总了Python中SANSUtility的典型用法代码示例。如果您正苦于以下问题:Python SANSUtility类的具体用法?Python SANSUtility怎么用?Python SANSUtility使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了SANSUtility类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_monitors_are_renamed_correctly

    def test_monitors_are_renamed_correctly(self):
        #Arrange
        ws_1 = CreateSampleWorkspace()
        ws_2 = CreateSampleWorkspace()
        ws_3 = CreateSampleWorkspace()

        ws_mon_1 = CreateSampleWorkspace()
        ws_mon_2 = CreateSampleWorkspace()
        ws_mon_3 = CreateSampleWorkspace()

        ws_group = GroupWorkspaces(InputWorkspaces=[ws_1, ws_2, ws_3])
        ws_mon_group = GroupWorkspaces(InputWorkspaces=[ws_mon_1, ws_mon_2, ws_mon_3])

        # Act
        su.rename_monitors_for_multiperiod_event_data(ws_mon_group, ws_group, self.monitor_appendix)

        # Assert
        self.assertTrue(ws_mon_1.name() == ws_1.name() + self.monitor_appendix, "Monitors should be renamed to xxxx_monitors")
        self.assertTrue(ws_mon_2.name() == ws_2.name() + self.monitor_appendix, "Monitors should be renamed to xxxx_monitors")
        self.assertTrue(ws_mon_3.name() == ws_3.name() + self.monitor_appendix, "Monitors should be renamed to xxxx_monitors")

        # Clean up
        for element in mtd.getObjectNames():
            if element in mtd:
                DeleteWorkspace(element)
开发者ID:spaceyatom,项目名称:mantid,代码行数:25,代码来源:SANSUtilityTest.py

示例2: test_removes_zero_errors_correctly

    def test_removes_zero_errors_correctly(self):
        # Arrange
        ws_name = 'test'
        type ='Histogram'
        self._setup_workspace(ws_name, type)
        ws = mtd[ws_name]

        # Act and Assert
        errors = ws.dataE
        self.assertTrue(errors(0)[0] == 0.0)
        self.assertTrue(errors(1)[0] != 0.0)
        self.assertTrue(errors(2)[0] == 0.0)
        self.assertTrue(errors(3)[0] != 0.0)

        su.remove_zero_errors_from_workspace(ws)

        self.assertTrue(errors(0)[0] == su.ZERO_ERROR_DEFAULT)
        self.assertTrue(errors(1)[0] != 0.0)
        self.assertTrue(errors(1)[0] != su.ZERO_ERROR_DEFAULT)
        self.assertTrue(errors(2)[0] == su.ZERO_ERROR_DEFAULT)
        self.assertTrue(errors(3)[0] != 0.0)
        self.assertTrue(errors(3)[0] != su.ZERO_ERROR_DEFAULT)

        self._removeWorkspace(ws_name)
        self.assertTrue(not ws_name in mtd)
开发者ID:,项目名称:,代码行数:25,代码来源:

示例3: test_that_non_matching_workspaces_are_detected

 def test_that_non_matching_workspaces_are_detected(self):
     # Arrange
     front_name = "front"
     rear_name = "rear"
     result_name = "result"
     x1 = [1,2,3]
     e1 = [1,1]
     y1 = [2,2]
     dx1 = [1.,2.,3.]
     x2 = [1,2,3,4]
     e2 = [1,1, 1]
     y2 = [2,2, 2]
     dx2 = [1.,2.,3.,4.]
     provide_workspace_with_x_errors(front_name, True, 1, x1, y1, e1, dx1)
     provide_workspace_with_x_errors(rear_name, True, 1, x2, y2, e2, dx2)
     provide_workspace_with_x_errors(result_name, False, 1)
     front = mtd[front_name]
     rear = mtd[rear_name]
     result = mtd[result_name]
     scale = 2.
     # Act
     su.correct_q_resolution_for_merged(front, rear,result, scale)
     # Assert
     self.assertFalse(result.hasDx(0))
     # Clean up
     DeleteWorkspace(front)
     DeleteWorkspace(rear)
     DeleteWorkspace(result)
开发者ID:spaceyatom,项目名称:mantid,代码行数:28,代码来源:SANSUtilityTest.py

示例4: _match_IDF

    def _match_IDF(self, run):
        '''
        Compares the IDF in the stored instrument with the IDF in the workspace.
        If they are the same all is well. If they diff, then load the adequate
        user file.
        @param run: name of the run for which the file is to be extracted
        '''
        # We need the instrument name and the measurement time to determine
        # the IDF
        measurement_time = None
        instrument_name = self.get_instrument_name()
        # We need to be able to handle file-based and workspace-based queries
        # If we have a workspace we look at the end time, else we
        # need a sophisticated extraction mechanism
        if isinstance(run, Workspace):
            ws = None
            if isinstance(run, WorkspaceGroup):
                # Just look at the first element in a workspace group
                ws = run[0]
            else:
                ws = run
            measurement_time = str(ws.getRun().endTime()).strip()
        else:
            if run is None or run == "":
                return
            measurement_time = su.get_measurement_time_from_file(run)

        # Get the path to the instrument definition file
        idf_path_workspace = ExperimentInfo.getInstrumentFilename(instrument_name, measurement_time)
        idf_path_workspace = os.path.normpath(idf_path_workspace)

        # Get the idf from the reducer
        idf_path_reducer = self.get_idf_file_path()
        idf_path_reducer = os.path.normpath(idf_path_reducer)

        # Now check if both idf paths and underlying files. If they are, then don't do anything
        # else switch the underlying instrument
        if idf_path_reducer == idf_path_workspace and su.are_two_files_identical(idf_path_reducer, idf_path_reducer):
            return
        else:
            logger.notice("Updating the IDF of the Reducer. Switching from " +
                          str(idf_path_reducer) + " to " + str(idf_path_workspace))
            idf_path = os.path.basename(idf_path_workspace)
            instrument = self._get_correct_instrument(instrument_name, idf_path)

            # Get detector of the old instrument
            old_instrument = self.get_instrument()
            old_detector_selection = old_instrument.get_detector_selection()

            if instrument is not None:
                self.set_instrument(instrument)

                # We need to update the instrument, by reloading the user file.
                # This is pretty bad, but looking at the reducer architecture this
                # seems to be the only reasonable way to do this.
                self.user_settings.execute(self)

                # Now we set the correct detector, this is also being done in the GUI
                self.get_instrument().setDetector(old_detector_selection)
开发者ID:liyulun,项目名称:mantid,代码行数:59,代码来源:isis_reducer.py

示例5: set_run

    def set_run(self, run, reload, period, reducer):

        super(Can, self).set_run(run, reload, period, reducer)

        # currently, no slices will be applied to Can #8535
        for period in reversed(range(self.loader.periods_in_file)):
            self.loader.move2ws(period)
            name = self.loader.wksp_name
            if su.isEventWorkspace(name):
                su.fromEvent2Histogram(mtd[name], self.get_monitor())
开发者ID:mkoennecke,项目名称:mantid,代码行数:10,代码来源:isis_reducer.py

示例6: delete_cloned_workspaces

def delete_cloned_workspaces(save_names_dict):
    """
        If there are cloned workspaces in the worksapce map, then they are deleted
        @param save_names_dict: a workspace name map
    """
    to_delete =[]
    for key in save_names_dict:
        if key != save_names_dict[key]:
            to_delete.append(save_names_dict[key])
    for element in to_delete:
        su.delete_zero_error_free_workspace(input_workspace_name = element)
开发者ID:mantidproject,项目名称:mantid,代码行数:11,代码来源:SANSBatchMode.py

示例7: test_finds_invalid_xml_file_list

 def test_finds_invalid_xml_file_list(self):
     # Arrange
     input = ["test1.xml", "test2.ccl", "test3.xml"]
     # Act
     result =su.is_valid_xml_file_list(input)
     # Assert
     self.assertFalse(result)
开发者ID:spaceyatom,项目名称:mantid,代码行数:7,代码来源:SANSUtilityTest.py

示例8: test_load_valid_added_event_data_and_monitor_file_produces_group_ws

    def test_load_valid_added_event_data_and_monitor_file_produces_group_ws(self):
        # Arrange
        names = ['event_data', 'monitor']
        file_names = self._prepare_workspaces(names = names)
        self._cleanup_workspaces(names = names)

        # Act
        group_ws_name = 'g_ws'
        output_group_file_name = su.bundle_added_event_data_as_group(file_names[0], file_names[1])

        Load(Filename = output_group_file_name, OutputWorkspace = group_ws_name)
        group_ws = mtd[group_ws_name]

        # Assert
        self.assertTrue(isinstance(group_ws, WorkspaceGroup))
        self.assertEqual(group_ws.size(), 2)
        self.assertTrue(os.path.exists(file_names[0])) # File for group workspace exists
        self.assertFalse(os.path.exists(file_names[1]))  # File for monitors is deleted

        # Clean up
        ws_names_to_delete = []
        for ws_name in mtd.getObjectNames():
            if ws_name != group_ws_name:
                ws_names_to_delete.append(str(ws_name))
        self._cleanup_workspaces(names = ws_names_to_delete)

        if os.path.exists(file_names[0]):
            os.remove(file_names[0])
开发者ID:,项目名称:,代码行数:28,代码来源:

示例9: test_finds_empty_list

 def test_finds_empty_list(self):
     # Arrange
     input = []
     # Act
     result = su.is_valid_xml_file_list(input)
     # Assert
     self.assertFalse(result)
开发者ID:spaceyatom,项目名称:mantid,代码行数:7,代码来源:SANSUtilityTest.py

示例10: test_that_error_is_transferred

    def test_that_error_is_transferred(self):
        # Arrange
        x1 = [1,2,3,4,5,6,7,8,9]
        x2 = [1,2,3,4,5,6,7,8,9]
        y1 = [2,2,2,2,2,2,2,2]
        y2 = [2,2,2,2,2,2,2,2]
        e1 = [1,1,1,1,1,1,1,1]
        e2 = [2,2,2,2,2,2,2,2]
        front, rear = self._createWorkspace(x1,y1, e1, x2, y2, e2)

        x_min = 3
        x_max = 7
        # Act 
        f_return, r_return = su.get_error_corrected_front_and_rear_data_sets(front, rear,x_min, x_max)

        # Assert
        self.assertEqual(5, len(f_return.dataX(0)))
        self.assertEqual(5, len(r_return.dataX(0)))

        expected_errors_in_rear = [np.sqrt(5),np.sqrt(5),np.sqrt(5),np.sqrt(5)]
        self.assertTrue(expected_errors_in_rear[0] == r_return.dataE(0)[0])
        self.assertTrue(expected_errors_in_rear[1] == r_return.dataE(0)[1])
        self.assertTrue(expected_errors_in_rear[2] == r_return.dataE(0)[2])
        self.assertTrue(expected_errors_in_rear[3] == r_return.dataE(0)[3])

        # Clean up
        DeleteWorkspace(front)
        DeleteWorkspace(rear)
开发者ID:spaceyatom,项目名称:mantid,代码行数:28,代码来源:SANSUtilityTest.py

示例11: test_converts_false_to_float_when_convertible_string

 def test_converts_false_to_float_when_convertible_string(self):
     # Arrange
     input = "4.78_tg"
     # Act
     result = su.is_convertible_to_float(input)
     # Assert
     self.assertFalse(result)
开发者ID:spaceyatom,项目名称:mantid,代码行数:7,代码来源:SANSUtilityTest.py

示例12: test_converts_true_to_float_when_float

 def test_converts_true_to_float_when_float(self):
     # Arrange
     input = 3.8
     # Act
     result = su.is_convertible_to_float(input)
     # Assert
     self.assertTrue(result)
开发者ID:spaceyatom,项目名称:mantid,代码行数:7,代码来源:SANSUtilityTest.py

示例13: test_convertible_true_to_float_when_convertible_string

 def test_convertible_true_to_float_when_convertible_string(self):
     # Arrange
     input = "4.78"
     # Act
     result = su.is_convertible_to_float(input)
     # Assert
     self.assertTrue(result)
开发者ID:spaceyatom,项目名称:mantid,代码行数:7,代码来源:SANSUtilityTest.py

示例14: test__converts_false_to_integer_when_non_convertible_string

 def test__converts_false_to_integer_when_non_convertible_string(self):
     # Arrange
     input = '34_gt'
     # Act
     result = su.is_convertible_to_int(input)
     # Assert
     self.assertFalse(result)
开发者ID:spaceyatom,项目名称:mantid,代码行数:7,代码来源:SANSUtilityTest.py

示例15: test_converts_true_to_integer_when_convertible_string

 def test_converts_true_to_integer_when_convertible_string(self):
     # Arrange
     input = '34'
     # Act
     result = su.is_convertible_to_int(input)
     # Assert
     self.assertTrue(result)
开发者ID:spaceyatom,项目名称:mantid,代码行数:7,代码来源:SANSUtilityTest.py


注:本文中的SANSUtility类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。