Skip to content
Snippets Groups Projects
Commit 813028c6 authored by Shahroz Ahmed's avatar Shahroz Ahmed
Browse files

fixes all warning on pylint

Refs #13405
parent ebaec559
No related merge requests found
......@@ -2,10 +2,10 @@
from mantid.simpleapi import *
from os.path import join
import CRY_utils
import CRY_load
import CRY_sample
import CRY_vana
import cry_utils
import cry_load
import cry_sample
import cry_vana
# ===========
......@@ -13,57 +13,57 @@ import CRY_vana
# ==========
def focus_all(experimentf, samplelistTexte, scale=0, NoVabs=False, NoSAC=False, Eff=True, Norm=True):
def focus_all(EXPR_FILE, samplelistTexte, scale=0, NoVabs=False, NoSAC=False, Eff=True, Norm=True):
if scale == 0:
scale = float(experimentf.scale)
scale = float(EXPR_FILE.scale)
# === Norm boolean flag used to Optionally correct to a Vana ===
if Norm:
print 'Existing Vana Status:' + experimentf.ExistV
print 'Existing Vana Status:' + EXPR_FILE.ExistV
# SAC/EFF corrections loads the Vana
load_sac_eff(experimentf, NoSAC=NoSAC, Eff=Eff)
if experimentf.ExistV == "load":
for i in experimentf.bankList:
load_sac_eff(EXPR_FILE, NoSAC=NoSAC, Eff=Eff)
if EXPR_FILE.ExistV == "load":
for i in EXPR_FILE.bankList:
spec = i - 1
vanfil = experimentf.CorrVanFile + "-" + str(spec) + ".nxs"
vanfil = EXPR_FILE.CorrVanFile + "-" + str(spec) + ".nxs"
LoadNexusProcessed(Filename=vanfil, OutputWorkspace="Vanadium-" + str(i))
# CORRECT
elif experimentf.ExistV == "no" and experimentf.VGrpfocus == "van":
elif EXPR_FILE.ExistV == "no" and EXPR_FILE.VGrpfocus == "van":
print "was here?"
CRY_vana.create_vana(experimentf, NoAbs=NoVabs)
cry_vana.create_vana(EXPR_FILE, NoAbs=NoVabs)
else:
load_sac_eff(experimentf, NoSAC=True)
load_sac_eff(EXPR_FILE, NoSAC=True)
# === Construct a list of runs, sum of runs
sampleSumLists = CRY_utils.get_sample_list(experimentf.basefile, samplelistTexte, experimentf.RawDir)
sampleSumLists = cry_utils.get_sample_list(EXPR_FILE.basefile, samplelistTexte, EXPR_FILE.RawDir)
# to loop over
isfirst = True
for sample2Add in sampleSumLists:
print '--------------------------'
print ' Start focus here '
print '--------------------------'
print " ---> " + Focus(experimentf, sample2Add, scale, Norm, isfirst, NoAbs=NoVabs)
print " ---> " + Focus(EXPR_FILE, sample2Add, scale, Norm, isfirst, NoAbs=NoVabs)
isfirst = False
#
# changed by WAK 8/3/2011:delete workspaces
if not experimentf.debugMode:
if not EXPR_FILE.debugMode:
mtd.remove("Corr")
mtd.remove("Sample")
for i in experimentf.bankList:
for i in EXPR_FILE.bankList:
mtd.remove("Sample-" + str(i))
for i in experimentf.bankList:
for i in EXPR_FILE.bankList:
mtd.remove("Vanadium-" + str(i))
def load_sac_eff(experimentf, NoSAC=False, Eff=True):
def load_sac_eff(EXPR_FILE, NoSAC=False, Eff=True):
# Loads SAC/Efficiency correction in wkspc "Corr" or sets it to "1"
newCalFile = experimentf.CorrVanDir + '/' + experimentf.GrpFile
experimentf.Path2VanGrpFile = newCalFile
newCalFile = EXPR_FILE.CorrVanDir + '/' + EXPR_FILE.GrpFile
EXPR_FILE.Path2VanGrpFile = newCalFile
if NoSAC:
CreateSingleValuedWorkspace(OutputWorkspace="Corr", DataValue=str(1))
print " => No SAC/Eff applied "
return
else:
# First try to load the vana (this won't crash if no vana run is set)....
(dum, uampstotal) = CRY_sample.get_data_sum(experimentf.VanFile, "Vanadium", experimentf)
(dum, uampstotal) = cry_sample.get_data_sum(EXPR_FILE.VanFile, "Vanadium", EXPR_FILE)
uampstotal = mtd["Vanadium"].getRun().getProtonCharge()
if uampstotal < 1e-6:
print " => Van NOT found : No SAC/eff correction will be applied"
......@@ -72,77 +72,78 @@ def load_sac_eff(experimentf, NoSAC=False, Eff=True):
print ' => Pre-calculate SAC from Vana '
Integration(InputWorkspace="Vanadium", OutputWorkspace="VanadiumSum")
# Modified test equal to Zero the 17/10/2012
MaskDetectorsIf(InputWorkspace="VanadiumSum", InputCalFile=experimentf.Path2GrpFile,
MaskDetectorsIf(InputWorkspace="VanadiumSum", InputCalFile=EXPR_FILE.Path2GrpFile,
OutputCalFile=newCalFile,
Mode="DeselectIf", Operator="LessEqual", Value=10)
if not experimentf.debugMode:
if not EXPR_FILE.debugMode:
mtd.remove("VanadiumSum")
SolidAngle(InputWorkspace="Vanadium", OutputWorkspace="SAC")
CreateSingleValuedWorkspace(OutputWorkspace="Sc", DataValue=str(100))
Multiply(LHSWorkspace="SAC", RHSWorkspace="Sc", OutputWorkspace="Corr")
if not experimentf.debugMode:
if not EXPR_FILE.debugMode:
mtd.remove("SAC")
if Eff:
Divide(LHSWorkspace="Vanadium", RHSWorkspace="Corr", OutputWorkspace="Eff")
print ' => Pre-calculate Efficiency correction from Vana '
ConvertUnits(InputWorkspace="Eff", OutputWorkspace="Eff", Target="Wavelength")
Integration(InputWorkspace="Eff", OutputWorkspace="Eff", \
RangeLower=experimentf.LowerLambda, RangeUpper=experimentf.UpperLambda)
RangeLower=EXPR_FILE.LowerLambda, RangeUpper=EXPR_FILE.UpperLambda)
Multiply(LHSWorkspace="Corr", RHSWorkspace="Eff", OutputWorkspace="Corr")
# if experimentf.instr=="polaris":
# if EXPR_FILE.instr=="polaris":
# CreateSingleValuedWorkspace("Sc", str(10000000))
# else:
CreateSingleValuedWorkspace(OutputWorkspace="Sc", DataValue=str(100000))
Divide(LHSWorkspace="Corr", RHSWorkspace="Sc", OutputWorkspace="Corr")
mtd.remove("Sc")
mtd.remove("Vanadium")
if not experimentf.debugMode:
if not EXPR_FILE.debugMode:
mtd.remove("Eff")
def Focus(experimentf, sampleAdd, scale, Norm, isfirst=False, NoAbs=False):
(outname, uampstotal) = CRY_sample.get_data_sum(sampleAdd, "sample", experimentf)
def Focus(EXPR_FILE, sampleAdd, scale, Norm, isfirst=False, NoAbs=False):
(outname, uampstotal) = cry_sample.get_data_sum(sampleAdd, "sample", EXPR_FILE)
if uampstotal < 1e-6:
return "No usable data, Raw files probably not found: cannot create " + outname + "\n"
newCalFile = join(experimentf.user, experimentf.GrpFile)
newCalFile = join(EXPR_FILE.user, EXPR_FILE.GrpFile)
Integration(InputWorkspace="sample", OutputWorkspace="sampleSum")
MaskDetectorsIf(InputWorkspace="sampleSum", InputCalFile=experimentf.Path2GrpFile, OutputCalFile=newCalFile,
MaskDetectorsIf(InputWorkspace="sampleSum", InputCalFile=EXPR_FILE.Path2GrpFile, OutputCalFile=newCalFile,
Mode="DeselectIf", Operator="Equal", Value=10)
mtd.remove("sampleSum")
experimentf.Path2DatGrpFile = newCalFile
if experimentf.VGrpfocus == "sam" and isfirst:
CRY_vana.create_vana(experimentf, NoAbs)
if experimentf.SEmptyFile[0] != "none":
EXPR_FILE.Path2DatGrpFile = newCalFile
if EXPR_FILE.VGrpfocus == "sam" and isfirst:
cry_vana.create_vana(EXPR_FILE, NoAbs)
if EXPR_FILE.SEmptyFile[0] != "none":
# === Optionally loads Sample Empty ===
# (dum1, uamps) = CRY_sample.get_data_sum(experimentf.SEmptyFile, "Sempty", experimentf)
# (dum1, uamps) = CRY_sample.get_data_sum(EXPR_FILE.SEmptyFile, "Sempty", EXPR_FILE)
Minus(LHSWorkspace="sample", RHSWorkspace="Sempty", OutputWorkspace="sample")
mtd.remove("Sempty")
CRY_load.align_fnc("sample", experimentf)
cry_load.align_fnc("sample", EXPR_FILE)
Divide(LHSWorkspace="sample", RHSWorkspace="Corr", OutputWorkspace="sample")
CRY_load.scale_wspc("sample", scale)
if experimentf.CorrectSampleAbs == "yes":
if experimentf.SampleAbsCorrected == False:
CRY_utils.correct_abs(InputWkspc="sample", outputWkspc="SampleTrans", \
TheCylinderSampleHeight=experimentf.SampleHeight, \
TheCylinderSampleRadius=experimentf.SampleRadius, \
TheAttenuationXSection=experimentf.SampleAttenuationXSection, \
TheScatteringXSection=experimentf.SampleScatteringXSection, \
TheSampleNumberDensity=experimentf.SampleNumberDensity, \
TheNumberOfSlices=experimentf.SampleNumberOfSlices, \
TheNumberOfAnnuli=experimentf.SampleNumberOfAnnuli, \
TheNumberOfWavelengthPoints=experimentf.SampleNumberOfWavelengthPoints, \
TheExpMethod=experimentf.SampleExpMethod)
experimentf.SampleAbsCorrected = True
cry_load.scale_wspc("sample", scale)
if EXPR_FILE.CorrectSampleAbs == "yes":
if EXPR_FILE.SampleAbsCorrected == False:
cry_utils.correct_abs(InputWkspc="sample", outputWkspc="SampleTrans", \
TheCylinderSampleHeight=EXPR_FILE.SampleHeight, \
TheCylinderSampleRadius=EXPR_FILE.SampleRadius, \
TheAttenuationXSection=EXPR_FILE.SampleAttenuationXSection, \
TheScatteringXSection=EXPR_FILE.SampleScatteringXSection, \
TheSampleNumberDensity=EXPR_FILE.SampleNumberDensity, \
TheNumberOfSlices=EXPR_FILE.SampleNumberOfSlices, \
TheNumberOfAnnuli=EXPR_FILE.SampleNumberOfAnnuli, \
TheNumberOfWavelengthPoints=EXPR_FILE.SampleNumberOfWavelengthPoints, \
TheExpMethod=EXPR_FILE.SampleExpMethod)
EXPR_FILE.SampleAbsCorrected = True
else:
ConvertUnits(InputWorkspace="sample", OutputWorkspace="sample", Target="Wavelength")
Divide(LHSWorkspace="sample", RHSWorkspace="SampleTrans", OutputWorkspace="sample")
ConvertUnits(InputWorkspace="sample", OutputWorkspace="sample", Target="dSpacing")
DiffractionFocussing(InputWorkspace="sample", OutputWorkspace="sample", GroupingFileName=experimentf.Path2DatGrpFile,
DiffractionFocussing(InputWorkspace="sample", OutputWorkspace="sample",
GroupingFileName=EXPR_FILE.Path2DatGrpFile,
PreserveEvents=False)
divide_samp_vana(experimentf, Norm)
divide_samp_vana(EXPR_FILE, Norm)
# === Cleans results in D and TOF before outputing bank by bank ===
CRY_load.bin_bank("ResultD", experimentf.bankList, experimentf.Drange)
for i in experimentf.bankList:
cry_load.bin_bank("ResultD", EXPR_FILE.bankList, EXPR_FILE.Drange)
for i in EXPR_FILE.bankList:
ConvertUnits(InputWorkspace="ResultD-" + str(i), OutputWorkspace="ResultTOF-" + str(i), Target="TOF")
ReplaceSpecialValues(InputWorkspace="ResultD-" + str(i), OutputWorkspace="ResultD-" + str(i), NaNValue="0",
InfinityValue="0", BigNumberThreshold="99999999.99999999")
......@@ -150,49 +151,49 @@ def Focus(experimentf, sampleAdd, scale, Norm, isfirst=False, NoAbs=False):
InfinityValue="0", BigNumberThreshold="99999999.99999999")
# === Output===
# GSS
GrpList = "ResultTOF-" + str(experimentf.bankList[0])
if len(experimentf.bankList[1:]) > 1:
for i in experimentf.bankList[1:]:
GrpList = "ResultTOF-" + str(EXPR_FILE.bankList[0])
if len(EXPR_FILE.bankList[1:]) > 1:
for i in EXPR_FILE.bankList[1:]:
GrpList = GrpList + ",ResultTOF-" + str(i)
GroupWorkspaces(OutputWorkspace="ResultTOFgrp", InputWorkspaces=GrpList)
if experimentf.OutSuf == "":
OutputFile = join(experimentf.user, outname)
if EXPR_FILE.OutSuf == "":
OutputFile = join(EXPR_FILE.user, outname)
else:
OutputFile = join(experimentf.user, outname + "_" + experimentf.OutSuf)
OutputFile = join(EXPR_FILE.user, outname + "_" + EXPR_FILE.OutSuf)
# Gss
rearrang4gss(OutputFile, experimentf)
rearrang4gss(OutputFile, EXPR_FILE)
# Nexus
rearrange_4nex(OutputFile, experimentf)
rearrange_4nex(OutputFile, EXPR_FILE)
# XYE
OutputFile = OutputFile + "_"
rearrange_4xye(OutputFile, experimentf, units="TOF")
rearrange_4xye(OutputFile, experimentf, units="D")
rearrange_4xye(OutputFile, EXPR_FILE, units="TOF")
rearrange_4xye(OutputFile, EXPR_FILE, units="D")
return outname + " focused with uampstotal=" + str(uampstotal)
def divide_samp_vana(experimentf, Norm):
def divide_samp_vana(EXPR_FILE, Norm):
print " => SAMPLE FOCUSED"
if not experimentf.dataRangeSet:
CRY_load.sets_drange("sample", experimentf)
CRY_load.split_bank("sample", experimentf.bankList, Del=False)
if not EXPR_FILE.dataRangeSet:
cry_load.sets_drange("sample", EXPR_FILE)
cry_load.split_bank("sample", EXPR_FILE.bankList, Del=False)
if Norm:
# === Optional normalization ===
for i in experimentf.bankList:
for i in EXPR_FILE.bankList:
RebinToWorkspace(WorkspaceToRebin="Vanadium-" + str(i), WorkspaceToMatch="sample-" + str(i),
OutputWorkspace="Vanadium-" + str(i))
Divide(LHSWorkspace="sample-" + str(i), RHSWorkspace="Vanadium-" + str(i),
OutputWorkspace="ResultD-" + str(i))
else:
for i in experimentf.bankList:
for i in EXPR_FILE.bankList:
RenameWorkspace(InputWorkspace="sample-" + str(i), OutputWorkspace="ResultD-" + str(i))
# ===========
# Output in XYE, GSS...
# ==========
def rearrange_4xye(OutputFile, experimentf, units="TOF"):
if (units == "D" and experimentf.saveXYEd) or (units == "TOF" and experimentf.saveXYEtof):
for i in experimentf.bankList:
def rearrange_4xye(OutputFile, EXPR_FILE, units="TOF"):
if (units == "D" and EXPR_FILE.saveXYEd) or (units == "TOF" and EXPR_FILE.saveXYEtof):
for i in EXPR_FILE.bankList:
inwkpsc = "Result" + units + "-" + str(i)
SaveFocusedXYE(InputWorkspace=inwkpsc, Filename=OutputFile + "b" + str(i) + "_" + units + ".dat",
SplitFiles=False, IncludeHeader=False)
......@@ -200,10 +201,10 @@ def rearrange_4xye(OutputFile, experimentf, units="TOF"):
# SaveFocusedXYE(InputWorkspace=inwkpsc, Filename=OutputFile+"b"+str(i)+"_"+units+".dat", SplitFiles=False)
def rearrang4gss(OutputFile, experimentf):
if experimentf.GSS == "no":
def rearrang4gss(OutputFile, EXPR_FILE):
if EXPR_FILE.GSS == "no":
return
if len(experimentf.bankList[1:]) > 1:
if len(EXPR_FILE.bankList[1:]) > 1:
SaveGSS(InputWorkspace="ResultTOFgrp", Filename=OutputFile + ".gss", SplitFiles=False, Append=False)
else:
SaveGSS(InputWorkspace="ResultTOF-1", Filename=OutputFile + ".gss", SplitFiles=False, Append=False)
......@@ -211,8 +212,8 @@ def rearrang4gss(OutputFile, experimentf):
# changed by WAK 3/3/2011 following Martyn Gigg's advice on group save
def rearrange_4nex(OutputFile, experimentf):
if experimentf.Nex == "no":
def rearrange_4nex(OutputFile, EXPR_FILE):
if EXPR_FILE.Nex == "no":
return
SaveNexusProcessed(Filename=OutputFile + ".nxs", InputWorkspace="ResultTOFgrp")
......
#pylint: disable=attribute-defined-outside-init,undefined-loop-variable,too-many-arguments,too-many-branches
#pylint: disable=attribute-defined-outside-init,undefined-loop-variable,too-many-arguments,too-many-branches,too-many-instance-attributes,old-style-class,global-variable-not-assigned
from mantid.simpleapi import *
import CRY_utils
import cry_utils
import re
import os.path
from os.path import abspath, join, dirname
env_analysis_dir = ''
ANALYSIS_DIR = ''
#print '--------------------- '
#print 'Using the B:\\MantidPowderFocus\\\scripts2\\CRY_ini.py scripts... '
#print '--------------------- '
......@@ -14,7 +14,7 @@ env_analysis_dir = ''
class Files:
def __init__(self, instr, RawDir="", Analysisdir="", UnitTest=False, debugMode=False):
global env_analysis_dir
global ANALYSIS_DIR
self.debugMode = False
if debugMode:
self.debugMode = True
......@@ -91,7 +91,7 @@ class Files:
if Analysisdir != "":
self.Analysisdir = abspath(Analysisdir)
else:
self.Analysisdir = abspath(env_analysis_dir)
self.Analysisdir = abspath(ANALYSIS_DIR)
self.OffDir = join(self.Analysisdir, "GrpOff")
self.GrpDir = join(self.Analysisdir, "GrpOff")
......@@ -221,7 +221,7 @@ class Files:
self.dataRangeSet = False
if self.saveXYEtof or self.saveXYEd:
bankList = self.read_prefline("BankList")
self.bankList = CRY_utils.get_list_int(bankList)
self.bankList = cry_utils.get_list_int(bankList)
print "Done"
if Verbose:
self.tell()
......@@ -307,11 +307,11 @@ class Files:
self.SEmptyDir = self.RawDir
def updateCalib(self):
self.VanFile = CRY_utils.list_of_list2_list(CRY_utils.get_sample_list(self.basefile, self.VrunnoList, self.VanDir))
self.VEmptyFile = CRY_utils.list_of_list2_list(
CRY_utils.get_sample_list(self.basefile, self.VErunnoList, self.VEmptyDir))
self.SEmptyFile = CRY_utils.list_of_list2_list(
CRY_utils.get_sample_list(self.basefile, self.SErunnoList, self.SEmptyDir))
self.VanFile = cry_utils.list_of_list2_list(cry_utils.get_sample_list(self.basefile, self.VrunnoList, self.VanDir))
self.VEmptyFile = cry_utils.list_of_list2_list(
cry_utils.get_sample_list(self.basefile, self.VErunnoList, self.VEmptyDir))
self.SEmptyFile = cry_utils.list_of_list2_list(
cry_utils.get_sample_list(self.basefile, self.SErunnoList, self.SEmptyDir))
self.Path2OffFile = self.OffDir + "/" + self.OffFile
self.Path2GrpFile = self.GrpDir + "/" + self.GrpFile
self.CorrVanFile = self.CorrVanDir + "/" + self.CorrVanFile
......@@ -450,8 +450,8 @@ class Files:
if __name__ == '__main__':
# Opt : experimentf=Files("hrpd",RawDir="",Analysisdir="")
experimentf = Files("hrpd")
# Opt : EXPR_FILE=Files("hrpd",RawDir="",Analysisdir="")
EXPR_FILE = Files("hrpd")
# default
experimentf.initialize('Cycle08_2', 'Si')
# Opt : experimentf.initialize('Cycle09_2','tests',prefFile='mtd.pref', prefDir="")
EXPR_FILE.initialize('Cycle08_2', 'Si')
# Opt : EXPR_FILE.initialize('Cycle09_2','tests',prefFile='mtd.pref', prefDir="")
#pylint: disable=unused-variable
from mantid.simpleapi import *
from getcycle import *
import time
......
......@@ -2,12 +2,12 @@ from mantid.simpleapi import *
from types import *
import math
old_version = False
OLD_VERSION = False
# First a function definition for the Loading algorithms which
# loads the data and immediately aligns the detectors
def load(outputArea, pathtofile, experimentf, add=False):
def load(outputArea, pathtofile, EXPR_FILE, add=False):
total = outputArea
if add:
outputArea = outputArea + "add"
......@@ -18,11 +18,11 @@ def load(outputArea, pathtofile, experimentf, add=False):
# raise
# else:
# fin.close()
if old_version:
if OLD_VERSION:
LoadRaw(Filename=pathtofile, OutputWorkspace=outputArea)
else:
LoadRaw(Filename=pathtofile, OutputWorkspace=outputArea, LoadLogFiles=False)
if experimentf.instr == "hrpd":
if EXPR_FILE.instr == "hrpd":
removeallpromptpulses(outputArea)
uamps = mtd[outputArea].getRun().getProtonCharge()
if add:
......@@ -33,8 +33,8 @@ def load(outputArea, pathtofile, experimentf, add=False):
return uamps, uampstot
def align_fnc(outputArea, experimentf):
AlignDetectors(InputWorkspace=outputArea, OutputWorkspace=outputArea, CalibrationFile=experimentf.Path2OffFile)
def align_fnc(outputArea, EXPR_FILE):
AlignDetectors(InputWorkspace=outputArea, OutputWorkspace=outputArea, CalibrationFile=EXPR_FILE.Path2OffFile)
def split_bank(InputArea, bankList, Del=True):
......@@ -50,23 +50,23 @@ def bin_bank(InputArea, bankList, Drange):
Rebin(InputWorkspace=InputArea + "-" + str(i), OutputWorkspace=InputArea + "-" + str(i), Params=Drange[i - 1])
def sets_drange(wkspc, experimentf):
def sets_drange(wkspc, EXPR_FILE):
datamatrix = mtd[wkspc]
for i in range(0, experimentf.Nbank):
for i in range(0, EXPR_FILE.Nbank):
x_data = datamatrix.readX(i)
last = len(x_data) - 1
CropRange = experimentf.CropRange[i].rstrip().split()
CropRange = EXPR_FILE.CropRange[i].rstrip().split()
xbegin = str(x_data[0] * (1 + float(CropRange[0])))
xend = str(x_data[last] * float(CropRange[1]))
datbin = math.exp(math.log(x_data[last] / x_data[0]) / last) - 1
if datbin > float(experimentf.Bining[i]):
print 'WARNING: Rebining in *pref file ' + experimentf.Bining[
if datbin > float(EXPR_FILE.Bining[i]):
print 'WARNING: Rebining in *pref file ' + EXPR_FILE.Bining[
i] + ' is lower than diffraction focusing rebining step'
print 'WARNING: Rebining Kept to be ' + str(datbin) + ' for bank ' + str(i + 1)
experimentf.Bining[i] = str(datbin)
Drange = xbegin + ",-" + experimentf.Bining[i] + "," + xend
experimentf.Drange.append(Drange)
experimentf.dataRangeSet = True
EXPR_FILE.Bining[i] = str(datbin)
Drange = xbegin + ",-" + EXPR_FILE.Bining[i] + "," + xend
EXPR_FILE.Drange.append(Drange)
EXPR_FILE.dataRangeSet = True
return sets_drange
......
......@@ -3,11 +3,10 @@
import re
from mantid.simpleapi import *
import CRY_load
import CRY_ini
import cry_load
def get_data_sum(sampleAdd, samLab, experimentf):
def get_data_sum(sampleAdd, samLab, EXPR_FILE):
# Adds a list of data files given as a list of filenames
# into the workspace samLab. Zero uamps runs are skipped
# Function returns (BasenameRunno,uampstot) the first non-Zero run
......@@ -17,9 +16,9 @@ def get_data_sum(sampleAdd, samLab, experimentf):
if SampleFn == "none":
return ('', 0)
if firstnonzeronotfound: # load first run
uamps, uampstot = CRY_load.load(samLab, SampleFn, experimentf, add=False)
uamps, uampstot = cry_load.load(samLab, SampleFn, EXPR_FILE, add=False)
else: # Or add a new run
uamps, uampstot = CRY_load.load(samLab, SampleFn, experimentf, add=True)
uamps, uampstot = cry_load.load(samLab, SampleFn, EXPR_FILE, add=True)
if uamps > 1e-6:
uampstotal = uampstotal + uamps
print "'w' uamps = " + str(uampstot) + 'Data uamps =' + str(uamps) + 'Manually computed sum=' + str(
......@@ -27,14 +26,14 @@ def get_data_sum(sampleAdd, samLab, experimentf):
if firstnonzeronotfound:
# Gets BasenameRunno from SampleFn using RegEx
# try to find it as path\BasenameRunno.raw
pseaerch = ".*(" + experimentf.basefile + "[0-9]+)\.raw"
pseaerch = ".*(" + EXPR_FILE.basefile + "[0-9]+)\.raw"
p_wrd = re.compile(pseaerch)
m_wrd = p_wrd.match(SampleFn)
if m_wrd is not None:
sampleout = m_wrd.group(1)
else:
# else... try to it find as path\BasenameRunno.s*
pseaerch = ".*(" + experimentf.basefile + "[0-9]+)\.s([0-9]+)"
pseaerch = ".*(" + EXPR_FILE.basefile + "[0-9]+)\.s([0-9]+)"
p_wrd = re.compile(pseaerch)
m_wrd = p_wrd.match(SampleFn)
sampleout = m_wrd.group(1) + "_" + m_wrd.group(2)
......@@ -52,9 +51,9 @@ def get_data_sum(sampleAdd, samLab, experimentf):
if __name__ == '__main__':
experimentf = CRY_ini.File("hrpd")
experimentf.initialize('Cycle09_2', 'tests', prefFile="mtd_tst.pref")
experimentf.tell()
EXPR_FILE = CRY_ini.File("hrpd")
EXPR_FILE.initialize('Cycle09_2', 'tests', prefFile="mtd_tst.pref")
EXPR_FILE.tell()
# CorrectVana(VanFile,EmptyFile,AcalibFile,1)
# normalizeall(SampleDatFile,AcalibFile)
# rearrangeallbanks(OutputFile,"")
......@@ -2,23 +2,22 @@
from mantid.simpleapi import *
import os.path
import CRY_ini
import CRY_load
import cry_load
numbankdic = { \
NUM_BANK_DIC = { \
'hrp': 3, \
'gem': 5, \
'pol': 6 \
}
grpofdic = { \
GRP_OF_DIC = { \
'hrp': 'hrpd_new_072_01_corr.cal'
}
def rawpath(runno, inst='hrp', Verbose=False):
file = open('//filepath.isis.rl.ac.uk/' + inst + str(runno) + '.raw/windir.txt', 'r')
line = os.path.abspath(file.readline())
ofile = open('//filepath.isis.rl.ac.uk/' + inst + str(runno) + '.raw/windir.txt', 'r')
line = os.path.abspath(ofile.readline())
if Verbose:
print '//filepath.isis.rl.ac.uk/' + inst + str(runno) + '.raw/windir.txt'
print line
......@@ -29,9 +28,9 @@ class Instrument:
def __init__(self, instr):
self.name = instr
self.sname = instr[0:3]
self.nbank = numbankdic[self.sname]
self.nbank = NUM_BANK_DIC[self.sname]
self.pc_comp = 'Y:'
self.grpOfffile = CRY_ini.env_analysis_dir + '/GrpOff/' + grpofdic[self.sname]
self.grpOfffile = CRY_ini.ANALYSIS_DIR + '/GrpOff/' + GRP_OF_DIC[self.sname]
class Focus(Instrument):
......@@ -79,16 +78,16 @@ class Focus(Instrument):
DiffractionFocussing(InputWorkspace=wkspname, OutputWorkspace=wkspname,
GroupingFileName=self.Instr.grpOfffile)
blist = range(1, self.Instr.nbank + 1)
CRY_load.split_bank(wkspname, blist, Del=True)
cry_load.split_bank(wkspname, blist, Del=True)
if __name__ == '__main__':
from SET_env_scripts2_migrated import *
afocus = Focus()
A_FOCUS = Focus()
# a_focus.savemode_on()
# a_focus.load('TEST|//isis/inst$/ndxhrpd/instrument/data/cycle_11_5/hrp51683.raw', path=True)
print rawpath(35493, inst='gem', Verbose=False)
# a_focus.load('TEST|//isis/inst$/ndxhrpd/instrument/data/cycle_11_5/hrp51683.raw', path=True)
afocus.load(35493)
A_FOCUS.load(35493)
#pylint: disable=redefined-outer-name
#pylint: disable=redefined-outer-name,unused-argument,anomalous-backslash-in-string,too-many-arguments
from mantid.simpleapi import *
from types import *
import re
def get_sample_list(basefile, listText, direct=""):
raw = True
thedir = ""
......@@ -140,8 +139,8 @@ def correct_abs(InputWkspc, outputWkspc, TheCylinderSampleHeight, TheCylinderSam
if __name__ == '__main__':
# AList=git_list("1-3 15-150-10 42-44")
list = git_list("44429+44453")
print list
print get_sample_list(experimentf.basefile, "1000 1245-1268 1308-1400-10", direct=experimentf.RawDir)
print get_sample_list(experimentf.basefile, "s41256 1-5 10 15-30-3", direct=experimentf.RawDir)
G_LIST = git_list("44429+44453")
print G_LIST
print get_sample_list(EXPR_FILE.basefile, "1000 1245-1268 1308-1400-10", direct=EXPR_FILE.RawDir)
print get_sample_list(EXPR_FILE.basefile, "s41256 1-5 10 15-30-3", direct=EXPR_FILE.RawDir)
# print get_list_int("1-3 15-150 42-44")
#pylint: disable=unused-variable
from mantid.simpleapi import *
import CRY_utils
import CRY_sample
import CRY_load
import cry_utils
import cry_sample
import cry_load
def create_vana(experimentf, NoAbs=False):
def create_vana(EXPR_FILE, NoAbs=False):
# ==== Vana loading
(dum, uampstotal) = CRY_sample.get_data_sum(experimentf.VanFile, "Vanadium", experimentf)
(dum, uampstotal) = cry_sample.get_data_sum(EXPR_FILE.VanFile, "Vanadium", EXPR_FILE)
# Subtract the empty instrument ===
(dum, uampstotal) = CRY_sample.get_data_sum(experimentf.VEmptyFile, "Empty", experimentf)
(dum, uampstotal) = cry_sample.get_data_sum(EXPR_FILE.VEmptyFile, "Empty", EXPR_FILE)
if uampstotal > 1e-6:
print " => Substract the Empty to the Vana"
Minus(LHSWorkspace="Vanadium", RHSWorkspace="Empty", OutputWorkspace="Vanadium_align")
mtd.remove("Empty")
CRY_load.align_fnc("Vanadium_align", experimentf)
cry_load.align_fnc("Vanadium_align", EXPR_FILE)
Divide(LHSWorkspace="Vanadium_align", RHSWorkspace="Corr", OutputWorkspace="Vanadium_corr")
if not NoAbs:
print " => Van Absortption correction"
CRY_utils.correct_abs(InputWkspc="Vanadium_corr", outputWkspc="Transmission", \
TheCylinderSampleHeight=experimentf.VHeight, \
TheCylinderSampleRadius=experimentf.VRadius, \
TheAttenuationXSection=experimentf.VAttenuationXSection, \
TheScatteringXSection=experimentf.VScatteringXSection, \
TheSampleNumberDensity=experimentf.VanaNumberDensity, \
TheNumberOfSlices=experimentf.VNumberOfSlices, \
TheNumberOfAnnuli=experimentf.VNumberOfAnnuli, \
TheNumberOfWavelengthPoints=experimentf.VNumberOfWavelengthPoints, \
TheExpMethod=experimentf.VExpMethod)
cry_utils.correct_abs(InputWkspc="Vanadium_corr", outputWkspc="Transmission", \
TheCylinderSampleHeight=EXPR_FILE.VHeight, \
TheCylinderSampleRadius=EXPR_FILE.VRadius, \
TheAttenuationXSection=EXPR_FILE.VAttenuationXSection, \
TheScatteringXSection=EXPR_FILE.VScatteringXSection, \
TheSampleNumberDensity=EXPR_FILE.VanaNumberDensity, \
TheNumberOfSlices=EXPR_FILE.VNumberOfSlices, \
TheNumberOfAnnuli=EXPR_FILE.VNumberOfAnnuli, \
TheNumberOfWavelengthPoints=EXPR_FILE.VNumberOfWavelengthPoints, \
TheExpMethod=EXPR_FILE.VExpMethod)
# --- Alternative way
# ConvertUnits(InputWorkspace="Vanadium", OutputWorkspace="Vanadium", Target="Wavelength")
# CylinderAbsorption(InputWorkspace="Vanadium", OutputWorkspace="Vanadium",
# CylinderSampleHeight= experimentf.VHeight,
# CylinderSampleRadius= experimentf.VRadius,
# AttenuationXSection= experimentf.VAttenuationXSection,
# ScatteringXSection= experimentf.VScatteringXSection,
# SampleNumberDensity= experimentf.VanaNumberDensity,
# NumberOfSlices = experimentf.VNumberOfSlices,
# NumberOfAnnuli= experimentf.VNumberOfAnnuli,
# NumberOfWavelengthPoints = experimentf.VNumberOfWavelengthPoints,
# ExpMethod= experimentf.VExpMethod )
# CylinderSampleHeight= EXPR_FILE.VHeight,
# CylinderSampleRadius= EXPR_FILE.VRadius,
# AttenuationXSection= EXPR_FILE.VAttenuationXSection,
# ScatteringXSection= EXPR_FILE.VScatteringXSection,
# SampleNumberDensity= EXPR_FILE.VanaNumberDensity,
# NumberOfSlices = EXPR_FILE.VNumberOfSlices,
# NumberOfAnnuli= EXPR_FILE.VNumberOfAnnuli,
# NumberOfWavelengthPoints = EXPR_FILE.VNumberOfWavelengthPoints,
# ExpMethod= EXPR_FILE.VExpMethod )
# ConvertUnits(InputWorkspace="Vanadium", OutputWorkspace="Vanadium", Target="dSpacing")
# (dum,uampstotal)=CRY_sample.get_data_sum(experimentf.VanFile,"Vanadium2",experimentf)
# (dum,uampstotal)=CRY_sample.get_data_sum(EXPR_FILE.VanFile,"Vanadium2",EXPR_FILE)
# Divide("Vanadium2", "Vanadium", "Vanadium")
##ConvertUnits(InputWorkspace=InputWkspc, OutputWorkspace=InputWkspc, Target="dSpacing")
# mtd.remove("Vanadium2")
##
print " => Focus type : " + experimentf.VGrpfocus
if experimentf.VGrpfocus == "sam":
GrpFile = experimentf.Path2DatGrpFile
print " => Focus type : " + EXPR_FILE.VGrpfocus
if EXPR_FILE.VGrpfocus == "sam":
GrpFile = EXPR_FILE.Path2DatGrpFile
else:
GrpFile = experimentf.Path2VanGrpFile
GrpFile = EXPR_FILE.Path2VanGrpFile
print " => Van Focused with the Cal file :" + GrpFile
DiffractionFocussing(InputWorkspace="Vanadium_corr", OutputWorkspace="Vanadium_foc", GroupingFileName=GrpFile,
PreserveEvents=False)
print " => VANADIUM FOCUSED"
ReplaceSpecialValues(InputWorkspace="Vanadium_foc", OutputWorkspace="Vanadium", NaNValue="0", InfinityValue="0",
BigNumberThreshold="99999999.99999999")
SaveNexusProcessed(Filename=experimentf.CorrVanFile + "_unstripped.nxs", InputWorkspace="Vanadium")
SaveFocusedXYE(Filename=experimentf.CorrVanFile + "_unstripped.dat", InputWorkspace="Vanadium", SplitFiles=True)
strip_the_vana(experimentf)
if experimentf.ExistV == 'no' and experimentf.VGrpfocus == 'van':
experimentf.write_prefline("ExistingV", "yes")
experimentf.ExistV = "yes"
if not experimentf.debugMode:
SaveNexusProcessed(Filename=EXPR_FILE.CorrVanFile + "_unstripped.nxs", InputWorkspace="Vanadium")
SaveFocusedXYE(Filename=EXPR_FILE.CorrVanFile + "_unstripped.dat", InputWorkspace="Vanadium", SplitFiles=True)
strip_the_vana(EXPR_FILE)
if EXPR_FILE.ExistV == 'no' and EXPR_FILE.VGrpfocus == 'van':
EXPR_FILE.write_prefline("ExistingV", "yes")
EXPR_FILE.ExistV = "yes"
if not EXPR_FILE.debugMode:
mtd.remove("Vanadium_foc")
mtd.remove("Transmission")
mtd.remove("Vanadium_corr")
......@@ -70,77 +72,77 @@ def create_vana(experimentf, NoAbs=False):
return False
def strip_the_vana(experimentf, LoadUnstrip=""):
def strip_the_vana(EXPR_FILE, LoadUnstrip=""):
if not LoadUnstrip:
LoadNexusProcessed(Filename=LoadUnstrip, OutputWorkspace="Vanadium", EntryNumber=1)
print experimentf.bankList
CRY_load.split_bank("Vanadium", bankList=experimentf.bankList, Del=True)
if experimentf.VanPeakRemove == "interpol":
print EXPR_FILE.bankList
cry_load.split_bank("Vanadium", bankList=EXPR_FILE.bankList, Del=True)
if EXPR_FILE.VanPeakRemove == "interpol":
print " => Van Bragg-peak stripping"
print "Smmoth Vana data with " + experimentf.VanSmooth + " points"
remove_bins(experimentf)
elif experimentf.VanPeakRemove == "strip":
print "Smmoth Vana data with " + EXPR_FILE.VanSmooth + " points"
remove_bins(EXPR_FILE)
elif EXPR_FILE.VanPeakRemove == "strip":
print " => Van Bragg-peak stripping"
van_strip(experimentf)
elif experimentf.VanPeakRemove == "spline":
van_spline(experimentf)
elif experimentf.VanPeakRemove == "splineonly":
van_spline_only(experimentf)
van_strip(EXPR_FILE)
elif EXPR_FILE.VanPeakRemove == "spline":
van_spline(EXPR_FILE)
elif EXPR_FILE.VanPeakRemove == "splineonly":
van_spline_only(EXPR_FILE)
else:
return
save_vana(experimentf)
save_vana(EXPR_FILE)
def save_vana(experimentf):
for i in experimentf.bankList:
def save_vana(EXPR_FILE):
for i in EXPR_FILE.bankList:
spec = i - 1
vanfil = experimentf.CorrVanFile + "-" + str(spec) + ".nxs"
vanfil = EXPR_FILE.CorrVanFile + "-" + str(spec) + ".nxs"
SaveNexusProcessed(Filename=vanfil, InputWorkspace="Vanadium-" + str(i))
def remove_bins(experimentf):
for i in experimentf.bankList:
def remove_bins(EXPR_FILE):
for i in EXPR_FILE.bankList:
spec = i - 1
SmoothData(InputWorkspace="Vanadium-" + str(i), OutputWorkspace="Vanadium-" + str(i),
NPoints=int(experimentf.VanSmooth))
NPoints=int(EXPR_FILE.VanSmooth))
print "Strip Vanapeak in bank=" + str(i)
for peak in experimentf.VanPeakList[spec]:
for peak in EXPR_FILE.VanPeakList[spec]:
RemoveBins(InputWorkspace="Vanadium-" + str(i), OutputWorkspace="Vanadium-" + str(i), XMin=peak[0],
XMax=peak[1], RangeUnit="AsInput", Interpolation="Linear", WorkspaceIndex=0)
SaveFocusedXYE(Filename=experimentf.CorrVanFile + "-" + str(spec) + "_.dat", InputWorkspace="Vanadium-" + str(i),
SaveFocusedXYE(Filename=EXPR_FILE.CorrVanFile + "-" + str(spec) + "_.dat", InputWorkspace="Vanadium-" + str(i),
SplitFiles=False)
def van_strip(experimentf):
for i in experimentf.bankList:
def van_strip(EXPR_FILE):
for i in EXPR_FILE.bankList:
spec = i - 1
if experimentf.VanPeakWdt[spec] != 0:
if EXPR_FILE.VanPeakWdt[spec] != 0:
print "Strip Vanapeaks with params : bank=" + str(i) + " FWHM=" + str(
experimentf.VanPeakWdt[spec]) + " Tol=" + str(experimentf.VanPeakTol[spec])
EXPR_FILE.VanPeakWdt[spec]) + " Tol=" + str(EXPR_FILE.VanPeakTol[spec])
StripPeaks(InputWorkspace="Vanadium-" + str(i), OutputWorkspace="Vanadium-" + str(i),
FWHM=experimentf.VanPeakWdt[spec], Tolerance=experimentf.VanPeakTol[spec], WorkspaceIndex=0)
SaveFocusedXYE(Filename=experimentf.CorrVanFile + "-" + str(spec) + "_.dat", InputWorkspace="Vanadium-" + str(i),
FWHM=EXPR_FILE.VanPeakWdt[spec], Tolerance=EXPR_FILE.VanPeakTol[spec], WorkspaceIndex=0)
SaveFocusedXYE(Filename=EXPR_FILE.CorrVanFile + "-" + str(spec) + "_.dat", InputWorkspace="Vanadium-" + str(i),
SplitFiles=False)
def van_spline(experimentf):
for i in experimentf.bankList:
def van_spline(EXPR_FILE):
for i in EXPR_FILE.bankList:
spec = i - 1
print "Strip Vanapeak in bank=" + str(i)
for peak in experimentf.VanPeakList[spec]:
for peak in EXPR_FILE.VanPeakList[spec]:
MaskBins(InputWorkspace="Vanadium-" + str(i), OutputWorkspace="Vanadium-" + str(i), XMin=peak[0],
XMax=peak[1])
SplineBackground(InputWorkspace="Vanadium-" + str(i), OutputWorkspace="Vanadium-" + str(i), WorkspaceIndex=0,
NCoeff=int(experimentf.VanSplineCoef))
SaveFocusedXYE(Filename=experimentf.CorrVanFile + "-" + str(spec) + "_.dat", InputWorkspace="Vanadium-" + str(i),
NCoeff=int(EXPR_FILE.VanSplineCoef))
SaveFocusedXYE(Filename=EXPR_FILE.CorrVanFile + "-" + str(spec) + "_.dat", InputWorkspace="Vanadium-" + str(i),
SplitFiles=False)
def van_spline_only(experimentf):
for i in experimentf.bankList:
def van_spline_only(EXPR_FILE):
for i in EXPR_FILE.bankList:
spec = i - 1
SplineBackground(InputWorkspace="Vanadium-" + str(i), OutputWorkspace="Vanadium-" + str(i), WorkspaceIndex=0,
NCoeff=int(experimentf.VanSplineCoef))
SaveFocusedXYE(Filename=experimentf.CorrVanFile + "-" + str(spec) + "_.dat", InputWorkspace="Vanadium-" + str(i),
NCoeff=int(EXPR_FILE.VanSplineCoef))
SaveFocusedXYE(Filename=EXPR_FILE.CorrVanFile + "-" + str(spec) + "_.dat", InputWorkspace="Vanadium-" + str(i),
SplitFiles=False)
......@@ -3,8 +3,8 @@ import os.path
def rawpath(runno, inst='hrp', Verbose=False):
file = open('//filepath.isis.rl.ac.uk/' + inst + str(runno) + '.raw/windir.txt', 'r')
line = os.path.abspath(file.readline()) + '\\' + inst + str(runno) + '.raw'
ofile = open('//filepath.isis.rl.ac.uk/' + inst + str(runno) + '.raw/windir.txt', 'r')
line = os.path.abspath(ofile.readline()) + '\\' + inst + str(runno) + '.raw'
if Verbose:
print '//filepath.isis.rl.ac.uk/' + inst + str(runno) + '.raw/windir.txt'
print line
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment