예제 #1
0
    def get_state(self):
        elem = TOFTOFScriptElement()

        def line_text(lineEdit):
            return str(lineEdit.text()).strip()

        def is_checked(checkBox):
            return checkBox.isChecked() and checkBox.isEnabled()

        elem.facility_name = self._settings.facility_name
        elem.instrument_name = self._settings.instrument_name

        elem.prefix = line_text(self.prefix)
        elem.dataDir = line_text(self.dataDir)

        elem.vanRuns = line_text(self.vanRuns)
        elem.vanCmnt = line_text(self.vanCmnt)
        elem.vanTemp = OptionalFloat(line_text(self.vanTemp))
        elem.vanEcFactor = self.vanEcFactor.value()

        elem.ecRuns = line_text(self.ecRuns)
        elem.ecTemp = OptionalFloat(line_text(self.ecTemp))
        elem.ecFactor = self.ecFactor.value()

        elem.dataRuns = self.runDataModel.tableData

        elem.binEon = is_checked(self.binEon)
        elem.binEstart = self.binEstart.value()
        elem.binEstep = self.binEstep.value()
        elem.binEend = self.binEend.value()

        elem.binQon = is_checked(self.binQon)
        elem.binQstart = self.binQstart.value()
        elem.binQstep = self.binQstep.value()
        elem.binQend = self.binQend.value()

        elem.maskDetectors = line_text(self.maskDetectors)

        elem.subtractECVan = is_checked(self.chkSubtractECVan)
        elem.replaceNaNs = is_checked(self.chkReplaceNaNs)
        elem.createDiff = is_checked(self.chkCreateDiff)
        elem.keepSteps = is_checked(self.chkKeepSteps)

        elem.saveDir = line_text(self.saveDir)
        elem.saveSofTWNxspe = is_checked(self.chkSofTWNxspe)
        elem.saveSofTWNexus = is_checked(self.chkSofTWNexus)
        elem.saveSofTWAscii = is_checked(self.chkSofTWAscii)
        elem.saveSofQWNexus = is_checked(self.chkSofQWNexus)
        elem.saveSofQWAscii = is_checked(self.chkSofQWAscii)

        elem.normalise     = elem.NORM_MONITOR    if self.rbtNormaliseMonitor.isChecked() else \
            elem.NORM_TIME       if self.rbtNormaliseTime.isChecked()    else \
            elem.NORM_NONE

        elem.correctTof    = elem.CORR_TOF_VAN    if self.rbtCorrectTOFVan.isChecked()    else \
            elem.CORR_TOF_SAMPLE if self.rbtCorrectTOFSample.isChecked() else \
            elem.CORR_TOF_NONE
        return elem
예제 #2
0
    def get_state(self):
        elem = TOFTOFScriptElement()

        def line_text(lineEdit):
            return lineEdit.text().strip()

        elem.facility_name = self._settings.facility_name
        elem.instrument_name = self._settings.instrument_name

        elem.prefix = line_text(self.prefix)
        elem.dataDir = line_text(self.dataDir)

        elem.vanRuns = line_text(self.vanRuns)
        elem.vanCmnt = line_text(self.vanCmnt)

        elem.ecRuns = line_text(self.ecRuns)
        elem.ecFactor = self.ecFactor.value()

        elem.dataRuns = self.runDataModel.dataRuns

        elem.binEon = self.binEon.isChecked()
        elem.binEstart = self.binEstart.value()
        elem.binEstep = self.binEstep.value()
        elem.binEend = self.binEend.value()

        elem.binQon = self.binQon.isChecked()
        elem.binQstart = self.binQstart.value()
        elem.binQstep = self.binQstep.value()
        elem.binQend = self.binQend.value()

        elem.maskDetectors = line_text(self.maskDetectors)

        elem.subtractECVan = self.chkSubtractECVan.isChecked()
        elem.replaceNaNs = self.chkReplaceNaNs.isChecked()
        elem.createDiff = self.chkCreateDiff.isChecked()
        elem.keepSteps = self.chkKeepSteps.isChecked()

        elem.saveDir = line_text(self.saveDir)
        elem.saveSofQW = self.chkSofQW.isChecked()
        elem.saveSofTW = self.chkSofTW.isChecked()
        elem.saveNXSPE = self.chkNxspe.isChecked()
        elem.saveNexus = self.chkNexus.isChecked()
        elem.saveAscii = self.chkAscii.isChecked()

        elem.normalise     = elem.NORM_MONITOR    if self.rbtNormaliseMonitor.isChecked() else \
            elem.NORM_TIME       if self.rbtNormaliseTime.isChecked()    else \
            elem.NORM_NONE

        elem.correctTof    = elem.CORR_TOF_VAN    if self.rbtCorrectTOFVan.isChecked()    else \
            elem.CORR_TOF_SAMPLE if self.rbtCorrectTOFSample.isChecked() else \
            elem.CORR_TOF_NONE
        return elem
예제 #3
0
    def get_state(self):
        elem = TOFTOFScriptElement()

        def line_text(lineEdit):
            return lineEdit.text().strip()

        elem.facility_name = self._settings.facility_name
        elem.instrument_name = self._settings.instrument_name

        elem.prefix = line_text(self.prefix)
        elem.dataDir = line_text(self.dataDir)

        elem.vanRuns = line_text(self.vanRuns)
        elem.vanCmnt = line_text(self.vanCmnt)

        elem.ecRuns = line_text(self.ecRuns)
        elem.ecFactor = self.ecFactor.value()

        elem.dataRuns = self.runDataModel.dataRuns

        elem.binEon = self.binEon.isChecked()
        elem.binEstart = self.binEstart.value()
        elem.binEstep = self.binEstep.value()
        elem.binEend = self.binEend.value()

        elem.binQon = self.binQon.isChecked()
        elem.binQstart = self.binQstart.value()
        elem.binQstep = self.binQstep.value()
        elem.binQend = self.binQend.value()

        elem.maskDetectors = line_text(self.maskDetectors)

        elem.subtractECVan = self.chkSubtractECVan.isChecked()

        elem.normalise = (
            elem.NORM_MONITOR
            if self.rbtNormaliseMonitor.isChecked()
            else elem.NORM_TIME
            if self.rbtNormaliseTime.isChecked()
            else elem.NORM_NONE
        )

        elem.correctTof = (
            elem.CORR_TOF_VAN
            if self.rbtCorrectTOFVan.isChecked()
            else elem.CORR_TOF_SAMPLE
            if self.rbtCorrectTOFSample.isChecked()
            else elem.CORR_TOF_NONE
        )
        return elem
예제 #4
0
    def test_that_preserves_data(self):
        scriptElement = TOFTOFScriptElement()
        scriptElement.reset()
        scriptElement.facility_name = 'nonsense'
        scriptElement.instrument_name = 'The 5th nonSense'

        # prefix of (some) workspace names
        scriptElement.prefix = 'ws'

        # data files are here
        scriptElement.dataDir = ''

        # vanadium runs & comment
        scriptElement.vanRuns = 'TOFTOFTestdata.nxs'
        scriptElement.vanCmnt = 'vanadium comment'
        scriptElement.vanTemp = OptionalFloat(None)

        # empty can runs, comment, and factor
        scriptElement.ecRuns = 'TOFTOFTestdata.nxs'
        scriptElement.ecTemp = OptionalFloat(21.0)
        scriptElement.ecFactor = 0.9

        # data runs: [(runs,comment, temperature), ...]
        scriptElement.dataRuns = [[
            unicode('TOFTOFTestdata.nxs'),
            unicode('H2O 21C'),
            OptionalFloat(None)
        ],
                                  [
                                      unicode('TOFTOFTestdata.nxs'),
                                      unicode('H2O 34C'),
                                      OptionalFloat(34.0)
                                  ]]

        # additional parameters
        scriptElement.binEon = True
        scriptElement.binEstart = -1.0
        scriptElement.binEstep = 0.4
        scriptElement.binEend = 1.8

        scriptElement.binQon = True
        scriptElement.binQstart = 0.4
        scriptElement.binQstep = 0.2
        scriptElement.binQend = 1.0

        scriptElement.maskDetectors = '1,2'

        # options
        scriptElement.subtractECVan = True
        scriptElement.normalise = TOFTOFScriptElement.NORM_MONITOR
        scriptElement.correctTof = TOFTOFScriptElement.CORR_TOF_VAN
        scriptElement.replaceNaNs = True
        scriptElement.createDiff = True
        scriptElement.keepSteps = True

        # save data
        scriptElement.saveDir = ''
        scriptElement.saveSofTWNxspe = False
        scriptElement.saveSofTWNexus = True
        scriptElement.saveSofTWAscii = True
        scriptElement.saveSofQWNexus = False
        scriptElement.saveSofQWAscii = True

        self.setupWidget.set_state(scriptElement)

        with mock.patch(
                'reduction_gui.reduction.toftof.toftof_reduction.TOFTOFScriptElement.reset'
        ):
            scriptElement2 = self.setupWidget.get_state()

        scriptElement.facility_name = self.settingsMock.facility_name
        scriptElement.instrument_name = self.settingsMock.instrument_name
        for name in dir(scriptElement):
            attr1 = getattr(scriptElement, name)
            try:
                attr2 = getattr(scriptElement2, name)
            except AttributeError:
                self.fail(
                    "TOFTOFSetupWidget.get_state() doesn't set the attribute '{}'"
                    .format(name))

            if not name.startswith('__') and not hasattr(attr1, '__call__'):
                self.assertEqual(
                    attr1, attr2,
                    "TOFTOFSetupWidget doesn't preserve state of attribute '{}'"
                    .format(name))
예제 #5
0
    def test_that_preserves_data(self):
        scriptElement = TOFTOFScriptElement()
        scriptElement.reset()
        scriptElement.facility_name   = 'nonsense'
        scriptElement.instrument_name = 'The 5th nonSense'

        # prefix of (some) workspace names
        scriptElement.prefix   = 'ws'

        # data files are here
        scriptElement.dataDir  = ''

        # vanadium runs & comment
        scriptElement.vanRuns  = 'TOFTOFTestdata.nxs'
        scriptElement.vanCmnt  = 'vanadium comment'
        scriptElement.vanTemp  = OptionalFloat(None)

        # empty can runs, comment, and factor
        scriptElement.ecRuns   = 'TOFTOFTestdata.nxs'
        scriptElement.ecTemp   = OptionalFloat(21.0)
        scriptElement.ecFactor = 0.9

        # data runs: [(runs,comment, temperature), ...]
        scriptElement.dataRuns = [
            [unicode('TOFTOFTestdata.nxs'), unicode('H2O 21C'), OptionalFloat(None)],
            [unicode('TOFTOFTestdata.nxs'), unicode('H2O 34C'), OptionalFloat(34.0)]
        ]

        # additional parameters
        scriptElement.binEon        = True
        scriptElement.binEstart     = -1.0
        scriptElement.binEstep      = 0.4
        scriptElement.binEend       = 1.8

        scriptElement.binQon        = True
        scriptElement.binQstart     = 0.4
        scriptElement.binQstep      = 0.2
        scriptElement.binQend       = 1.0

        scriptElement.maskDetectors = '1,2'

        # options
        scriptElement.subtractECVan = True
        scriptElement.normalise     = TOFTOFScriptElement.NORM_MONITOR
        scriptElement.correctTof    = TOFTOFScriptElement.CORR_TOF_VAN
        scriptElement.replaceNaNs   = True
        scriptElement.createDiff    = True
        scriptElement.keepSteps     = True

        # save data
        scriptElement.saveDir        = ''
        scriptElement.saveSofTWNxspe = False
        scriptElement.saveSofTWNexus = True
        scriptElement.saveSofTWAscii = True
        scriptElement.saveSofQWNexus = False
        scriptElement.saveSofQWAscii = True

        self.setupWidget.set_state(scriptElement)

        with mock.patch('reduction_gui.reduction.toftof.toftof_reduction.TOFTOFScriptElement.reset'):
            scriptElement2 = self.setupWidget.get_state()

        scriptElement.facility_name   = self.settingsMock.facility_name
        scriptElement.instrument_name = self.settingsMock.instrument_name
        for name in dir(scriptElement):
            attr1 = getattr(scriptElement, name)
            try:
                attr2 = getattr(scriptElement2, name)
            except AttributeError:
                self.fail("TOFTOFSetupWidget.get_state() doesn't set the attribute '{}'".format(name))

            if not name.startswith('__') and not hasattr(attr1, '__call__'):
                self.assertEqual(attr1, attr2, "TOFTOFSetupWidget doesn't preserve state of attribute '{}'".format(name))