Skip to content

Commit

Permalink
Format declareProperties in a nicer way
Browse files Browse the repository at this point in the history
  • Loading branch information
GuiMacielPereira committed Sep 6, 2024
1 parent 6b07991 commit 5518599
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 53 deletions.
159 changes: 107 additions & 52 deletions src/mvesuvio/analysis_reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,59 +47,114 @@ def category(self):
return "VesuvioAnalysis"

def PyInit(self):
self.declareProperty(MatrixWorkspaceProperty(name="InputWorkspace",
defaultValue="",
direction=Direction.Input),
doc="Workspace to fit Neutron Compton Profiles.")

self.declareProperty(TableWorkspaceProperty(name="InputProfiles",
defaultValue="",
direction=Direction.Input),
doc="Table workspace containing starting parameters for profiles")

self.declareProperty(FileProperty(name='InstrumentParametersFile',
defaultValue='',
action=FileAction.Load,
extensions=["par", "dat"]),
doc="Filename of the instrument parameter file.")

self.declareProperty("HRatioToLowestMass", 0.0, validator=FloatBoundedValidator(lower=0),
doc="Intensity ratio between H peak and lowest mass peak.")

self.declareProperty("NumberOfIterations", 2, validator=IntBoundedValidator(lower=0))

self.declareProperty(IntArrayProperty(name="InvalidDetectors",
validator=IntArrayBoundedValidator(lower=3, upper=198),
direction=Direction.Input),
doc="List of invalid detectors whithin range 3-198")

self.declareProperty("MultipleScatteringCorrection", False, doc="Whether to run multiple scattering correction")
self.declareProperty("GammaCorrection", False, doc="Whether to run gamma correction")

self.declareProperty("SampleVerticalWidth", -1.0, validator=FloatBoundedValidator(lower=0))
self.declareProperty("SampleHorizontalWidth", -1.0, validator=FloatBoundedValidator(lower=0))
self.declareProperty("SampleThickness", -1.0, validator=FloatBoundedValidator(lower=0))

self.declareProperty("ModeRunning",
"BACKWARD",
validator=StringListValidator(["BACKWARD", "FORWARD"]),
doc="Whether running backward or forward scattering.")

self.declareProperty("OutputDirectory", "", doc="Directory where to save analysis results.")

# self.declareProperty("Constraints", (), doc="Constraints to use during fitting profiles.")

self.declareProperty("TransmissionGuess", -1.0, validator=FloatBoundedValidator(lower=0, upper=1))
self.declareProperty("MultipleScatteringOrder", -1, validator=IntBoundedValidator(lower=0))
self.declareProperty("NumberOfEvents", -1, validator=IntBoundedValidator(lower=0))
self.declareProperty("ResultsPath", "", doc="Directory to store results, to be deleted later")
self.declareProperty("FiguresPath", "", doc="Directory to store figures, to be deleted later")

self.declareProperty(MatrixWorkspaceProperty(
name="InputWorkspace",
defaultValue="",
direction=Direction.Input),
doc="Workspace to fit Neutron Compton Profiles."
)
self.declareProperty(TableWorkspaceProperty(
name="InputProfiles",
defaultValue="",
direction=Direction.Input),
doc="Table workspace containing starting parameters for profiles"
)
self.declareProperty(FileProperty(
name='InstrumentParametersFile',
defaultValue='',
action=FileAction.Load,
extensions=["par", "dat"]),
doc="Filename of the instrument parameter file."
)
self.declareProperty(
name="HRatioToLowestMass",
defaultValue=0.0,
validator=FloatBoundedValidator(lower=0),
doc="Intensity ratio between H peak and lowest mass peak."
)
self.declareProperty(
name="NumberOfIterations",
defaultValue=2,
validator=IntBoundedValidator(lower=0)
)
self.declareProperty(IntArrayProperty(
name="InvalidDetectors",
validator=IntArrayBoundedValidator(lower=3, upper=198),
direction=Direction.Input),
doc="List of invalid detectors whithin range 3-198"
)
self.declareProperty(
name="MultipleScatteringCorrection",
defaultValue=False,
doc="Whether to run multiple scattering correction"
)
self.declareProperty(
name="GammaCorrection",
defaultValue=False,
doc="Whether to run gamma correction"
)
self.declareProperty(
name="SampleVerticalWidth",
defaultValue=-1.0,
validator=FloatBoundedValidator(lower=0)
)
self.declareProperty(
name="SampleHorizontalWidth",
defaultValue=-1.0,
validator=FloatBoundedValidator(lower=0)
)
self.declareProperty(
name="SampleThickness",
defaultValue=-1.0,
validator=FloatBoundedValidator(lower=0)
)
self.declareProperty(
name="ModeRunning",
defaultValue="BACKWARD",
validator=StringListValidator(["BACKWARD", "FORWARD"]),
doc="Whether running backward or forward scattering.")

self.declareProperty(
name="OutputDirectory",
defaultValue="",
doc="Directory where to save analysis results."
)
# self.declareProperty(
# name="Constraints",
# defaultValue=(),
# doc="Constraints to use during fitting profiles."
# )
self.declareProperty(
name="TransmissionGuess",
defaultValue=-1.0,
validator=FloatBoundedValidator(lower=0, upper=1)
)
self.declareProperty(
name="MultipleScatteringOrder",
defaultValue=-1,
validator=IntBoundedValidator(lower=0)
)
self.declareProperty(
name="NumberOfEvents",
defaultValue=-1,
validator=IntBoundedValidator(lower=0)
)
self.declareProperty(
name="ResultsPath",
defaultValue="",
doc="Directory to store results, to be deleted later"
)
self.declareProperty(
name="FiguresPath",
defaultValue="",
doc="Directory to store figures, to be deleted later"
)
# Outputs
self.declareProperty(TableWorkspaceProperty(name="OutputMeansTable",
defaultValue="",
direction=Direction.Output),
doc="TableWorkspace containing final means of intensity and widths.")
self.declareProperty(TableWorkspaceProperty(
name="OutputMeansTable",
defaultValue="",
direction=Direction.Output),
doc="TableWorkspace containing final means of intensity and widths.")


def PyExec(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/data/analysis/inputs/sample_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class ForwardInitialConditions(GeneralInitialConditions):
def __init__(self, ipFilesPath):
self.InstrParsPath = ipFilesPath / "ip2018_3.par"

HToMassIdxRatio = 0.0 # New way to ignore ratio
HToMassIdxRatio = 0 # New way to ignore ratio

masses = np.array([1.0079, 12, 16, 27])
initPars = np.array([1, 4.7, 0, 1, 12.71, 0.0, 1, 8.76, 0.0, 1, 13.897, 0.0])
Expand Down

0 comments on commit 5518599

Please sign in to comment.