Skip to content

Commit

Permalink
Revised UI. Refs #6555.
Browse files Browse the repository at this point in the history
  • Loading branch information
wdzhou committed Feb 27, 2013
1 parent 9f76df7 commit efed4f9
Show file tree
Hide file tree
Showing 9 changed files with 1,057 additions and 771 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,24 @@ def PyInit(self):
self.declareProperty("PushDataPositive", "None",
StringListValidator(["None", "ResetToZero", "AddMinimum"]),
"Add a constant to the data that makes it positive over the whole range.")
self.declareProperty("BackgroundNumber", defaultValue=0, validator=IntBoundedValidator(lower=-1),
doc="If specified overrides value in CharacterizationRunsFile If -1 turns off correction.")
self.declareProperty("VanadiumNumber", defaultValue=0, validator=IntBoundedValidator(lower=-1),
doc="If specified overrides value in CharacterizationRunsFile. If -1 turns off correction.")
self.declareProperty("VanadiumBackgroundNumber", defaultValue=0, validator=IntBoundedValidator(lower=-1),
doc="If specified overrides value in CharacterizationRunsFile. If -1 turns off correction.")

self.declareProperty(FileProperty(name="CalibrationFile",defaultValue="",action=FileAction.Load,
extensions = ["cal"]))

# Characterization... Vanadium, Background corrections
self.declareProperty(FileProperty(name="CharacterizationRunsFile",defaultValue="",action=FileAction.OptionalLoad,
extensions = ["txt"]),"File with characterization runs denoted")
self.declareProperty("BackgroundNumber", defaultValue=0, validator=IntBoundedValidator(lower=-1),
doc="If specified overrides value in CharacterizationRunsFile.")
self.declareProperty("DisableBackgroundCorrection", False, "If specified background correction is tured off.")
self.declareProperty("VanadiumNumber", defaultValue=0, validator=IntBoundedValidator(lower=-1),
doc="If specified overrides value in CharacterizationRunsFile. ")
self.declareProperty("DisableVanadiumCorrection", False, "If specified vanadium correction is tured off.")
self.declareProperty("VanadiumBackgroundNumber", defaultValue=0, validator=IntBoundedValidator(lower=-1),
doc="If specified overrides value in CharacterizationRunsFile. ")
self.declareProperty("DisableVanadiumBackgroundCorrection", False, "If specified vanadium correction is tured off.")

# Instrument Geometry corrections
self.declareProperty("UnwrapRef", 0.,
"Reference total flight path for frame unwrapping. Zero skips the correction")
self.declareProperty("LowResRef", 0.,
Expand All @@ -217,12 +225,17 @@ def PyInit(self):
self.declareProperty("MaxChunkSize", 0.0, "Specify maximum Gbytes of file to read in one chunk. Default is whole file.")
self.declareProperty("FilterCharacterizations", False,
"Filter the characterization runs using above parameters. This only works for event files.")

# Binning
self.declareProperty(FloatArrayProperty("Binning", values=[0.,0.,0.],
direction=Direction.Input), "Positive is linear bins, negative is logorithmic")
self.declareProperty("ResampleX", 0,
"Number of bins in x-axis. Non-zero value overrides \"Params\" property. Negative value means logorithmic binning.")
self.declareProperty("DoResampleX", False, "Flag to use ResampleX or Binning")
self.declareProperty("BinInDspace", True,
"If all three bin parameters a specified, whether they are in dspace (true) or time-of-flight (false)")

# Strip vanadium peaks
self.declareProperty("StripVanadiumPeaks", True,
"Subtract fitted vanadium peaks from the known positions.")
self.declareProperty("VanadiumFWHM", 7, "Default=7")
Expand All @@ -232,6 +245,8 @@ def PyInit(self):
self.declareProperty("FilterBadPulses", True, "Filter out events measured while proton charge is more than 5% below average")
outfiletypes = ['gsas', 'fullprof', 'gsas and fullprof', 'gsas and fullprof and pdfgetn', 'NeXus',
'gsas and NeXus', 'fullprof and NeXus', 'gsas and fullprof and NeXus', 'gsas and fullprof and pdfgetn and NeXus']

# Filter
self.declareProperty("FilterByTimeMin", 0.,
"Relative time to start filtering by in seconds. Applies only to sample.")
self.declareProperty("FilterByTimeMax", 0.,
Expand Down Expand Up @@ -271,7 +286,15 @@ def PyExec(self):
self.preserveevents = self.getProperty("PreserveEvents").value
self.sumspec = self.getProperty("Sum").value
self.cal_file = self.getProperty("CalibrationFile").value

self.char_file = self.getProperty("CharacterizationRunsFile").value
self.bkgdrunnumber = self.getProperty("BackgroundNumber").value
self.disablebkgdcorrection = self.getProperty("DisableBackgroundCorrection").value
self.vanrunnumber = self.getProperty("VanadiumNumber").value
self.disablevancorrection = self.getProperty("DisableVanadiumCorrection").value
self.vanbkgdrunnumber = self.getProperty("VanadiumBackgroundNumber").value
self.disablevanbkgdcorrection = self.getProperty("DisableVanadiumBackgroundCorrection").value

self.lowresref = self.getProperty("LowResRef").value
self.unwrapref = self.getProperty("UnwrapRef").value
self.rmpulsewidth = self.getProperty("RemovePromptPulseWidth").value
Expand All @@ -282,7 +305,19 @@ def PyExec(self):
self.savedir = self.getProperty("OutputDirectory").value
self.normalizebycurrent = self.getProperty("NormalizeByCurrent").value
self.dataunit = self.getProperty("FinalDataUnits").value
self.vanrunnumber = self.getProperty("VanadiumNumber").value
self.doresamplex = self.getProperty("DoResampleX").value

# 2. Set up the alternative choices
if self.doresamplex is False:
self.resamplex = 0

if self.disablebkgdcorrection is True:
self.bkgdrunnumber = -1
if self.disablevancorrection is True:
self.vanrunnumber = -1
if self.disablevanbkgdcorrection is True:
self.vanbkgdrunnumber = -1

"""
self. = self.getProperty().value
self. = self.getProperty().value
Expand All @@ -302,6 +337,9 @@ def PyExec(self):
PreserveEvents=self.preserveevents,
CalibrationFile=self.cal_file,
CharacterizationRunsFile=self.char_file,
BackgroundNumber = self.bkgdrunnumber,
VanadiumNumber = self.vanrunnumber,
VanadiumBackgroundNumber = self.vanbkgdrunnumber,
LowResRef=self.lowresref,
RemovePromptPulseWidth=self.rmpulsewidth,
Binning=self.binning,
Expand All @@ -311,7 +349,6 @@ def PyExec(self):
OutputDirectory=self.savedir,
NormalizeByCurrent=self.normalizebycurrent,
FinalDataUnits=self.dataunit,
VanadiumNumber=self.vanrunnumber
)

"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,27 @@ class RunSetupScript(BaseScriptElement):
preserveevents = False
dosum = False
extension = "_event.nxs"
binning = ""
binning = -0.0001
binningtype = "Logarithmic"
tofmin = ""
tofmax = ""
resamplex = 0
binindspace = True
saveas = "NeXus"
outputdir = ""
finalunits = "dSpacing"

bkgdrunnumber = ""
vanrunnumber = ""
vannoiserunnumber = ""
vanbkgdrunnumber = ""

disablebkgdcorrection = False
disablevancorrection = False
disablevanbkgdcorrection = False
doresamplex = False


def __init__(self, inst_name):
""" Initialization
"""
Expand Down Expand Up @@ -54,65 +68,73 @@ def createParametersList(self):
self.parnamelist.append("SaveAs")
self.parnamelist.append("OutputDirectory")
self.parnamelist.append("FinalDataUnits")
self.parnamelist.append("BackgroundNumber")
self.parnamelist.append("VanadiumNumber")
self.parnamelist.append("VanadiumNoiseNumber")
self.parnamelist.append("VanadiumBackgroundNumber")
self.parnamelist.append("DisableBackgroundCorrection")
self.parnamelist.append("DisableVanadiumCorrection")
self.parnamelist.append("DisableVanadiumBackgroundCorrection")
self.parnamelist.append("DoReSampleX")

return

def set_default_pars(self, inst_name):

# import dgs_utils
# ip = dgs_utils.InstrumentParameters(inst_name)
# RunSetupScript.monitor1_specid = int(ip.get_parameter("ei-mon1-spec"))
# RunSetupScript.monitor2_specid = int(ip.get_parameter("ei-mon2-spec"))

return

def to_script(self):
""" 'Public' method to save the current GUI to string via str() and general class ReductionScript
"""
if False:
script += "RunNumbers = \"%s\",\n" % (str(self.runnumbers))
script += "CalibrationFile = \"%s\"\n" % (str(self.charfilename))
script += "PreserveEvents = \"%s\"\n"
else:
parnamevaluedict = self.buildParameterDict()
script = ""
for parname in self.parnamelist:
script += "%-10s = \"%s\",\n" % (parname, parnamevaluedict[parname])
#ENDFOR
# ENDIFELSE

return script


def buildParameterDict(self):
""" Create a dictionary for parameter and parameter values for SNSPowderReductionPlus()
"""
pardict = {}

pardict["RunNumbers"] = str(self.runnumbers)
pardict["Extension"] = str(self.extension)
if self.preserveevents is True:
pardict["PreserveEvents"] = "1"
else:
pardict["PreserveEvents"] = "0"
if self.dosum is True:
pardict["Sum"] = "1"
else:
pardict["Sum"] = "0"
pardict["PreserveEvents"] = str(int(self.preserveevents))
pardict["Sum"] = str(int(self.dosum))
pardict["CalibrationFile"] = self.calibfilename
pardict["CharacterizationRunsFile"] = self.charfilename
# FIXME - Requiring validation on binning parameters
pardict["Binning"] = self.binning
if self.binningtype == "Logarithmic":
pardict["Binning"] = -1.0*abs(self.binning)
else:
pardict["Binning"] = self.binning
pardict["ResampleX"] = str(self.resamplex)
if self.binindspace is True:
pardict["BinInDspace"] = "1"
else:
pardict["BinInDspace"] = "0"
pardict["BinInDspace"] = str(int(self.binindspace))
pardict["SaveAs"] = self.saveas
pardict["OutputDirectory"] = self.outputdir
pardict["FinalDataUnits"] = self.finalunits

pardict["BackgroundNumber"] = self.bkgdrunnumber
pardict["VanadiumNumber"] = self.vanrunnumber
pardict["VanadiumNoiseNumber"] = self.vannoiserunnumber
pardict["VanadiumBackgroundNumber"] = self.vanbkgdrunnumber

pardict["DisableBackgroundCorrection"] = str(int(self.disablebkgdcorrection))
pardict["DisableVanadiumCorrection"] = str(int(self.disablevancorrection))
pardict["DisableVanadiumBackgroundCorrection"] = str(int(self.disablevanbkgdcorrection))
pardict["DoReSampleX"] = str(int(self.doresamplex))

return pardict

def set_default_pars(self, inst_name):
""" Set default value to parameters
Arguments:
- inst_name: name of the instrument
"""
return

def to_script(self):
""" 'Public' method to save the current GUI to string via str() and general class ReductionScript
"""
# 1. Build parameter dictionary
parnamevaluedict = self.buildParameterDict()

# 2. Write out the script as keys
script = ""
for parname in self.parnamelist:
parvalue = parnamevaluedict[parname]
if parvalue != "":
script += "%-10s = \"%s\",\n" % (parname, parvalue)
#ENDFOR

return script

def to_xml(self):
""" 'Public' method to create XML from the current data.
Expand Down Expand Up @@ -164,7 +186,7 @@ def from_xml(self, xml_str):
self.charfilename = BaseScriptElement.getStringElement(instrument_dom,
"characterizationrunsfile", default=RunSetupScript.charfilename)

self.binning = BaseScriptElement.getStringElement(instrument_dom,
self.binning = BaseScriptElement.getFloatElement(instrument_dom,
"binning", default=RunSetupScript.binning)

tempbool = BaseScriptElement.getStringElement(instrument_dom,
Expand All @@ -183,6 +205,42 @@ def from_xml(self, xml_str):
self.finalunits = BaseScriptElement.getStringElement(instrument_dom,
"finaldataunits", default=RunSetupScript.finalunits)

tempint = BaseScriptElement.getStringElement(instrument_dom,
"backgroundnumber", default=RunSetupScript.bkgdrunnumber)
try:
self.bkgdrunnumber = int(tempint)
except ValueError:
self.bkgdrunnumber = None
tempbool = BaseScriptElement.getStringElement(instrument_dom,
"disablebackgroundcorrection", default=str(int(RunSetupScript.disablebkgdcorrection)))
self.disablebkgdcorrection = bool(int(tempbool))

tempint = BaseScriptElement.getStringElement(instrument_dom,
"vanadiumnumber", default=RunSetupScript.vanrunnumber)
try:
self.vanrunnumber = int(tempint)
except ValueError:
self.vanrunnumber = ""
tempbool = BaseScriptElement.getStringElement(instrument_dom,
"disablevanadiumcorrection", default=str(int(RunSetupScript.disablevancorrection)))
self.disablevancorrection = bool(int(tempbool))

tempint = BaseScriptElement.getStringElement(instrument_dom,
"vanadiumbackgroundnumber", default=RunSetupScript.vanbkgdrunnumber)
try:
self.vanbkgdrunnumber = int(tempint)
except ValueError:
self.vanbkgdrunnumber = None
tempbool = BaseScriptElement.getStringElement(instrument_dom,
"disablevanadiumbackgroundcorrection", default=str(int(RunSetupScript.disablevanbkgdcorrection)))
self.disablevanbkgdcorrection = bool(int(tempbool))

# tempint = BaseScriptElement.getStringElement(instrument_dom,
# try:
# self.vannoiserunnumber = int(tempint)
# except ValueError:
# self.vannoiserunnumber = ""

return

def reset(self):
Expand All @@ -201,5 +259,13 @@ def reset(self):
self.outputdir = RunSetupScript.outputdir
self.finalunits = RunSetupScript.finalunits

self.disablebkgdcorrection = RunSetupScript.disablebkgdcorrection
self.disablevancorrection = RunSetupScript.disablevancorrection
self.disablevanbkgdcorrection = RunSetupScript.disablevanbkgdcorrection

self.bkgdrunnumber = RunSetupScript.bkgdrunnumber
self.vanrunnumber = RunSetupScript.vanrunnumber
self.vanbkgdrunnumber = RunSetupScript.vanbkgdrunnumber

return

0 comments on commit efed4f9

Please sign in to comment.