def test_that_script_is_executable_in_mantid(self): # data files are here self.scriptElement.dataDir = '' # vanadium runs & comment self.scriptElement.vanRuns = 'TOFTOFTestdata.nxs' # empty can runs, comment, and factor self.scriptElement.ecRuns = 'TOFTOFTestdata.nxs' self.scriptElement.ecTemp = OptionalFloat(21.0) self.scriptElement.ecFactor = 0.9 # data runs: [(runs,comment, temperature), ...] self.scriptElement.dataRuns = [ [unicode('TOFTOFTestdata.nxs'), unicode('H2O 21C'), OptionalFloat(None)], [unicode('TOFTOFTestdata.nxs'), unicode('H2O 34C'), OptionalFloat(34.0)] ] self.scriptElement.maskDetectors = '1,2' # options self.scriptElement.subtractECVan = True self.scriptElement.normalise = TOFTOFScriptElement.NORM_MONITOR self.scriptElement.correctTof = TOFTOFScriptElement.CORR_TOF_VAN self.scriptElement.replaceNaNs = True self.scriptElement.createDiff = True self.scriptElement.keepSteps = True testhelpers.assertRaisesNothing(self, self.execScript, self.scriptElement.to_script().replace('import matplotlib.pyplot as plt', ''))
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
def setValidInputs(scriptElement): scriptElement.reset() scriptElement.facility_name = 'MLZ' scriptElement.instrument_name = 'TOFTOF' # prefix of (some) workspace names scriptElement.prefix = 'ws' # data files are here scriptElement.dataDir = '/Somepath/somewhere/' # vanadium runs & comment scriptElement.vanRuns = '1:3' scriptElement.vanCmnt = 'vanadium comment' scriptElement.vanTemp = OptionalFloat(None) # empty can runs, comment, and factor scriptElement.ecRuns = '' scriptElement.ecTemp = OptionalFloat(None) scriptElement.ecFactor = 1 # data runs: [(runs,comment, temperature), ...] scriptElement.dataRuns = [[ unicode('0:5'), unicode('Comment for Run 0:5'), OptionalFloat(None) ]] # additional parameters scriptElement.binEon = True scriptElement.binEstart = 0.0 scriptElement.binEstep = 0.1 scriptElement.binEend = 1.0 scriptElement.binQon = True scriptElement.binQstart = 0.0 scriptElement.binQstep = 0.1 scriptElement.binQend = 1.0 scriptElement.maskDetectors = '' # options scriptElement.subtractECVan = False scriptElement.normalise = TOFTOFScriptElement.NORM_NONE scriptElement.correctTof = TOFTOFScriptElement.CORR_TOF_NONE scriptElement.replaceNaNs = False scriptElement.createDiff = False scriptElement.keepSteps = False # save data scriptElement.saveDir = '' scriptElement.saveSofTWNxspe = False scriptElement.saveSofTWNexus = False scriptElement.saveSofTWAscii = False scriptElement.saveSofQWNexus = False scriptElement.saveSofQWAscii = False
def _textToData(self, row, col, text): """ converts a displayable text back to stored data. """ if col == 2: return OptionalFloat(text) else: return text # just return the value, it is already str.
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))