Пример #1
0
    def test_fit(self):
        """
        Tests that the fit executes, and the outputs
        are moved into the dataset. Does not check the fit values.
        """
        from mantid.simpleapi import mtd
        mtd.clear()

        data = sc.neutron.load(filename=MantidDataHelper.find_file(
            "iris26176_graphite002_sqw.nxs"))

        params, diff = sc.compat.mantid.fit(
            data['Q', 0],
            mantid_args={
                'Function': 'name=LinearBackground,A0=0,A1=1',
                'StartX': 0,
                'EndX': 3
            })

        # check that no workspaces have been leaked in the ADS
        assert len(mtd) == 0
        assert 'data' in diff
        assert 'calculated' in diff
        assert 'diff' in diff
        assert 'status' in params.coords
        assert 'function' in params.coords
        assert 'cost-function' in params.coords
        assert 'chi^2/d.o.f.' in params.coords
Пример #2
0
 def test_Workspace2D_with_include_monitors(self):
     filename = MantidDataHelper.find_file("WISH00016748.raw")
     ds = mantidcompat.load(filename,
                            mantid_args={"LoadMonitors": "Include"})
     monitors = ds.attrs['monitors'].values
     assert isinstance(monitors, sc.DataArray)
     assert monitors.shape == [5, 4471]
Пример #3
0
 def setUpClass(cls):
     import mantid.simpleapi as mantid
     # This is from the Mantid system-test data
     filename = "CNCS_51936_event.nxs"
     # This needs OutputWorkspace specified, as it doesn't
     # pick up the name from the class variable name
     cls.base_event_ws = mantid.LoadEventNexus(
         MantidDataHelper.find_file(filename),
         OutputWorkspace="test_ws{}".format(__file__))
Пример #4
0
    def test_load_component_info(self):
        from mantid.simpleapi import mtd
        mtd.clear()

        ds = sc.Dataset()

        sc.compat.mantid.load_component_info(
            ds, MantidDataHelper.find_file("iris26176_graphite002_sqw.nxs"))

        # check that no workspaces have been leaked in the ADS
        assert len(mtd) == 0, f"Workspaces present: {mtd.getObjectNames()}"

        self.assertTrue("source_position" in ds.coords)
        self.assertTrue("sample_position" in ds.coords)
        self.assertTrue("position" in ds.coords)
Пример #5
0
 def test_Workspace2D_with_include_monitors(self):
     from mantid.simpleapi import mtd
     mtd.clear()
     filename = MantidDataHelper.find_file("WISH00016748.raw")
     ds = mantidcompat.load(filename,
                            mantid_args={"LoadMonitors": "Include"})
     self.assertEqual(len(mtd), 0, mtd.getObjectNames())
     attrs = ds.attrs.keys()
     expected_monitor_attrs = set(
         ["monitor1", "monitor2", "monitor3", "monitor4", "monitor5"])
     assert expected_monitor_attrs.issubset(attrs)
     for monitor_name in expected_monitor_attrs:
         monitors = ds.attrs[monitor_name].values
         assert isinstance(monitors, sc.DataArray)
         assert monitors.shape == [4471]
Пример #6
0
    def test_fit_executes(self):
        """
        Tests that the fit executes, and the outputs
        are moved into the dataset. Does not check the fit values.
        """
        from mantid.simpleapi import Load, mtd
        mtd.clear()

        ws = Load(MantidDataHelper.find_file("iris26176_graphite002_sqw.nxs"),
                  StoreInADS=False)

        fit_ds = sc.compat.mantid.fit(ws, 'name=LinearBackground,A0=0,A1=1', 0,
                                      0, 3)

        # check that no workspaces have been leaked in the ADS
        self.assertEqual(len(mtd), 0, mtd.getObjectNames())
        self.assertTrue("workspace" in fit_ds)
        self.assertTrue("normalised_covariance_matrix" in fit_ds)
        self.assertTrue("parameters" in fit_ds)
        self.assertTrue("cost_function" in fit_ds.attrs)
        self.assertTrue("function" in fit_ds.attrs)
        self.assertTrue("status" in fit_ds.attrs)
        self.assertTrue("chi2_over_DoF" in fit_ds.attrs)
Пример #7
0
 def test_EventWorkspace_with_monitors(self):
     from mantid.simpleapi import mtd
     mtd.clear()
     filename = MantidDataHelper.find_file("CNCS_51936_event.nxs")
     ds = mantidcompat.load(filename, mantid_args={"LoadMonitors": True})
     self.assertEqual(len(mtd), 0, mtd.getObjectNames())
     attrs = ds.attrs.keys()
     expected_monitor_attrs = set(["monitor2", "monitor3"])
     assert expected_monitor_attrs.issubset(attrs)
     for monitor_name in expected_monitor_attrs:
         monitor = ds.attrs[monitor_name].value
         assert isinstance(monitor, sc.DataArray)
         assert monitor.shape == [200001]
         assert 'position' in monitor.coords
         assert 'source_position' in monitor.coords
         # This is essential, otherwise unit conversion assumes scattering
         # from sample:
         assert 'sample_position' not in monitor.coords
         # Absence of the following is not crucial, but currently there is
         # no need for these, and it avoid duplication:
         assert 'detector_info' not in monitor.coords
         assert 'run' not in monitor.attrs
         assert 'sample' not in monitor.attrs
Пример #8
0
 def test_EventWorkspace_with_monitors(self):
     filename = MantidDataHelper.find_file("CNCS_51936_event.nxs")
     ds = mantidcompat.load(filename, mantid_args={"LoadMonitors": True})
     monitors = ds.attrs['monitors'].values
     assert isinstance(monitors, sc.DataArray)
     assert monitors.shape == [2, 200001]