Пример #1
0
    def PyExec(self):
        """ Main Execution Body
        """
        # 1. Setup output workspaces
        paramWS = WorkspaceFactory.createTable()
        self.setProperty("InstrumentParameterWorkspace", paramWS)

        hklWS = WorkspaceFactory.createTable()
        self.setProperty("BraggPeakParameterWorkspace", hklWS)

        # 2. Get Other Properties
        instrument = self.getProperty("Instrument")
        reflectionfilename = self.getPropertyValue("ReflectionsFile")
        irffilename = self.getPropertyValue("FullprofParameterFile")

        # 3. Import reflections list
        hkldict = self.importFullProfHKLFile(reflectionfilename)

        hkllist = sorted(hkldict.keys())
        if _OUTPUTLEVEL == "INFORMATION":
            for hkl in hkllist:
                print "Import Peak (%d, %d, %d): FWHM = %f" % (hkl[0], hkl[1], hkl[2], hkldict[hkl]["FWHM"])

        # 4. Import parameter file (.irf)
        peakparamsdict = self.parseFullprofPeakProfileFile(irffilename)

        # 5. Set up the table workspaces 
        self.createPeakParameterWorkspace(peakparamsdict, paramWS)
        self.createReflectionWorkspace(hkldict, hklWS)

        return
Пример #2
0
 def test_table_is_resized_correctly(self):
     table = WorkspaceFactory.createTable()
     self.assertEquals(len(table), 0)
     table.setRowCount(5)
     self.assertEquals(len(table), 5)
     self.assertTrue(table.addColumn(type="int",name="index"))
     self.assertEquals(table.columnCount(), 1)
Пример #3
0
    def PyExec(self):
        """ Main Execution Body
        """
        # 1. Get Input properties
        inppeakws = self.getProperty("BraggPeakParameterWorkspace").value
        inpzscows = self.getProperty("ZscoreWorkspace").value

        minpeakheight = float(self.getPropertyValue("MinimumPeakHeight"))
        zscorefilterstr = self.getPropertyValue("ZscoreFilter")

        print "Input: PeakParameterWorkspace = %s;  ZscoreWorkspace = %s" % (inppeakws.name, inpzscows.name)
        print "       Minimum peak height = %f" % (minpeakheight)
        print "       Zscore filter: %s" % (zscorefilterstr)

        # 3. Parse Zscore table and peak parameters
        self.mPeaks = {}

        zscoredict = self.parseBraggPeakParameterTable(inpzscows)
        self.mPeaks = self.parseBraggPeakParameterTable(inppeakws)

        # 4. Filter by peak height
        self.filterByPeakHeight(minpeakheight)

        # 5. Filter by zscore
        zscorefilterdict = self.parseZscoreFilter(zscorefilterstr)
        self.filterByZscore(zscoredict, zscorefilterdict)

        # 6. Generate the output
        paramWS = WorkspaceFactory.createTable()
        self.genBraggPeakParameterWorkspace(paramWS)
        self.setProperty("OutputBraggPeakParameterWorkspace", paramWS)

        return
Пример #4
0
    def _loadFullprofPrfFile(self, prffilename):
        """ Load Fullprof .prf file
        """
        # 1. Parse the file to dictionary
        infodict, data = self._parseFullprofPrfFile(prffilename)

        # 2. Export information to table file
        tablews = WorkspaceFactory.createTable()
        tablews.addColumn("str", "Name")
        tablews.addColumn("double", "Value")
        for parname in infodict.keys():
            parvalue = infodict[parname]
            tablews.addRow([parname, parvalue])

        # 3. Export the data workspace
        datasize = len(data)
        print "Data Size = ", datasize
        dataws = WorkspaceFactory.create("Workspace2D", 4, datasize, datasize)
        for i in xrange(datasize):
            for j in xrange(4):
                dataws.dataX(j)[i] = data[i][0]
                dataws.dataY(j)[i] = data[i][j+1]
                dataws.dataE(j)[i] = 1.0

        return (tablews, dataws)
Пример #5
0
    def test_adding_table_data_using_numpy(self):
        table = WorkspaceFactory.createTable()
        table.addColumn(type="int",name="index")
        self.assertEquals(table.columnCount(), 1)
        table.addColumn(type="int",name="value")
        self.assertEquals(table.columnCount(), 2)

        nextrow = [1, 10]
        values32 = numpy.array(nextrow).astype(numpy.int32)
        values64 = numpy.array(nextrow).astype(numpy.int64)

        table.addRow(values32)
        self.assertEquals(len(table), 1)
        insertedrow = table.row(0)
        self.assertEquals(1, insertedrow['index'])
        self.assertEquals(10, insertedrow['value'])

        table.addRow(values64)
        self.assertEquals(len(table), 2)
        insertedrow = table.row(1)
        self.assertEquals(1, insertedrow['index'])
        self.assertEquals(10, insertedrow['value'])

        incorrect_type = numpy.array(['1', '10'])
        self.assertRaises(TypeError, table.addRow, incorrect_type)
Пример #6
0
    def test_set_and_extract_v3d_columns(self):
        from mantid.kernel import V3D

        table = WorkspaceFactory.createTable()
        table.addColumn(type='V3D', name='pos')
        table.addRow([V3D(1,1,1)])

        self.assertEquals(V3D(1,1,1), table.cell(0, 0))
Пример #7
0
    def test_set_and_extract_boolean_columns(self):
        table = WorkspaceFactory.createTable()
        table.addColumn(type='bool', name='yes_no')
        table.addRow([True])
        table.addRow([False])

        self.assertTrue(table.cell(0, 0))
        self.assertFalse(table.cell(1, 0))
Пример #8
0
 def _create_test_table(self):
     table = WorkspaceFactory.createTable()
     table.addColumn(type='int', name='index')
     table.addColumn(type='str', name='name')
     table.addRow([0, '1'])
     table.addRow([0, '2'])
     table.addRow([0, '3'])
     return table
Пример #9
0
 def test_set_and_extract_boolean_columns(self):
     table = WorkspaceFactory.createTable()
     table.addColumn(type='bool', name='yes_no')
     table.addRow([True])
     table.addRow([False])
     
     self.assertTrue(table.cell(0, 0))
     self.assertFalse(table.cell(1, 0))
Пример #10
0
 def _create_test_table(self):
     table = WorkspaceFactory.createTable()
     table.addColumn(type="int", name="index")
     table.addColumn(type="str", name="name")
     table.addRow([0, "1"])
     table.addRow([0, "2"])
     table.addRow([0, "3"])
     return table
Пример #11
0
 def _create_test_table(self):
     table = WorkspaceFactory.createTable()
     table.addColumn(type='int', name='index')
     table.addColumn(type='str', name='name')
     table.addRow([0,'1'])
     table.addRow([0,'2'])
     table.addRow([0,'3'])
     return table
Пример #12
0
    def test_set_and_extract_v3d_columns(self):
        from mantid.kernel import V3D

        table = WorkspaceFactory.createTable()
        table.addColumn(type='V3D', name='pos')
        table.addRow([V3D(1,1,1)])

        self.assertEquals(V3D(1,1,1), table.cell(0, 0))
Пример #13
0
def create_results_table():
    table = WorkspaceFactory.createTable()

    table.addColumn(type='str', name='workspace_name')
    table.addColumn(type='float', name='A0')
    table.addColumn(type='float', name='A1')
    table.addRow(["MUSR62260; Group; bottom; Asymmetry; MA", 0.1, 0.2])
    table.addRow(["MUSR62260; Group; top; Asymmetry; MA", 0.3, 0.4])
    table.addRow(["MUSR62260; Group; fwd; Asymmetry; MA", 0.5, 0.6])
    return table
Пример #14
0
    def test_that_get_workspace_names_to_display_from_context_only_returns_the_names_that_exist_in_the_ADS(
            self):
        self.model.context.results_context.result_table_names = self.result_table_names

        table_workspace = WorkspaceFactory.createTable()
        add_ws_to_ads("Result1", table_workspace)

        self.assertEqual(
            self.model.get_workspace_names_to_display_from_context(),
            ["Result1"])
Пример #15
0
    def test_set_and_extract_vector_columns(self):
        table = WorkspaceFactory.createTable()
        table.addColumn(type='vector_int', name='values')

        # Settings from general Python list
        table.addRow([ [1,2,3,4,5] ])
        # Setting from numpy array
        table.addRow([ numpy.array([6,7,8,9,10]) ])

        self.assertTrue( numpy.array_equal( table.cell(0,0), numpy.array([1,2,3,4,5]) ) )
        self.assertTrue( numpy.array_equal( table.cell(1,0), numpy.array([6,7,8,9,10]) ) )
Пример #16
0
    def test_column_types(self):
        table = WorkspaceFactory.createTable()
        table.addColumn(type="int", name="index")
        table.addColumn(type="str", name="value")
        table.addColumn(type="V3D", name="position")

        types = table.columnTypes()

        self.assertEqual(types[0], "int")
        self.assertEqual(types[1], "str")
        self.assertEqual(types[2], "V3D")
Пример #17
0
    def test_set_and_extract_vector_columns(self):
        table = WorkspaceFactory.createTable()
        table.addColumn(type='vector_int', name='values')

        # Settings from general Python list
        table.addRow([ [1,2,3,4,5] ])
        # Setting from numpy array
        table.addRow([ numpy.array([6,7,8,9,10]) ])

        self.assertTrue( numpy.array_equal( table.cell(0,0), numpy.array([1,2,3,4,5]) ) )
        self.assertTrue( numpy.array_equal( table.cell(1,0), numpy.array([6,7,8,9,10]) ) )
 def create_table_workspace(self, table_name):
     table = WorkspaceFactory.createTable()
     table.addColumn('double', X_COLUMN_LABEL, 1)
     table.addColumn('double', Y_COLUMN_LABEL, 2)
     for i in range(1, 10):
         table.addRow([0.1 * i, 5])
     AnalysisDataService.Instance().addOrReplace(table_name, table)
     self.fit_browser.getXColumnName.return_value = X_COLUMN_LABEL
     self.fit_browser.getYColumnName.return_value = Y_COLUMN_LABEL
     self.fit_browser.getErrColumnName.return_value = None
     self.fit_browser.startX.return_value = 0.15
     self.fit_browser.endX.return_value = 0.95
Пример #19
0
    def test_adding_table_data_using_list(self):
        table = WorkspaceFactory.createTable()
        table.addColumn(type="int", name="index")
        self.assertEquals(table.columnCount(), 1)
        table.addColumn(type="str", name="value")
        self.assertEquals(table.columnCount(), 2)

        nextrow = {'index': 1, 'value': '10'}
        values = nextrow.values()
        table.addRow(nextrow)
        self.assertEquals(len(table), 1)
        insertedrow = table.row(0)
        self.assertEquals(insertedrow, nextrow)
        insertedrow = table.row(0)
        self.assertEquals(insertedrow, nextrow)
Пример #20
0
    def test_adding_table_data_using_dictionary(self):
        table = WorkspaceFactory.createTable()
        table.addColumn(type="int", name="index")
        self.assertEquals(table.columnCount(), 1)
        table.addColumn(type="str", name="value")
        self.assertEquals(table.columnCount(), 2)

        nextrow = {'index': 1, 'value': '10'}
        table.addRow(nextrow)
        self.assertEquals(len(table), 1)
        insertedrow = table.row(0)
        self.assertEquals(insertedrow, nextrow)

        incorrect_type = {'index': 1, 'value': 10}
        self.assertRaises(ValueError, table.addRow, incorrect_type)
Пример #21
0
 def test_adding_table_data_using_dictionary(self):
     table = WorkspaceFactory.createTable()
     table.addColumn(type="int",name="index")
     self.assertEquals(table.columnCount(), 1)
     table.addColumn(type="str",name="value")
     self.assertEquals(table.columnCount(), 2)
     
     nextrow = {'index':1, 'value':'10'}
     table.addRow(nextrow)
     self.assertEquals(len(table), 1)
     insertedrow = table.row(0)
     self.assertEquals(insertedrow, nextrow)
     
     incorrect_type = {'index':1, 'value':10}
     self.assertRaises(ValueError, table.addRow, incorrect_type)
Пример #22
0
 def test_adding_table_data_using_list(self):
     table = WorkspaceFactory.createTable()
     table.addColumn(type="int",name="index")
     self.assertEquals(table.columnCount(), 1)
     table.addColumn(type="str",name="value")
     self.assertEquals(table.columnCount(), 2)
     
     nextrow = {'index':1, 'value':'10'}
     values = nextrow.values()
     table.addRow(nextrow)
     self.assertEquals(len(table), 1)
     insertedrow = table.row(0)
     self.assertEquals(insertedrow, nextrow)
     insertedrow = table.row(0)
     self.assertEquals(insertedrow, nextrow)
Пример #23
0
    def test_adding_table_data_using_tuple(self):
        table = WorkspaceFactory.createTable()
        table.addColumn(type="int", name="index")
        self.assertEqual(table.columnCount(), 1)
        table.addColumn(type="str", name="value")
        self.assertEqual(table.columnCount(), 2)

        values = (1, '10')
        table.addRow(values)
        self.assertEqual(len(table), 1)
        insertedrow = table.row(0)
        self.assertEqual(1, insertedrow['index'])
        self.assertEqual('10', insertedrow['value'])

        incorrect_type = (1, 10)
        self.assertRaises(TypeError, table.addRow, incorrect_type)
Пример #24
0
    def test_adding_table_data_using_list(self):
        table = WorkspaceFactory.createTable()
        table.addColumn(type="int",name="index")
        self.assertEquals(table.columnCount(), 1)
        table.addColumn(type="str",name="value")
        self.assertEquals(table.columnCount(), 2)

        values = [1, '10']
        table.addRow(values)
        self.assertEquals(len(table), 1)
        insertedrow = table.row(0)
        self.assertEquals(1, insertedrow['index'])
        self.assertEquals('10', insertedrow['value'])

        incorrect_type = [1, 10]
        self.assertRaises(TypeError, table.addRow, incorrect_type)
    def test_plot_guess_plots_for_table_workspaces(self):
        table = WorkspaceFactory.createTable()
        table.addColumn('double', 'X', 1)
        table.addColumn('double', 'Y', 2)
        for i in range(1, 10):
            table.addRow([0.1 * i, 5])
        name = "table_name"
        AnalysisDataService.Instance().addOrReplace(name, table)
        property_browser = self._create_widget()
        property_browser.getFittingFunction = Mock(
            return_value='name=FlatBackground')
        property_browser.workspaceName = Mock(return_value=name)
        property_browser.startX = Mock(return_value=0.15)
        property_browser.endX = Mock(return_value=0.95)
        property_browser.plot_guess()

        self.assertEqual(1, property_browser.get_axes().plot.call_count)
Пример #26
0
def create_results_table():
    table = WorkspaceFactory.createTable()

    table.addColumn(type='str', name='workspace_name')
    table.addColumn(type='float', name='A0')
    table.addColumn(type='float', name='A1')
    table.addColumn(type='float', name='Sigma')
    table.addColumn(type='float', name='Lambda')
    table.addColumn(type='float', name='f1.Sigma')
    table.addColumn(type='float', name='f1.Lambda')
    table.addRow([
        "MUSR62260; Group; bottom; Asymmetry; MA", 0.1, 0.2, 0.3, 0.4, 0.5, 0.6
    ])
    table.addRow(
        ["MUSR62260; Group; top; Asymmetry; MA", 0.3, 0.4, 0.5, 0.6, 0.7, 0.8])
    table.addRow(
        ["MUSR62260; Group; fwd; Asymmetry; MA", 0.5, 0.6, 0.7, 0.8, 0.9, 1.0])
    return table
Пример #27
0
    def test_workspaces_removed_from_workspace_list_widget_if_deleted_from_ADS(self):
        name = "ws"
        fig, canvas_mock, _ = self._create_and_plot_matrix_workspace(name)
        property_browser = self._create_widget(canvas=canvas_mock)
        property_browser.setOutputName(name)

        # create fake fit output results
        matrixWorkspace = WorkspaceFactory.Instance().create("Workspace2D", NVectors=3, YLength=5, XLength=5)
        AnalysisDataService.Instance().addOrReplace(name + "_Workspace", matrixWorkspace)
        tableWorkspace = WorkspaceFactory.createTable()
        AnalysisDataService.Instance().addOrReplace(name + "_Parameters", tableWorkspace)

        property_browser.fitting_done_slot(name + "_Workspace")
        AnalysisDataService.Instance().remove(name + "_Parameters")
        property_browser.postDeleteHandle(name + "_Parameters")

        wsList = property_browser.getWorkspaceList()
        self.assertEqual(1, len(wsList))
Пример #28
0
    def test_pickle_table_workspace(self):
        from mantid.kernel import V3D
        import pickle

        table = WorkspaceFactory.createTable()
        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())
Пример #29
0
    def test_adding_table_data_using_dictionary(self):
        table = WorkspaceFactory.createTable()
        table.addColumn(type="int", name="index")
        self.assertEqual(table.columnCount(), 1)
        table.addColumn(type="str", name="value")
        self.assertEqual(table.columnCount(), 2)

        nextrow = {'index': 1, 'value': '10'}
        table.addRow(nextrow)
        self.assertEqual(len(table), 1)
        insertedrow = table.row(0)
        self.assertEqual(1, insertedrow['index'])
        self.assertEqual('10', insertedrow['value'])

        incorrect_type = {'index': 1, 'value': 10}
        self.assertRaises(TypeError, table.addRow, incorrect_type)

        incorrect_key = {'notindex': 2, 'notvalue': '20'}
        self.assertRaises(KeyError, table.addRow, incorrect_key)
Пример #30
0
    def test_set_and_extract_plot_types(self):
        table = WorkspaceFactory.createTable()

        table.addColumn("int", "index")
        table.addColumn("int", "value", 3)
        self.assertEqual(table.columnCount(), 2)

        self.assertEqual(table.getPlotType(0), -1000)  # default plot type
        self.assertEqual(table.getPlotType(1), 3)

        table.setPlotType(0, 1)
        table.setPlotType("value", 2)

        self.assertEqual(table.getPlotType("index"), 1)
        self.assertEqual(table.getPlotType("value"), 2)

        table.addRow([1, 2])
        table.addRow([3, 4])
        self.assertEqual(table.rowCount(), 2)
Пример #31
0
    def test_set_and_extract_plot_types(self):
        table = WorkspaceFactory.createTable()

        table.addColumn("int", "index")
        table.addColumn("int", "value", 3)
        self.assertEquals(table.columnCount(), 2)

        self.assertEquals(table.getPlotType(0), -1000) # default plot type
        self.assertEquals(table.getPlotType(1), 3)

        table.setPlotType(0, 1)
        table.setPlotType("value", 2)

        self.assertEquals(table.getPlotType("index"), 1)
        self.assertEquals(table.getPlotType("value"), 2)

        table.addRow([1, 2])
        table.addRow([3, 4])
        self.assertEquals(table.rowCount(), 2)
Пример #32
0
    def test_convert_to_dict(self):
        from mantid.kernel import V3D
        expected_output = {
            'index': [1, 2], 
            'value': ['10', '100'], 
            'position': [V3D(0, 0, 1), V3D(1, 0, 0)] 
        }

        table = WorkspaceFactory.createTable()
        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)

        data = table.toDict()
        self.assertEquals(data, expected_output)
Пример #33
0
    def test_fit_result_workspaces_are_added_to_browser_when_fitting_done(self):
        name = "ws"
        fig, canvas, _ = self._create_and_plot_matrix_workspace(name)
        property_browser = self._create_widget(canvas=canvas)
        property_browser.setOutputName(name)

        # create fake fit output results
        matrixWorkspace = WorkspaceFactory.Instance().create("Workspace2D", NVectors=3, YLength=5, XLength=5)
        tableWorkspace = WorkspaceFactory.createTable()
        AnalysisDataService.Instance().addOrReplace(name + "_Workspace", matrixWorkspace)
        AnalysisDataService.Instance().addOrReplace(name + "_Parameters", tableWorkspace)
        AnalysisDataService.Instance().addOrReplace(name + "_NormalisedCovarianceMatrix", tableWorkspace)

        property_browser.fitting_done_slot(name + "_Workspace")
        workspaceList = property_browser.getWorkspaceList()

        self.assertEqual(3, workspaceList.count())
        self.assertEqual(name + "_NormalisedCovarianceMatrix", workspaceList.item(0).text())
        self.assertEqual(name + "_Parameters", workspaceList.item(1).text())
        self.assertEqual(name + "_Workspace", workspaceList.item(2).text())
Пример #34
0
    def test_convert_to_dict(self):
        from mantid.kernel import V3D
        expected_output = {
            'index': [1, 2],
            'value': ['10', '100'],
            'position': [V3D(0, 0, 1), V3D(1, 0, 0)]
        }

        table = WorkspaceFactory.createTable()
        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)

        data = table.toDict()
        self.assertEqual(data, expected_output)
Пример #35
0
    def test_that_all_latest_fits_will_return_the_two_most_recent_unique_fits(
            self):
        output_ws = WorkspaceFactory.create("Workspace2D",
                                            NVectors=3,
                                            YLength=5,
                                            XLength=5)
        table_workspace = WorkspaceFactory.createTable()

        output_ws_wrap1 = StaticWorkspaceWrapper("Output1", output_ws)
        parameter_ws_wrap1 = StaticWorkspaceWrapper("Parameter1",
                                                    table_workspace)
        covariance_ws_wrap1 = StaticWorkspaceWrapper("Covariance1",
                                                     table_workspace)
        output_ws_wrap2 = StaticWorkspaceWrapper("Output2", output_ws)
        parameter_ws_wrap2 = StaticWorkspaceWrapper("Parameter2",
                                                    table_workspace)
        covariance_ws_wrap2 = StaticWorkspaceWrapper("Covariance2",
                                                     table_workspace)

        fit1 = FitInformation(["Input1"], "GausOsc", [output_ws_wrap1],
                              parameter_ws_wrap1, covariance_ws_wrap1)
        fit2 = FitInformation(["Input2"], "GausOsc", [output_ws_wrap2],
                              parameter_ws_wrap2, covariance_ws_wrap2)
        fit3 = FitInformation(["Input1"], "GausOsc", [output_ws_wrap1],
                              parameter_ws_wrap1, covariance_ws_wrap1)

        self.fitting_context.tf_asymmetry_mode = True
        self.fitting_context.simultaneous_fitting_mode = True
        self.fitting_context.active_fit_history = [fit1, fit2, fit3]

        self.assertEqual(self.fitting_context.active_fit_history[0], fit1)
        self.assertEqual(self.fitting_context.active_fit_history[1], fit2)
        self.assertEqual(self.fitting_context.active_fit_history[2], fit3)

        self.assertEqual(self.fitting_context.all_latest_fits()[0], fit2)
        self.assertEqual(self.fitting_context.all_latest_fits()[1], fit3)

        self.fitting_context.tf_asymmetry_mode = False
        self.assertEqual(self.fitting_context.active_fit_history, [])
        self.assertEqual(self.fitting_context.all_latest_fits()[0], fit2)
        self.assertEqual(self.fitting_context.all_latest_fits()[1], fit3)
    def test_remove_workspace_by_name_will_remove_a_fit_containing_a_specific_parameter_workspace(self):
        output_ws = WorkspaceFactory.create("Workspace2D", NVectors=3, YLength=5, XLength=5)
        table_workspace = WorkspaceFactory.createTable()

        output_ws_wrap1 = StaticWorkspaceWrapper("Output1", output_ws)
        parameter_ws_wrap1 = StaticWorkspaceWrapper("Parameter1", table_workspace)
        covariance_ws_wrap1 = StaticWorkspaceWrapper("Covariance1", table_workspace)
        output_ws_wrap2 = StaticWorkspaceWrapper("Output2", output_ws)
        parameter_ws_wrap2 = StaticWorkspaceWrapper("Parameter2", table_workspace)
        covariance_ws_wrap2 = StaticWorkspaceWrapper("Covariance2", table_workspace)

        fit1 = FitInformation(["Input1"], "GausOsc", [output_ws_wrap1], parameter_ws_wrap1, covariance_ws_wrap1)
        fit2 = FitInformation(["Input2"], "GausOsc", [output_ws_wrap2], parameter_ws_wrap2, covariance_ws_wrap2)

        self.fitting_context.simultaneous_fitting_mode = True
        self.fitting_context.active_fit_history = [fit1, fit2]

        self.fitting_context.remove_workspace_by_name("Parameter1")

        self.assertEqual(self.fitting_context.active_fit_history[0], fit2)
        self.assertEqual(self.fitting_context.all_latest_fits()[0], fit2)
Пример #37
0
    def test_fit_result_matrix_workspace_in_browser_is_viewed_when_clicked(self):
        from mantidqt.widgets.workspacedisplay.table.presenter import TableWorkspaceDisplay

        name = "ws"
        fig, canvas, _ = self._create_and_plot_matrix_workspace(name)
        property_browser = self._create_widget(canvas=canvas)
        property_browser.setOutputName(name)

        # create fake fit output results
        matrixWorkspace = WorkspaceFactory.Instance().create("Workspace2D", NVectors=3, YLength=5, XLength=5)
        AnalysisDataService.Instance().addOrReplace(name + "_Workspace", matrixWorkspace)
        tableWorkspace = WorkspaceFactory.createTable()
        AnalysisDataService.Instance().addOrReplace(name + "_Parameters", tableWorkspace)

        property_browser.fitting_done_slot(name + "_Workspace")
        wsList = property_browser.getWorkspaceList()
        TableWorkspaceDisplay.show_view = Mock()

        # click on table workspace
        item = wsList.item(0).text()
        property_browser.workspaceClicked.emit(item)
        self.assertEqual(1, TableWorkspaceDisplay.show_view.call_count)
Пример #38
0
    def _createReflectionWorkspace(self, hkldict):
        """ Create TableWorkspace containing reflections and etc. 
        """
        # 1. Set up columns
        tablews = WorkspaceFactory.createTable()
        
        tablews.addColumn("int", "H");
        tablews.addColumn("int", "K");
        tablews.addColumn("int", "L"); 
        tablews.addColumn("double", "Alpha"); 
        tablews.addColumn("double", "Beta"); 
        tablews.addColumn("double", "Sigma2"); 
        tablews.addColumn("double", "Gamma"); 
        tablews.addColumn("double", "FWHM"); 
        tablews.addColumn("double", "PeakHeight"); 

        # 2. Add rows
        for hkl in sorted(hkldict.keys()):
            pardict = hkldict[hkl]
            tablews.addRow([hkl[0], hkl[1], hkl[2], pardict["alpha"], pardict["beta"], pardict["sigma2"], pardict["gamma2"], pardict["FWHM"], 1.0])
        # ENDFOR

        return tablews
Пример #39
0
    def test_adding_table_data_using_numpy(self):
        table = WorkspaceFactory.createTable()
        table.addColumn(type="int",name="index")
        self.assertEquals(table.columnCount(), 1)
        table.addColumn(type="int",name="value")
        self.assertEquals(table.columnCount(), 2)

        nextrow = {'index': 1, 'value': 10}
        values32 = numpy.array(nextrow.values()).astype(numpy.int32)
        values64 = numpy.array(nextrow.values()).astype(numpy.int64)

        table.addRow(values32)
        self.assertEquals(len(table), 1)
        insertedrow = table.row(0)
        self.assertEquals(insertedrow, nextrow)

        table.addRow(values64)
        self.assertEquals(len(table), 2)
        insertedrow = table.row(1)
        self.assertEquals(insertedrow, nextrow)

        incorrect_type = numpy.array(['1', '10'])
        self.assertRaises(TypeError, table.addRow, incorrect_type)
Пример #40
0
    def test_log_names_respects_filter(self):
        time_series_logs = (('ts_1', (1., )), ('ts_2', (3., )), ('ts_3', [2.]),
                            ('ts_4', [3.]))
        fake1 = create_test_workspace(ws_name='fake1',
                                      time_series_logs=time_series_logs[:2])
        fake2 = create_test_workspace(ws_name='fake2',
                                      time_series_logs=time_series_logs[2:])

        table_workspace = WorkspaceFactory.createTable()
        fit1 = FitInformation(
            mock.MagicMock(), 'func1',
            [StaticWorkspaceWrapper(fake1.name(), fake1)],
            StaticWorkspaceWrapper(fake1.name(), table_workspace),
            mock.MagicMock())
        fit2 = FitInformation(
            mock.MagicMock(), 'func1',
            [StaticWorkspaceWrapper(fake2.name(), fake2)],
            StaticWorkspaceWrapper(fake2.name(), table_workspace),
            mock.MagicMock())

        self.mock_active_fit_history = mock.PropertyMock(
            return_value=[fit1, fit2])
        type(self.fitting_context
             ).active_fit_history = self.mock_active_fit_history
        self.fitting_context.all_latest_fits = mock.MagicMock(
            return_value=[fit1, fit2])

        self.fitting_context.add_fit(fit1)
        self.fitting_context.add_fit(fit2)

        required_logs = ('ts_2', 'ts_4')
        log_names = self.fitting_context.log_names(
            filter_fn=lambda log: log.name in required_logs)
        self.assertEqual(len(required_logs), len(log_names))
        for name in required_logs:
            self.assertTrue(name in log_names,
                            msg="{} not found in log list".format(name))
Пример #41
0
    def _createReflectionWorkspace(self, hkldict):
        """ Create TableWorkspace containing reflections and etc.
        """
        # 1. Set up columns
        tablews = WorkspaceFactory.createTable()

        tablews.addColumn("int", "H")
        tablews.addColumn("int", "K")
        tablews.addColumn("int", "L")
        tablews.addColumn("double", "Alpha")
        tablews.addColumn("double", "Beta")
        tablews.addColumn("double", "Sigma2")
        tablews.addColumn("double", "Gamma")
        tablews.addColumn("double", "FWHM")
        tablews.addColumn("double", "PeakHeight")

        # 2. Add rows
        for hkl in sorted(hkldict.keys()):
            pardict = hkldict[hkl]
            tablews.addRow([hkl[0], hkl[1], hkl[2], pardict["alpha"], pardict["beta"],
                            pardict["sigma2"], pardict["gamma2"], pardict["FWHM"], 1.0])
        # ENDFOR

        return tablews
    def test_fit_curves_removed_when_workspaces_deleted(self):
        fig, canvas = self._create_and_plot_matrix_workspace(name="ws")
        property_browser = self._create_widget(canvas=canvas)

        manager_mock = Mock()
        manager_mock.canvas = canvas
        observer = FigureManagerADSObserver(manager=manager_mock)  # noqa: F841

        for plot_diff in [True, False]:
            # create fake fit output results
            matrixWorkspace = WorkspaceFactory.Instance().create("Workspace2D",
                                                                 NVectors=3,
                                                                 YLength=5,
                                                                 XLength=5)
            tableWorkspace = WorkspaceFactory.createTable()
            AnalysisDataService.Instance().addOrReplace(
                "ws_Workspace", matrixWorkspace)
            AnalysisDataService.Instance().addOrReplace(
                "ws_Parameters", tableWorkspace)
            AnalysisDataService.Instance().addOrReplace(
                "ws_NormalisedCovarianceMatrix", tableWorkspace)

            property_browser.plotDiff = Mock(return_value=plot_diff)
            property_browser.fitting_done_slot("ws_Workspace")

            if plot_diff:
                self.assertEqual(3, len(fig.get_axes()[0].lines))
            else:
                self.assertEqual(2, len(fig.get_axes()[0].lines))

            AnalysisDataService.Instance().remove("ws_Workspace")
            AnalysisDataService.Instance().remove("ws_Parameters")
            AnalysisDataService.Instance().remove(
                "ws_NormalisedCovarianceMatrix")

            self.assertEqual(1, len(fig.get_axes()[0].lines))
Пример #43
0
    def PyExec(self):
        """ Main Execution Body
        """
        warnings.warn("A message", ModuleDeprecationWarning)

        # 1. Get Input properties
        inppeakws = self.getProperty("BraggPeakParameterWorkspace").value
        inpzscows = self.getProperty("ZscoreWorkspace").value

        minpeakheight = float(self.getPropertyValue("MinimumPeakHeight"))
        zscorefilterstr = self.getPropertyValue("ZscoreFilter")

        print("Input: PeakParameterWorkspace = %s;  ZscoreWorkspace = %s" %
              (inppeakws.name, inpzscows.name))
        print("       Minimum peak height = %f" % (minpeakheight))
        print("       Zscore filter: %s" % (zscorefilterstr))

        # 3. Parse Zscore table and peak parameters
        self.mPeaks = {}

        zscoredict = self.parseBraggPeakParameterTable(inpzscows)
        self.mPeaks = self.parseBraggPeakParameterTable(inppeakws)

        # 4. Filter by peak height
        self.filterByPeakHeight(minpeakheight)

        # 5. Filter by zscore
        zscorefilterdict = self.parseZscoreFilter(zscorefilterstr)
        self.filterByZscore(zscoredict, zscorefilterdict)

        # 6. Generate the output
        paramWS = WorkspaceFactory.createTable()
        self.genBraggPeakParameterWorkspace(paramWS)
        self.setProperty("OutputBraggPeakParameterWorkspace", paramWS)

        return
Пример #44
0
    def PyExec(self):
        """ Mantid required
        """
        self.log().warning('Poldi Data Analysis ---- add dir')
        load_data_at_the_end = False
        
        sample_info_ws_name = ""
          
        try:
            sample_info_ws_name = self.getProperty("PoldiAnalysis").value
            if(sample_info_ws_name == ""):
                sample_info_ws_name = "PoldiAnalysis"
            self.log().debug('Poldi Data Analysis ---- %s'%(sample_info_ws_name))
            sample_info_ws = mtd["PoldiAnalysis"]
            self.log().debug('                    ---- workspace loaded')
        except:
            self.log().debug('                    ---- workspace created')
            sample_info_ws = WorkspaceFactory.createTable()
            sample_info_ws.addColumn("str","spl Name")
            sample_info_ws.addColumn("int","year")
            sample_info_ws.addColumn("int","number")
            sample_info_ws.addColumn("str","data file")
            sample_info_ws.addColumn("str","spl log")
            sample_info_ws.addColumn("str","spl corr")
            sample_info_ws.addColumn("str","spl dead wires")
            sample_info_ws.addColumn("str","spl peak")
            load_data_at_the_end = True
#             self.setProperty("PoldiAnalysis", sample_info_ws)
        
        
        
#         self.log().debug('Poldi Data Analysis ---- %s'%(sample_info_ws_name))
#         sample_info_ws = mtd[sample_info_ws_name]
        
        
        directory = self.getProperty("Directory").value
        
        onlyfiles = [ f for f in listdir(directory) if isfile(join(directory,f)) ]
                
        self.log().debug('Poldi - load data')
        for dataFile in onlyfiles:
            (sample_name, sampleExt) = splitext(dataFile)
            file_path = join(directory,dataFile)
            
#             PoldiProjectAddFile(File=file_path)
#                                 , PoldiAnalysis=sample_info_ws)
         
            
            
            if("hdf" in sampleExt):
                self.log().error('Poldi -  samples : %s' %(sample_name))
                file_path = join(directory,dataFile)
                sample_name_log = "%sLog" %sample_name
                sample_name_corr = "%sCorr" %sample_name
                sample_name_deadw = "%sDeadWires" %sample_name
                (sample_year, sample_numero) = self.interpreteName(sample_name)
                sample_name_peak = "%sPeak" %sample_name
                  
                sample_info_ws.addRow([sample_name, sample_year, sample_numero, file_path, 
                                       sample_name_log, 
                                       sample_name_corr,
                                       sample_name_deadw,
                                       sample_name_peak])  
        nb_of_sample = sample_info_ws.rowCount()
        self.log().error('Poldi -  %d samples added' %(nb_of_sample))
                 
                 
                 
          
        if(load_data_at_the_end):
            self.setProperty("PoldiAnalysis", sample_info_ws)
Пример #45
0
    def PyExec(self):
        """ Mantid required
        """
        self.log().debug('Poldi Data Analysis ---- start')
        
        sample_info_ws = self.getProperty("InputWorkspace").value
        
        load_data_at_the_end = False
        try:
            sample_ipp_ws_name = self.getProperty("OutputWorkspace").value
            if(sample_ipp_ws_name == ""):
                sample_ipp_ws_name = "PoldiIPPmanager"
            self.log().debug('Poldi IPP manager ---- %s'%(sample_info_ws_name))
            sample_ipp_ws = mtd["PoldiIPPmanager"]
            self.log().debug('                    ---- workspace ipp loaded')
        except:
            self.log().debug('                    ---- workspace ipp created')
            sample_ipp_ws = WorkspaceFactory.createTable()
            sample_ipp_ws.addColumn("str","spl Name")
            sample_ipp_ws.addColumn("str","ipp version")
            load_data_at_the_end = True
        
        
        wlen_min  = self.getProperty("wlenmin").value
        wlen_max  = self.getProperty("wlenmax").value
        
        bad_wires_threshold  = self.getProperty("BadWiresThreshold").value
        peak_detect_threshold  = self.getProperty("PeakDetectionThreshold").value
        
        self.log().information('Poldi run with parameters')
        self.log().information('      -  wlen_min : %s' %(wlen_min))
        self.log().information('      -  wlen_max : %s' %(wlen_max))
        self.log().information('      -  bad_wires_threshold   : %s' %(bad_wires_threshold))
        self.log().information('      -  peak_detect_threshold : %s' %(peak_detect_threshold))
        
        dictsearch=os.path.join(config['instrumentDefinition.directory'],"nexusdictionaries","poldi.dic")
        self.log().information('Poldi instr folder -  %s' %(dictsearch))
        
        firstOne=""               
                
        self.log().debug('Poldi - load data')
        nb_of_sample = sample_info_ws.rowCount()
        self.log().information('Poldi -  %d samples listed' %(nb_of_sample))
                
        for sample in range(nb_of_sample):
            sampleName      = sample_info_ws.column("spl Name")[sample]
            filePath        = sample_info_ws.column("data file")[sample]
            sampleNameLog   = sample_info_ws.column("spl log")[sample]
            sampleDeadWires = sample_info_ws.column("spl dead wires")[sample]
                
            self.log().information('Poldi - sample %s' %(sampleName))
            LoadSINQFile(Instrument="POLDI", 
                         Filename=filePath, 
                         OutputWorkspace=sampleName)
            
            sample_output_ws = mtd[sampleName]
            
            PoldiLoadLog(InputWorkspace=sample_output_ws, 
                         Filename=filePath, 
                         Dictionary=dictsearch, 
                         PoldiLog=sampleNameLog)
            
            cfgService = ConfigServiceImpl.Instance()

            LoadInstrument(Workspace=sample_output_ws, 
                           Filename=cfgService.getInstrumentDirectory() + "POLDI_Definition_ipp13.xml",
                           RewriteSpectraMap=True)
            
            
            self.log().debug('Poldi - set ipp')
            sample_instrument = sample_output_ws.getInstrument()
            ipp_version = sample_instrument.getStringParameter("ipp")[0]
            
            add_this_ipp = True
            for ipp in range(sample_ipp_ws.rowCount()):
                if(sample_ipp_ws.column("ipp version")[ipp] == ipp_version):
                    add_this_ipp = False
            if(add_this_ipp):
                sample_ipp_ws.addRow([sampleName, ipp_version])
            
            
            self.log().debug('Poldi - dead wires')
            PoldiRemoveDeadWires(InputWorkspace=sample_output_ws, 
                                 RemoveExcludedWires=True, 
                                 AutoRemoveBadWires=False,
                                 BadWiresThreshold=bad_wires_threshold, 
                                 PoldiDeadWires=sampleDeadWires)
        
        
        
        nb_of_ipp = sample_ipp_ws.rowCount()
        self.log().information('Poldi -  %d ipp listed' %(nb_of_ipp))
        
        for ipp in range(nb_of_ipp):
            ex_of_sample    = sample_ipp_ws.column("spl Name")[ipp]
            PoldiIPP        = sample_ipp_ws.column("ipp version")[ipp]
            ipp_chopper_slits = "%s_Chopper" %PoldiIPP
            ipp_Poldi_spectra = "%s_Spectra" %PoldiIPP
            ipp_ipp_data      = "%s_Data"    %PoldiIPP
            
            ex_of_sample_ws = mtd[ex_of_sample]
        
            self.log().debug('Poldi - chopper slits')
            PoldiLoadChopperSlits(InputWorkspace=ex_of_sample_ws, 
                                  PoldiChopperSlits=ipp_chopper_slits)
        
        
            self.log().debug('Poldi - spectra')
            PoldiLoadSpectra(InputWorkspace=ex_of_sample_ws, 
                             PoldiSpectra=ipp_Poldi_spectra)
        
        
            self.log().debug('Poldi - IPP')
            PoldiLoadIPP(InputWorkspace=ex_of_sample_ws, 
                         PoldiIPP=ipp_ipp_data)
        
        
        for sample in range(nb_of_sample):
            sampleName     = sample_info_ws.column("spl Name" )[sample]
            filePath       = sample_info_ws.column("data file")[sample]
            sampleNameLog  = sample_info_ws.column("spl log"  )[sample]
            sampleDeadWires= sample_info_ws.column("spl dead wires"  )[sample]
            sampleNameCorr = sample_info_ws.column("spl corr" )[sample]
            
            groupedResults = GroupWorkspaces([mtd[sampleName].name(), sampleNameLog, sampleDeadWires])
            RenameWorkspace(InputWorkspace=groupedResults,
                            OutputWorkspace="%s_Metadata" % sampleName)

        if(load_data_at_the_end):
            self.setProperty("OutputWorkspace", sample_ipp_ws)
Пример #46
0
 def PyExec(self):
     self.setProperty("OutputWorkspace", WorkspaceFactory.createTable())
Пример #47
0
 def test_creating_a_tableworkspace(self):
     table = WorkspaceFactory.createTable()
     self.assertTrue(isinstance(table, ITableWorkspace))
Пример #48
0
    def _loadFullprofDataFile(self, datafilename):
        """ Parse a Fullprof (multiple) column file
        """
        # Import file
        datafile = open(datafilename, "r")
        rawlines = datafile.readlines()
        datafile.close()

        # Parse head
        iline = 0
        parseheader = True
        #title = ""
        while iline < len(rawlines) and parseheader is True:
            line = rawlines[iline].strip()
            if len(line) > 0:
                if line.count("BANK") != 0:
                    # line information
                    terms = line.split()
                    if terms[0] != 'BANK':
                        raise NotImplementedError("First word must be 'BANK', but not %s" % (terms[0]))
                    #bankid = int(terms[1])
                    numdata = int(terms[2])
                    numlines = int(terms[3])

                    parseheader = False
                # ENDIF
            # ENDIF
            iline += 1
        # ENDWHILE (iline)

        # Data vectors
        vecx = []
        vecy = []
        vece = []

        for i in xrange(iline, len(rawlines)):
            line = rawlines[i].strip()
            if len(line) == 0:
                continue

            terms = line.split()
            numitems = len(terms)
            if numitems % 3 != 0:
                print "%d-th line '%s' is not a data line" % (i, line)
                continue

            numpts = numitems/3
            for j in xrange(numpts):
                x = float(terms[j*3])
                y = float(terms[j*3+1])
                e = float(terms[j*3+2])

                vecx.append(x)
                vecy.append(y)
                vece.append(e)
            # ENDFOR
        # ENDFOR (i)

        # Check
        self.log().notice("Expected to read %d data points; Exactly read %d data points. " % (numdata*numlines, len(vecx)))

        # Create output workspaces
        tablews = WorkspaceFactory.createTable()

        # Create the data workspace
        datasize = len(vecx)
        dataws = WorkspaceFactory.create("Workspace2D", 1, datasize, datasize)
        for i in xrange(datasize):
            dataws.dataX(0)[i] = vecx[i]
            dataws.dataY(0)[i] = vecy[i]
            dataws.dataE(0)[i] = vece[i]

        return (tablews, dataws)
Пример #49
0
    def _loadFullprofDataFile(self, datafilename):
        """ Parse a Fullprof (multiple) column file
        """
        # Import file
        datafile = open(datafilename, "r")
        rawlines = datafile.readlines()
        datafile.close()

        # Parse head
        iline = 0
        parseheader = True
        title = ""
        while iline < len(rawlines) and parseheader is True:
            line = rawlines[iline].strip()
            if len(line) > 0:
                if line.count("BANK") == 0:
                    # header
                    title += line + ", "
                else:
                    # line information
                    terms = line.split()
                    if terms[0] != 'BANK':
                        raise NotImplementedError(
                            "First word must be 'BANK', but not %s" %
                            (terms[0]))
                    bankid = int(terms[1])
                    numdata = int(terms[2])
                    numlines = int(terms[3])

                    parseheader = False
                # ENDIF
            # ENDIF
            iline += 1
        # ENDWHILE (iline)

        # Data vectors
        vecx = []
        vecy = []
        vece = []

        for i in xrange(iline, len(rawlines)):
            line = rawlines[i].strip()
            if len(line) == 0:
                continue

            terms = line.split()
            numitems = len(terms)
            if numitems % 3 != 0:
                print "%d-th line '%s' is not a data line" % (i, line)
                continue

            numpts = numitems / 3
            for j in xrange(numpts):
                x = float(terms[j * 3])
                y = float(terms[j * 3 + 1])
                e = float(terms[j * 3 + 2])

                vecx.append(x)
                vecy.append(y)
                vece.append(e)
            # ENDFOR
        # ENDFOR (i)

        # Check
        self.log().notice(
            "Expected to read %d data points; Exactly read %d data points. " %
            (numdata * numlines, len(vecx)))

        # Create output workspaces
        tablews = WorkspaceFactory.createTable()

        # Create the data workspace
        datasize = len(vecx)
        dataws = WorkspaceFactory.create("Workspace2D", 1, datasize, datasize)
        for i in xrange(datasize):
            dataws.dataX(0)[i] = vecx[i]
            dataws.dataY(0)[i] = vecy[i]
            dataws.dataE(0)[i] = vece[i]

        return (tablews, dataws)
Пример #50
0
    def PyExec(self):
        tableWS = WorkspaceFactory.createTable()

        self.setProperty("OutputWorkspace", tableWS)
Пример #51
0
    def PyExec(self):
        tableWS = WorkspaceFactory.createTable()

        self.setProperty("OutputWorkspace", tableWS)