def test_sampleAndCan(self): """ Test simple run with sample and can workspace. """ # Just pass if we can't actually run the algorithm if not is_supported_f2py_platform(): return CylinderPaalmanPingsCorrection( OutputWorkspace=self._corrections_ws_name, SampleWorkspace=self._sample_ws, SampleChemicalFormula='H2-O', SampleInnerRadius=0.05, SampleOuterRadius=0.1, CanWorkspace=self._can_ws, CanChemicalFormula='V', CanOuterRadius=0.15, BeamHeight=0.1, BeamWidth=0.1, Emode='Indirect', Efixed=1.845, Version=1) self._verify_workspaces_for_can()
def PyExec(self): from IndirectImport import run_f2py_compatibility_test, is_supported_f2py_platform if is_supported_f2py_platform(): import IndirectMuscat as Main run_f2py_compatibility_test() self.log().information('Muscat input') prefix = self.getPropertyValue('Instrument') ana = self.getPropertyValue('Analyser') geom = self.getPropertyValue('Geom') disp = self.getPropertyValue('Dispersion') sam = self.getPropertyValue('SamNumber') sname = prefix + sam + '_' + ana NRUN1 = self.getPropertyValue('NR1') NRUN2 = self.getPropertyValue('NR2') NMST = self.getPropertyValue('Nms') JRAND = 12345 MRAND = 67890 neut = [int(NRUN1), int(NRUN2), int(JRAND), int(MRAND), int(NMST)] HEIGHT = 3.0 alfa = self.getPropertyValue('DetAngle') THICK = self.getPropertyValue('Thick') WIDTH = self.getPropertyValue('Width') HEIGHT = self.getPropertyValue('Height') if geom == 'Flat': beam = [float(THICK), float(WIDTH), float(HEIGHT), float(alfa)] if geom == 'Cyl': beam = [float(THICK), float(WIDTH), float(HEIGHT), 0.0] #beam = [WIDTH, WIDTH2, HEIGHT, 0.0] dens = self.getPropertyValue('Density') sigb = self.getPropertyValue('SigScat') siga = self.getPropertyValue('SigAbs') sigss = sigb temp = self.getPropertyValue('Temperature') sam = [float(temp), float(dens), float(siga), float(sigb)] NQ = self.getPropertyValue('NQ') dQ = self.getPropertyValue('dQ') Nw = self.getPropertyValue('NW') dw = self.getPropertyValue('dW') #in microeV grid = [int(NQ), float(dQ), int(Nw), float(dw)] c1 = self.getPropertyValue('Coeff1') c2 = self.getPropertyValue('Coeff2') c3 = self.getPropertyValue('Coeff3') c4 = self.getPropertyValue('Coeff4') c5 = self.getPropertyValue('Coeff5') coeff = [float(c1), float(c2), float(c3), float(c4), float(c5)] kr1 = 1 verbOp = self.getProperty('Verbose').value plotOp = self.getPropertyValue('Plot') saveOp = self.getProperty('Save').value Main.MuscatFuncStart(sname, geom, neut, beam, sam, grid, disp, coeff, kr1, verbOp, plotOp, saveOp)
def PyExec(self): from IndirectImport import run_f2py_compatibility_test, is_supported_f2py_platform if is_supported_f2py_platform(): import IndirectBayes as Main run_f2py_compatibility_test() self.log().information('Quest input') inType = self.getPropertyValue('InputType') prefix = self.getPropertyValue('Instrument') ana = self.getPropertyValue('Analyser') sam = self.getPropertyValue('SamNumber') rinType = self.getPropertyValue('ResInputType') res = self.getPropertyValue('ResNumber') elastic = self.getProperty('ElasticOption').value bgd = self.getPropertyValue('BackgroundOption') emin = self.getPropertyValue('EnergyMin') emax = self.getPropertyValue('EnergyMax') nbin = self.getPropertyValue('SamBinning') nbins = [nbin, 1] nbet = self.getProperty('NumberBeta').value nsig = self.getProperty('NumberSigma').value nbs = [nbet, nsig] sname = prefix+sam+'_'+ana + '_red' rname = prefix+res+'_'+ana + '_res' erange = [float(emin), float(emax)] if elastic: o_el = 1 else: o_el = 0 fitOp = [o_el, bgd, 0, 0] loopOp = self.getProperty('Sequence').value verbOp = self.getProperty('Verbose').value plotOp = self.getPropertyValue('Plot') saveOp = self.getProperty('Save').value workdir = config['defaultsave.directory'] if inType == 'File': spath = os.path.join(workdir, sname+'.nxs') # path name for sample nxs file LoadNexusProcessed(Filename=spath, OutputWorkspace=sname) Smessage = 'Sample from File : '+spath else: Smessage = 'Sample from Workspace : '+sname if rinType == 'File': rpath = os.path.join(workdir, rname+'.nxs') # path name for res nxs file LoadNexusProcessed(Filename=rpath, OutputWorkspace=rname) Rmessage = 'Resolution from File : '+rpath else: Rmessage = 'Resolution from Workspace : '+rname if verbOp: logger.notice(Smessage) logger.notice(Rmessage) Main.QuestRun(sname,rname,nbs,erange,nbins,fitOp,loopOp,plotOp,saveOp)
def PyExec(self): from IndirectImport import run_f2py_compatibility_test, is_supported_f2py_platform if is_supported_f2py_platform(): import IndirectMuscat as Main run_f2py_compatibility_test() self.log().information('Muscat input') prefix = self.getPropertyValue('Instrument') ana = self.getPropertyValue('Analyser') geom = self.getPropertyValue('Geom') disp = self.getPropertyValue('Dispersion') sam = self.getPropertyValue('SamNumber') sname = prefix+sam+'_'+ana NRUN1 = self.getPropertyValue('NR1') NRUN2 = self.getPropertyValue('NR2') NMST = self.getPropertyValue('Nms') JRAND = 12345 MRAND = 67890 neut = [int(NRUN1), int(NRUN2), int(JRAND), int(MRAND), int(NMST)] HEIGHT = 3.0 alfa = self.getPropertyValue('DetAngle') THICK = self.getPropertyValue('Thick') WIDTH = self.getPropertyValue('Width') HEIGHT = self.getPropertyValue('Height') if geom == 'Flat': beam = [float(THICK), float(WIDTH), float(HEIGHT), float(alfa)] if geom == 'Cyl': beam = [float(THICK), float(WIDTH), float(HEIGHT), 0.0] #beam = [WIDTH, WIDTH2, HEIGHT, 0.0] dens = self.getPropertyValue('Density') sigb = self.getPropertyValue('SigScat') siga = self.getPropertyValue('SigAbs') sigss=sigb temp = self.getPropertyValue('Temperature') sam = [float(temp), float(dens), float(siga), float(sigb)] NQ = self.getPropertyValue('NQ') dQ = self.getPropertyValue('dQ') Nw = self.getPropertyValue('NW') dw = self.getPropertyValue('dW') #in microeV grid = [int(NQ), float(dQ), int(Nw), float(dw)] c1 = self.getPropertyValue('Coeff1') c2 = self.getPropertyValue('Coeff2') c3 = self.getPropertyValue('Coeff3') c4 = self.getPropertyValue('Coeff4') c5 = self.getPropertyValue('Coeff5') coeff = [float(c1), float(c2), float(c3), float(c4), float(c5)] kr1 = 1 verbOp = self.getProperty('Verbose').value plotOp = self.getPropertyValue('Plot') saveOp = self.getProperty('Save').value Main.MuscatFuncStart(sname,geom,neut,beam,sam,grid,disp,coeff,kr1,verbOp,plotOp,saveOp)
def PyExec(self): from IndirectImport import run_f2py_compatibility_test, is_supported_f2py_platform if is_supported_f2py_platform(): import IndirectMuscat as Main run_f2py_compatibility_test() self.log().information('Muscat input') prefix = self.getPropertyValue('Instrument') ana = self.getPropertyValue('Analyser') geom = self.getPropertyValue('Geom') sam = self.getPropertyValue('SamNumber') sqwi = self.getPropertyValue('SqwInput') sname = prefix + sam + '_' + ana sqw = prefix + sqwi + '_' + ana NRUN1 = self.getPropertyValue('NR1') NRUN2 = self.getPropertyValue('NR2') NMST = self.getPropertyValue('Nms') JRAND = 12345 MRAND = 67890 neut = [int(NRUN1), int(NRUN2), int(JRAND), int(MRAND), int(NMST)] HEIGHT = 3.0 alfa = self.getPropertyValue('DetAngle') THICK = self.getPropertyValue('Thick') WIDTH = self.getPropertyValue('Width') HEIGHT = self.getPropertyValue('Height') if geom == 'Flat': beam = [float(THICK), float(WIDTH), float(HEIGHT), float(alfa)] if geom == 'Cyl': beam = [float(THICK), float(WIDTH), float(HEIGHT), 0.0] #beam = [WIDTH, WIDTH2, HEIGHT, 0.0] dens = self.getPropertyValue('Density') sigb = self.getPropertyValue('SigScat') siga = self.getPropertyValue('SigAbs') temp = self.getPropertyValue('Temperature') sam = [float(temp), float(dens), float(siga), float(sigb)] kr1 = 1 verbOp = self.getProperty('Verbose').value plotOp = self.getPropertyValue('Plot') saveOp = self.getProperty('Save').value Main.MuscatDataStart(sname, geom, neut, beam, sam, sqw, kr1, verbOp, plotOp, saveOp)
def test_sampleAndCanDefaults(self): """ Test simple run with sample and can workspace using the default values. """ # Just pass if we can't actually run the algorithm if not is_supported_f2py_platform(): return CylinderPaalmanPingsCorrection(OutputWorkspace=self._corrections_ws_name, SampleWorkspace=self._sample_ws, SampleChemicalFormula='H2-O', CanWorkspace=self._can_ws, CanChemicalFormula='V', Version=1) self._verify_workspaces_for_can()
def PyExec(self): from IndirectImport import run_f2py_compatibility_test, is_supported_f2py_platform if is_supported_f2py_platform(): import IndirectBayes as Main run_f2py_compatibility_test() self.log().information('ResNorm input') inType = self.getPropertyValue('InputType') prefix = self.getPropertyValue('Instrument') ana = self.getPropertyValue('Analyser') van = self.getPropertyValue('VanNumber') rinType = self.getPropertyValue('ResInputType') res = self.getPropertyValue('ResNumber') emin = self.getPropertyValue('EnergyMin') emax = self.getPropertyValue('EnergyMax') nbin = self.getPropertyValue('VanBinning') vname = prefix + van + '_' + ana + '_red' rname = prefix + res + '_' + ana + '_res' erange = [float(emin), float(emax)] verbOp = self.getProperty('Verbose').value plotOp = self.getPropertyValue('Plot') saveOp = self.getProperty('Save').value workdir = config['defaultsave.directory'] if inType == 'File': vpath = os.path.join(workdir, vname + '.nxs') # path name for van nxs file LoadNexusProcessed(Filename=vpath, OutputWorkspace=vname) Vmessage = 'Vanadium from File : ' + vpath else: Vmessage = 'Vanadium from Workspace : ' + vname if rinType == 'File': rpath = os.path.join(workdir, rname + '.nxs') # path name for res nxs file LoadNexusProcessed(Filename=rpath, OutputWorkspace=rname) Rmessage = 'Resolution from File : ' + rpath else: Rmessage = 'Resolution from Workspace : ' + rname if verbOp: logger.notice(Vmessage) logger.notice(Rmessage) Main.ResNormRun(vname, rname, erange, nbin, verbOp, plotOp, saveOp)
def test_sampleAndCanDefaults(self): """ Test simple run with sample and can workspace using the default values. """ # Just pass if we can't actually run the algorithm if not is_supported_f2py_platform(): return CylinderPaalmanPingsCorrection( OutputWorkspace=self._corrections_ws_name, SampleWorkspace=self._sample_ws, SampleChemicalFormula='H2-O', CanWorkspace=self._can_ws, CanChemicalFormula='V', Version=1) self._verify_workspaces_for_can()
def PyExec(self): from IndirectImport import run_f2py_compatibility_test, is_supported_f2py_platform if is_supported_f2py_platform(): import IndirectBayes as Main run_f2py_compatibility_test() self.log().information('ResNorm input') inType = self.getPropertyValue('InputType') prefix = self.getPropertyValue('Instrument') ana = self.getPropertyValue('Analyser') van = self.getPropertyValue('VanNumber') rinType = self.getPropertyValue('ResInputType') res = self.getPropertyValue('ResNumber') emin = self.getPropertyValue('EnergyMin') emax = self.getPropertyValue('EnergyMax') nbin = self.getPropertyValue('VanBinning') vname = prefix+van+'_'+ana+ '_red' rname = prefix+res+'_'+ana+ '_res' erange = [float(emin), float(emax)] verbOp = self.getProperty('Verbose').value plotOp = self.getPropertyValue('Plot') saveOp = self.getProperty('Save').value workdir = config['defaultsave.directory'] if inType == 'File': vpath = os.path.join(workdir, vname+'.nxs') # path name for van nxs file LoadNexusProcessed(Filename=vpath, OutputWorkspace=vname) Vmessage = 'Vanadium from File : '+vpath else: Vmessage = 'Vanadium from Workspace : '+vname if rinType == 'File': rpath = os.path.join(workdir, rname+'.nxs') # path name for res nxs file LoadNexusProcessed(Filename=rpath, OutputWorkspace=rname) Rmessage = 'Resolution from File : '+rpath else: Rmessage = 'Resolution from Workspace : '+rname if verbOp: logger.notice(Vmessage) logger.notice(Rmessage) Main.ResNormRun(vname,rname,erange,nbin,verbOp,plotOp,saveOp)
def PyExec(self): from IndirectImport import run_f2py_compatibility_test, is_supported_f2py_platform if is_supported_f2py_platform(): import IndirectMuscat as Main run_f2py_compatibility_test() self.log().information('Muscat input') prefix = self.getPropertyValue('Instrument') ana = self.getPropertyValue('Analyser') geom = self.getPropertyValue('Geom') sam = self.getPropertyValue('SamNumber') sqwi = self.getPropertyValue('SqwInput') sname = prefix+sam+'_'+ana sqw = prefix+sqwi+'_'+ana NRUN1 = self.getPropertyValue('NR1') NRUN2 = self.getPropertyValue('NR2') NMST = self.getPropertyValue('Nms') JRAND = 12345 MRAND = 67890 neut = [int(NRUN1), int(NRUN2), int(JRAND), int(MRAND), int(NMST)] HEIGHT = 3.0 alfa = self.getPropertyValue('DetAngle') THICK = self.getPropertyValue('Thick') WIDTH = self.getPropertyValue('Width') HEIGHT = self.getPropertyValue('Height') if geom == 'Flat': beam = [float(THICK), float(WIDTH), float(HEIGHT), float(alfa)] if geom == 'Cyl': beam = [float(THICK), float(WIDTH), float(HEIGHT), 0.0] #beam = [WIDTH, WIDTH2, HEIGHT, 0.0] dens = self.getPropertyValue('Density') sigb = self.getPropertyValue('SigScat') siga = self.getPropertyValue('SigAbs') temp = self.getPropertyValue('Temperature') sam = [float(temp), float(dens), float(siga), float(sigb)] kr1 = 1 verbOp = self.getProperty('Verbose').value plotOp = self.getPropertyValue('Plot') saveOp = self.getProperty('Save').value Main.MuscatDataStart(sname,geom,neut,beam,sam,sqw,kr1,verbOp,plotOp,saveOp)
def test_sampleOnly(self): """ Test simple run with sample workspace only. """ # Just pass if we can't actually run the algorithm if not is_supported_f2py_platform(): return CylinderPaalmanPingsCorrection(OutputWorkspace=self._corrections_ws_name, SampleWorkspace=self._sample_ws, SampleChemicalFormula='H2-O', SampleInnerRadius=0.05, SampleOuterRadius=0.1, Emode='Indirect', Efixed=1.845, Version=1) ass_ws_name = self._corrections_ws_name + '_ass' self. _verify_workspace(ass_ws_name)
def PyExec(self): from IndirectImport import run_f2py_compatibility_test, is_supported_f2py_platform if is_supported_f2py_platform(): import IndirectBayes as Main run_f2py_compatibility_test() self.log().information("ResNorm input") inType = self.getPropertyValue("InputType") prefix = self.getPropertyValue("Instrument") ana = self.getPropertyValue("Analyser") van = self.getPropertyValue("VanNumber") rinType = self.getPropertyValue("ResInputType") res = self.getPropertyValue("ResNumber") emin = self.getPropertyValue("EnergyMin") emax = self.getPropertyValue("EnergyMax") nbin = self.getPropertyValue("VanBinning") vname = prefix + van + "_" + ana + "_red" rname = prefix + res + "_" + ana + "_res" erange = [float(emin), float(emax)] plotOp = self.getPropertyValue("Plot") saveOp = self.getProperty("Save").value workdir = config["defaultsave.directory"] if inType == "File": vpath = os.path.join(workdir, vname + ".nxs") # path name for van nxs file LoadNexusProcessed(Filename=vpath, OutputWorkspace=vname) Vmessage = "Vanadium from File : " + vpath else: Vmessage = "Vanadium from Workspace : " + vname if rinType == "File": rpath = os.path.join(workdir, rname + ".nxs") # path name for res nxs file LoadNexusProcessed(Filename=rpath, OutputWorkspace=rname) Rmessage = "Resolution from File : " + rpath else: Rmessage = "Resolution from Workspace : " + rname logger.information(Vmessage) logger.information(Rmessage) Main.ResNormRun(vname, rname, erange, nbin, plotOp, saveOp)
def test_sampleOnly(self): """ Test simple run with sample workspace only. """ # Just pass if we can't actually run the algorithm if not is_supported_f2py_platform(): return CylinderPaalmanPingsCorrection( OutputWorkspace=self._corrections_ws_name, SampleWorkspace=self._sample_ws, SampleChemicalFormula='H2-O', SampleInnerRadius=0.05, SampleOuterRadius=0.1, Emode='Indirect', Efixed=1.845, Version=1) ass_ws_name = self._corrections_ws_name + '_ass' self._verify_workspace(ass_ws_name)
def test_InterpolateDisabled(self): """ Tests that a workspace with a bin count equal to NumberWavelengths is created when interpolation is disabled. """ # Just pass if we can't actually run the algorithm if not is_supported_f2py_platform(): return CylinderPaalmanPingsCorrection(OutputWorkspace=self._corrections_ws_name, SampleWorkspace=self._sample_ws, SampleChemicalFormula='H2-O', CanWorkspace=self._can_ws, CanChemicalFormula='V', Interpolate=False, Version=1) corrections_ws = mtd[self._corrections_ws_name] # Check each correction workspace has X binning matching NumberWavelengths for workspace in corrections_ws: self.assertEqual(workspace.blocksize(), 10)
def test_InterpolateDisabled(self): """ Tests that a workspace with a bin count equal to NumberWavelengths is created when interpolation is disabled. """ # Just pass if we can't actually run the algorithm if not is_supported_f2py_platform(): return CylinderPaalmanPingsCorrection( OutputWorkspace=self._corrections_ws_name, SampleWorkspace=self._sample_ws, SampleChemicalFormula='H2-O', CanWorkspace=self._can_ws, CanChemicalFormula='V', Interpolate=False, Version=1) corrections_ws = mtd[self._corrections_ws_name] # Check each correction workspace has X binning matching NumberWavelengths for workspace in corrections_ws: self.assertEqual(workspace.blocksize(), 10)
def test_sampleAndCan(self): """ Test simple run with sample and can workspace. """ # Just pass if we can't actually run the algorithm if not is_supported_f2py_platform(): return CylinderPaalmanPingsCorrection(OutputWorkspace=self._corrections_ws_name, SampleWorkspace=self._sample_ws, SampleChemicalFormula='H2-O', SampleInnerRadius=0.05, SampleOuterRadius=0.1, CanWorkspace=self._can_ws, CanChemicalFormula='V', CanOuterRadius=0.15, BeamHeight=0.1, BeamWidth=0.1, Emode='Indirect', Efixed=1.845, Version=1) self._verify_workspaces_for_can()
def check_platform_support(self): if not is_supported_f2py_platform(): unsupported_msg = "This algorithm can only be run on valid platforms." \ + " please view the algorithm documentation to see" \ + " what platforms are currently supported" raise RuntimeError(unsupported_msg)
def skipTests(self): if is_supported_f2py_platform(): return False else: return True
def PyExec(self): from IndirectImport import is_supported_f2py_platform, import_f2py if is_supported_f2py_platform(): cylabs = import_f2py("cylabs") else: raise RuntimeError('This algorithm is only available on Windows') workdir = config['defaultsave.directory'] self._setup() self._wave_range() # Set sample material from chemical formula SetSampleMaterial(self._sample_ws_name, ChemicalFormula=self._sample_chemical_formula, SampleNumberDensity=self._sample_number_density) sample = mtd[self._sample_ws_name].sample() sam_material = sample.getMaterial() # total scattering x-section sigs = [sam_material.totalScatterXSection()] # absorption x-section siga = [sam_material.absorbXSection()] density = [self._sample_number_density, self._can_number_density, self._can_number_density] half_width = 0.5*float(self._beam_width) beam = [self._beam_height, half_width, -half_width, half_width, -half_width, 0.0, self._beam_height, 0.0, self._beam_height] radii = [self._sample_inner_radius, self._sample_outer_radius, self._can_outer_radius, self._can_outer_radius] ncan = 0 # If using a can, set sample material using chemical formula if self._use_can: ncan = 2 SetSampleMaterial(InputWorkspace=self._can_ws_name, ChemicalFormula=self._can_chemical_formula, SampleNumberDensity=self._can_number_density) can_sample = mtd[self._can_ws_name].sample() can_material = can_sample.getMaterial() # total scattering x-section for can sigs.append(can_material.totalScatterXSection()) sigs.append(can_material.totalScatterXSection()) # absorption x-section for can siga.append(can_material.absorbXSection()) siga.append(can_material.absorbXSection()) else: # total scattering x-section for can sigs.append(0.0) sigs.append(0.0) # absorption x-section for can siga.append(0.0) siga.append(0.0) # Holders for the corrected data data_ass = [] data_assc = [] data_acsc = [] data_acc = [] # initially set errors to zero wrk = workdir + self._can_ws_name self._get_angles() number_angles = len(self._angles) for angle_idx in range(number_angles): kill, ass, assc, acsc, acc = cylabs.cylabs(self._step_size, beam, ncan, radii, density, sigs, siga, self._angles[angle_idx], self._elastic, self._waves, angle_idx, wrk, 0) if kill == 0: logger.information('Angle %d: %f successful' % (angle_idx+1, self._angles[angle_idx])) data_ass = np.append(data_ass, ass) data_assc = np.append(data_assc, assc) data_acsc = np.append(data_acsc, acsc) data_acc = np.append(data_acc, acc) else: raise ValueError('Angle ' + str(angle_idx) + ' : ' + str(self._angles[angle_idx]) + ' *** failed : Error code ' + str(kill)) sample_logs = {'sample_shape': 'cylinder', 'sample_filename': self._sample_ws_name, 'sample_inner_radius': self._sample_inner_radius, 'sample_outer_radius': self._sample_outer_radius} dataX = self._waves * number_angles # Create the output workspaces ass_ws = self._output_ws_name + '_ass' CreateWorkspace(OutputWorkspace=ass_ws, DataX=dataX, DataY=data_ass, NSpec=number_angles, UnitX='Wavelength') self._add_sample_logs(ass_ws, sample_logs) workspaces = [ass_ws] if self._use_can: sample_logs['can_filename'] = self._can_ws_name sample_logs['can_outer_radius'] = self._can_outer_radius assc_ws = self._output_ws_name + '_assc' workspaces.append(assc_ws) CreateWorkspace(OutputWorkspace=assc_ws, DataX=dataX, DataY=data_assc, NSpec=number_angles, UnitX='Wavelength') self._add_sample_logs(assc_ws, sample_logs) acsc_ws = self._output_ws_name + '_acsc' workspaces.append(acsc_ws) CreateWorkspace(OutputWorkspace=acsc_ws, DataX=dataX, DataY=data_acsc, NSpec=number_angles, UnitX='Wavelength') self._add_sample_logs(acsc_ws, sample_logs) acc_ws = self._output_ws_name + '_acc' workspaces.append(acc_ws) CreateWorkspace(OutputWorkspace=acc_ws, DataX=dataX, DataY=data_acc, NSpec=number_angles, UnitX='Wavelength') self._add_sample_logs(acc_ws, sample_logs) if self._interpolate: self._interpolate_corrections(workspaces) try: self. _copy_detector_table(workspaces) except RuntimeError: logger.warning('Cannot copy spectra mapping. Check input workspace instrument.') GroupWorkspaces(InputWorkspaces=','.join(workspaces), OutputWorkspace=self._output_ws_name) self.setPropertyValue('OutputWorkspace', self._output_ws_name)
# Algorithm to start Bayes programs from MantidFramework import * from mantid.simpleapi import * from mantid import config, logger, mtd from IndirectImport import run_f2py_compatibility_test, is_supported_f2py_platform if is_supported_f2py_platform(): import IndirectBayes as Main class QLines(PythonAlgorithm): def category(self): return "Workflow\\MIDAS;PythonAlgorithms" def PyInit(self): self.declareProperty(Name='InputType',DefaultValue='File',Validator=ListValidator(['File','Workspace']),Description = 'Origin of data input - File (*.nxs) or Workspace') self.declareProperty(Name='Instrument',DefaultValue='iris',Validator=ListValidator(['irs','iris','osi','osiris']),Description = 'Instrument') self.declareProperty(Name='Analyser',DefaultValue='graphite002',Validator=ListValidator(['graphite002','graphite004']),Description = 'Analyser & reflection') self.declareProperty(Name='Program',DefaultValue='QL',Validator=ListValidator(['QL','QSe']),Description = 'Name of program to run') self.declareProperty(Name='SamNumber',DefaultValue='',Validator=MandatoryValidator(),Description = 'Sample run number') self.declareProperty(Name='ResInputType',DefaultValue='File',Validator=ListValidator(['File','Workspace']),Description = 'Origin of res input - File (*_res.nxs) or Workspace') self.declareProperty(Name='ResType',DefaultValue='Res',Validator=ListValidator(['Res','Data']),Description = 'Format of Resolution file') self.declareProperty(Name='ResNumber',DefaultValue='',Validator=MandatoryValidator(),Description = 'Resolution run number') self.declareProperty(Name='BackgroundOption',DefaultValue='Sloping',Validator=ListValidator(['Sloping','Flat','Zero']),Description = 'Form of background to fit') self.declareProperty(Name='ElasticOption',DefaultValue=True,Description = 'Include elastic peak in fit') self.declareProperty(Name='FixWidth',DefaultValue=False,Description = 'Fix one of the widths') self.declareProperty(Name='WidthFile', DefaultValue='',Description = 'Name of file containing fixed width values') self.declareProperty(Name='ResNorm',DefaultValue=False,Description = 'Use ResNorm output file') self.declareProperty(Name='ResNormNumber', DefaultValue='',Description = 'Name of file containing fixed width values') self.declareProperty(Name='EnergyMin', DefaultValue=-0.5,Description = 'Minimum energy for fit. Default=-0.5') self.declareProperty(Name='EnergyMax', DefaultValue=0.5,Description = 'Maximum energy for fit. Default=0.5')
def PyExec(self): from IndirectImport import run_f2py_compatibility_test, is_supported_f2py_platform if is_supported_f2py_platform(): import IndirectBayes as Main run_f2py_compatibility_test() self.log().information('QLines input') inType = self.getPropertyValue('InputType') prefix = self.getPropertyValue('Instrument') ana = self.getPropertyValue('Analyser') prog = self.getPropertyValue('Program') sam = self.getPropertyValue('SamNumber') rinType = self.getPropertyValue('ResInputType') rtype = self.getPropertyValue('ResType') res = self.getPropertyValue('ResNumber') elastic = self.getProperty('ElasticOption').value bgd = self.getPropertyValue('BackgroundOption') width = self.getProperty('FixWidth').value wfile = self.getPropertyValue('WidthFile') rsnormType = self.getPropertyValue('ResNormInputType') resnorm = self.getProperty('ResNorm').value resn = self.getPropertyValue('ResNormNumber') emin = self.getPropertyValue('EnergyMin') emax = self.getPropertyValue('EnergyMax') nbin = self.getPropertyValue('SamBinning') nrbin = self.getPropertyValue('ResBinning') nbins = [nbin, nrbin] if rtype == 'Res': rext = 'res' if rtype == 'Data': rext = 'red' sname = prefix+sam+'_'+ana + '_red' rname = prefix+res+'_'+ana + '_' + rext rsname = prefix+resn+'_'+ana + '_ResNorm_Paras' erange = [float(emin), float(emax)] fitOp = [elastic, bgd, width, resnorm] loopOp = self.getProperty('Sequence').value verbOp = self.getProperty('Verbose').value plotOp = self.getPropertyValue('Plot') saveOp = self.getProperty('Save').value workdir = config['defaultsave.directory'] if inType == 'File': spath = os.path.join(workdir, sname+'.nxs') # path name for sample nxs file LoadNexusProcessed(Filename=spath, OutputWorkspace=sname) Smessage = 'Sample from File : '+spath else: Smessage = 'Sample from Workspace : '+sname if rinType == 'File': rpath = os.path.join(workdir, rname+'.nxs') # path name for res nxs file LoadNexusProcessed(Filename=rpath, OutputWorkspace=rname) Rmessage = 'Resolution from File : '+rpath else: Rmessage = 'Resolution from Workspace : '+rname if resnorm: if rsnormType == 'File': rpath = os.path.join(workdir, rsname+'.nxs') # path name for res nxs file LoadNexusProcessed(Filename=rpath, OutputWorkspace=rsname) Rmessage = 'ResNorm from File : '+rpath else: Rmessage = 'ResNorm from Workspace : '+rsname if verbOp: logger.notice(Smessage) logger.notice(Rmessage) rsname = rsname[:-6] Main.QLRun(prog,sname,rname,rsname,erange,nbins,fitOp,wfile,loopOp,verbOp,plotOp,saveOp)
# # Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI, # NScD Oak Ridge National Laboratory, European Spallation Source, # Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS # SPDX - License - Identifier: GPL - 3.0 + # pylint: disable=invalid-name,too-many-instance-attributes,too-many-branches,no-init from IndirectImport import is_supported_f2py_platform, import_f2py, run_f2py_compatibility_test from mantid.api import (PythonAlgorithm, AlgorithmFactory, MatrixWorkspaceProperty, WorkspaceGroupProperty, Progress) from mantid.kernel import StringListValidator, Direction import mantid.simpleapi as s_api from mantid import config, logger import os import numpy as np if is_supported_f2py_platform(): Que = import_f2py("Quest") class BayesStretch(PythonAlgorithm): _sam_name = None _sam_ws = None _res_name = None _e_min = None _e_max = None _sam_bins = None _elastic = None _background = None _nbet = None _nsig = None _loop = None
def skipTests(self): return not is_supported_f2py_platform()
def PyExec(self): from IndirectImport import run_f2py_compatibility_test, is_supported_f2py_platform if is_supported_f2py_platform(): import IndirectBayes as Main run_f2py_compatibility_test() self.log().information('QLines input') inType = self.getPropertyValue('InputType') prefix = self.getPropertyValue('Instrument') ana = self.getPropertyValue('Analyser') prog = self.getPropertyValue('Program') sam = self.getPropertyValue('SamNumber') rinType = self.getPropertyValue('ResInputType') rtype = self.getPropertyValue('ResType') res = self.getPropertyValue('ResNumber') elastic = self.getProperty('ElasticOption').value bgd = self.getPropertyValue('BackgroundOption') width = self.getProperty('FixWidth').value wfile = self.getPropertyValue('WidthFile') rsnormType = self.getPropertyValue('ResNormInputType') resnorm = self.getProperty('ResNorm').value resn = self.getPropertyValue('ResNormNumber') emin = self.getPropertyValue('EnergyMin') emax = self.getPropertyValue('EnergyMax') nbin = self.getPropertyValue('SamBinning') nrbin = self.getPropertyValue('ResBinning') nbins = [nbin, nrbin] if rtype == 'Res': rext = 'res' if rtype == 'Data': rext = 'red' sname = prefix + sam + '_' + ana + '_red' rname = prefix + res + '_' + ana + '_' + rext rsname = prefix + resn + '_' + ana + '_ResNorm_Paras' erange = [float(emin), float(emax)] fitOp = [elastic, bgd, width, resnorm] loopOp = self.getProperty('Sequence').value verbOp = self.getProperty('Verbose').value plotOp = self.getPropertyValue('Plot') saveOp = self.getProperty('Save').value workdir = config['defaultsave.directory'] if inType == 'File': spath = os.path.join(workdir, sname + '.nxs') # path name for sample nxs file LoadNexusProcessed(Filename=spath, OutputWorkspace=sname) Smessage = 'Sample from File : ' + spath else: Smessage = 'Sample from Workspace : ' + sname if rinType == 'File': rpath = os.path.join(workdir, rname + '.nxs') # path name for res nxs file LoadNexusProcessed(Filename=rpath, OutputWorkspace=rname) Rmessage = 'Resolution from File : ' + rpath else: Rmessage = 'Resolution from Workspace : ' + rname if resnorm: if rsnormType == 'File': rpath = os.path.join(workdir, rsname + '.nxs') # path name for res nxs file LoadNexusProcessed(Filename=rpath, OutputWorkspace=rsname) Rmessage = 'ResNorm from File : ' + rpath else: Rmessage = 'ResNorm from Workspace : ' + rsname if verbOp: logger.notice(Smessage) logger.notice(Rmessage) rsname = rsname[:-6] Main.QLRun(prog, sname, rname, rsname, erange, nbins, fitOp, wfile, loopOp, plotOp, saveOp)