From 5238de67417c5a8b43c1024684cada9c97222f32 Mon Sep 17 00:00:00 2001 From: GuiMacielPereira Date: Tue, 13 Feb 2024 14:49:30 +0000 Subject: [PATCH] Do workaround for mantid editor bug Mantid editor caches variables in the module scope, leading to wrong behaviours The changes implemented in this commit fix this by calling the variables inside functions --- mvesuvio/vesuvio_analysis/ICHelpers.py | 29 +++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/mvesuvio/vesuvio_analysis/ICHelpers.py b/mvesuvio/vesuvio_analysis/ICHelpers.py index 4b3d6139..69d7012c 100644 --- a/mvesuvio/vesuvio_analysis/ICHelpers.py +++ b/mvesuvio/vesuvio_analysis/ICHelpers.py @@ -4,13 +4,27 @@ from mantid.kernel import logger import ntpath -inputsPath = Path(handle_config.read_config_var("caching.inputs")) -scriptName = inputsPath.name.removesuffix(".py") -experimentPath = inputsPath.parent / scriptName + +def _get_expr_path(): + inputsPath = Path(handle_config.read_config_var("caching.inputs")) + scriptName = _get_script_name() + experimentPath = inputsPath.parent / scriptName + return experimentPath + + +def _get_script_name(): + inputsPath = Path(handle_config.read_config_var("caching.inputs")) + scriptName = inputsPath.name.removesuffix(".py") + return scriptName + +# inputsPath = Path(handle_config.read_config_var("caching.inputs")) +# scriptName = inputsPath.name.removesuffix(".py") +# experimentPath = inputsPath.parent / scriptName def completeICFromInputs(IC, wsIC): """Assigns new methods to the initial conditions class from the inputs of that class""" + scriptName = _get_script_name() assert ( IC.lastSpec > IC.firstSpec @@ -81,6 +95,10 @@ def completeICFromInputs(IC, wsIC): def setInputWSForSample(wsIC): + experimentPath = _get_expr_path() + scriptName = _get_script_name() + print(scriptName.upper()) + inputWSPath = experimentPath / "input_ws" inputWSPath.mkdir(parents=True, exist_ok=True) @@ -114,6 +132,7 @@ def getRunningMode(wsIC): def setOutputDirsForSample(IC): + experimentPath = _get_expr_path() outputPath = experimentPath / "output_files" outputPath.mkdir(parents=True, exist_ok=True) @@ -208,6 +227,8 @@ def completeBootIC(bootIC, bckwdIC, fwdIC, yFitIC): def setBootstrapDirs(bckwdIC, fwdIC, bootIC, yFitIC): """Form bootstrap output data paths""" + experimentPath = _get_expr_path() + scriptName = _get_script_name() # Select script name and experiments path sampleName = bckwdIC.scriptName # Name of sample currently running @@ -318,12 +339,14 @@ def noOfHistsFromTOFBinning(IC): def buildFinalWSName(procedure: str, IC): + scriptName = _get_script_name() # Format of corrected ws from last iteration name = scriptName + "_" + procedure + "_" + str(IC.noOfMSIterations) return name def completeYFitIC(yFitIC): + experimentPath = _get_expr_path() # Set directories for figures figSavePath = experimentPath / "figures" figSavePath.mkdir(exist_ok=True)