diff --git a/.github/workflows/ci_tests_nightly.yml b/.github/workflows/ci_tests_nightly.yml index 0203624f..c0c16f5e 100644 --- a/.github/workflows/ci_tests_nightly.yml +++ b/.github/workflows/ci_tests_nightly.yml @@ -33,5 +33,4 @@ jobs: # Runs System tests - name: Run mvesuvio analysis system tests run: | - export VESUVIOPROPERTIES=$(pwd)/mvesuvio/system_tests/test_config/vesuvio.user.properties - python -m unittest discover -s ./mvesuvio/system_tests \ No newline at end of file + python -m unittest discover -s ./mvesuvio/system_tests diff --git a/.github/workflows/pr_workflow.yml b/.github/workflows/pr_workflow.yml index a15da777..97d90296 100644 --- a/.github/workflows/pr_workflow.yml +++ b/.github/workflows/pr_workflow.yml @@ -38,7 +38,6 @@ jobs: # Runs System tests - name: Run mvesuvio Analysis System Tests run: | - export VESUVIOPROPERTIES=$(pwd)/mvesuvio/system_tests/test_config/vesuvio.user.properties python -m unittest discover -s ./mvesuvio/system_tests - name: Run mvesuvio Calibration Unit Tests @@ -54,4 +53,4 @@ jobs: # Report coverage #- name: Report Coverage - # run: coverage report \ No newline at end of file + # run: coverage report diff --git a/.gitignore b/.gitignore index 6b62fef1..e2379958 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ output_npz_for_testing vesuvio_analysis/core_functions/bootstrap_ws/ running_times.txt figures/ +mvesuvio/system_tests/test_config/expr_for_tests/output_files diff --git a/environment.yml b/environment.yml index 7a211b35..803de10b 100644 --- a/environment.yml +++ b/environment.yml @@ -10,7 +10,7 @@ dependencies: - conda-wrappers - pre-commit==2.15 #review this - coverage - - mantid>=6.7 + - mantid==6.8 - matplotlib - iminuit - h5py diff --git a/mvesuvio/__init__.py b/mvesuvio/__init__.py index 2ffce353..e93fa026 100644 --- a/mvesuvio/__init__.py +++ b/mvesuvio/__init__.py @@ -6,8 +6,7 @@ nuclear kinetic energies and moment distributions. """ -version_info = (0, 0, 0) -__version__ = ".".join(map(str, version_info)) +from mvesuvio._version import __version__ __project_url__ = "https://github.com/mantidproject/vesuvio" from mvesuvio.scripts import main @@ -21,19 +20,14 @@ def command(self): return self.__command class ConfigArgInputs(ArgInputs): - def __init__(self, set_cache, set_experiment, set_ipfolder): + def __init__(self, set_inputs, set_ipfolder): super().__init__("config") - self.__set_cache = set_cache - self.__set_experiment = set_experiment + self.__set_inputs = set_inputs self.__set_ipfolder = set_ipfolder @property - def set_cache(self): - return self.__set_cache - - @property - def set_experiment(self): - return self.__set_experiment + def set_inputs(self): + return self.__set_inputs @property def set_ipfolder(self): @@ -50,8 +44,8 @@ def yes(self): return self.__yes -def set_config(cache_directory="", experiment_id="", ip_folder=""): - config_args = ConfigArgInputs(cache_directory, experiment_id, ip_folder) +def set_config(inputs_file="", ip_folder=""): + config_args = ConfigArgInputs(inputs_file, ip_folder) main(config_args) def run(yes_to_all=False): diff --git a/mvesuvio/_version.py b/mvesuvio/_version.py new file mode 100644 index 00000000..6c8e6b97 --- /dev/null +++ b/mvesuvio/_version.py @@ -0,0 +1 @@ +__version__ = "0.0.0" diff --git a/mvesuvio/analysis_runner.py b/mvesuvio/analysis_runner.py index 00b58005..8e9b7c8b 100644 --- a/mvesuvio/analysis_runner.py +++ b/mvesuvio/analysis_runner.py @@ -7,14 +7,9 @@ def run(yes_to_all=False): - scriptName = handle_config.read_config_var("caching.experiment") - experimentsPath = ( - Path(handle_config.read_config_var("caching.location")) - / "experiments" - / scriptName - ) # Path to the repository - inputs_path = experimentsPath / "analysis_inputs.py" + inputs_path = Path(handle_config.read_config_var("caching.inputs")) ipFilesPath = Path(handle_config.read_config_var("caching.ipfolder")) + ai = import_from_path(inputs_path, "analysis_inputs") start_time = time.time() @@ -29,7 +24,6 @@ def run(yes_to_all=False): runScript( userCtr, - scriptName, wsBackIC, wsFrontIC, bckwdIC, diff --git a/mvesuvio/config/analysis_inputs.py b/mvesuvio/config/analysis_inputs.py index 8690a8ca..b005d7a6 100644 --- a/mvesuvio/config/analysis_inputs.py +++ b/mvesuvio/config/analysis_inputs.py @@ -141,7 +141,7 @@ class YSpaceFitInitialConditions: showPlots = True symmetrisationFlag = True rebinParametersForYSpaceFit = "-25, 0.5, 25" # Needs to be symetric - fitModel = "Gaussian3D" # Options: 'SINGLE_GAUSSIAN', 'GC_C4', 'GC_C6', 'GC_C4_C6', 'DOUBLE_WELL', 'ANSIO_GAUSSIAN', 'Gaussian3D' + fitModel = "SINGLE_GAUSSIAN" # Options: 'SINGLE_GAUSSIAN', 'GC_C4', 'GC_C6', 'GC_C4_C6', 'DOUBLE_WELL', 'ANSIO_GAUSSIAN', 'Gaussian3D' runMinos = True globalFit = True # Performs global fit with Minuit by default nGlobalFitGroups = 4 # Number or string "ALL" @@ -160,3 +160,14 @@ class UserScriptControls: class BootstrapInitialConditions: runBootstrap = False + + +#################### +### RUN ANALYSIS ### +#################### + +if (__name__ == "__main__") or (__name__ == "mantidqt.widgets.codeeditor.execution"): + import mvesuvio + from pathlib import Path + mvesuvio.set_config(inputs_file=Path(__file__)) + mvesuvio.run() diff --git a/mvesuvio/config/vesuvio.user.properties b/mvesuvio/config/vesuvio.user.properties index d232dbee..2462f326 100644 --- a/mvesuvio/config/vesuvio.user.properties +++ b/mvesuvio/config/vesuvio.user.properties @@ -1,4 +1,3 @@ # properties that suit your particular installation. -caching.location= -caching.experiment= +caching.inputs= caching.ipfolder= diff --git a/mvesuvio/scripts/__init__.py b/mvesuvio/scripts/__init__.py index 7615d88e..723ac21d 100644 --- a/mvesuvio/scripts/__init__.py +++ b/mvesuvio/scripts/__init__.py @@ -15,11 +15,13 @@ def main(manual_args=None): __setup_config(None) __run_analysis(args.yes) + def __setup_and_parse_args(): parser = __set_up_parser() args = parser.parse_args() return args + def __set_up_parser(): parser = argparse.ArgumentParser( description="Package to analyse Vesuvio instrument data" @@ -27,7 +29,7 @@ def __set_up_parser(): subparsers = parser.add_subparsers(dest="command", required=True) config_parser = subparsers.add_parser("config", help="set mvesuvio configuration") config_parser.add_argument( - "--set-cache", "-c", help="set the cache directory", default="", type=str + "--set-inputs", "-i", help="set the inputs python file", default="", type=str ) config_parser.add_argument( "--set-ipfolder", @@ -36,13 +38,6 @@ def __set_up_parser(): default="", type=str, ) - config_parser.add_argument( - "--set-experiment", - "-e", - help="set the current experiment", - default="", - type=str, - ) run_parser = subparsers.add_parser("run", help="run mvesuvio analysis") run_parser.add_argument( @@ -55,17 +50,13 @@ def __setup_config(args): config_dir = handle_config.VESUVIO_CONFIG_PATH handle_config.setup_config_dir(config_dir) ipfolder_dir = handle_config.VESUVIO_IPFOLDER_PATH + inputs = handle_config.VESUVIO_INPUTS_PATH if handle_config.config_set(): - cache_dir = ( - handle_config.read_config_var("caching.location") - if not args or not args.set_cache - else args.set_cache - ) - experiment = ( - handle_config.read_config_var("caching.experiment") - if not args or not args.set_experiment - else args.set_experiment + inputs = ( + handle_config.read_config_var("caching.inputs") + if not args or not args.set_inputs + else args.set_inputs ) ipfolder_dir = ( handle_config.read_config_var("caching.ipfolder") @@ -73,24 +64,22 @@ def __setup_config(args): else args.set_ipfolder ) else: - cache_dir = config_dir if not args or not args.set_cache else args.set_cache - experiment = ( - "default" if not args or not args.set_experiment else args.set_experiment + inputs = ( + inputs if not args or not args.set_inputs else args.set_inputs ) ipfolder_dir = ( ipfolder_dir if not args or not args.set_ipfolder else args.set_ipfolder ) handle_config.setup_default_ipfile_dir() + handle_config.setup_default_inputs() handle_config.set_config_vars( { - "caching.location": cache_dir, - "caching.experiment": experiment, + "caching.inputs": inputs, "caching.ipfolder": ipfolder_dir, } ) - handle_config.setup_expr_dir(cache_dir, experiment) handle_config.check_dir_exists("IP folder", ipfolder_dir) diff --git a/mvesuvio/scripts/handle_config.py b/mvesuvio/scripts/handle_config.py index 8fd7b28d..97bfc01a 100644 --- a/mvesuvio/scripts/handle_config.py +++ b/mvesuvio/scripts/handle_config.py @@ -15,6 +15,7 @@ def __parse_config_env_var(): ### PATH CONSTANTS ### VESUVIO_CONFIG_PATH, VESUVIO_CONFIG_FILE = __parse_config_env_var() VESUVIO_INPUTS_FILE = "analysis_inputs.py" +VESUVIO_INPUTS_PATH = os.path.join(VESUVIO_CONFIG_PATH, VESUVIO_INPUTS_FILE) VESUVIO_PACKAGE_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) MANTID_CONFIG_FILE = "Mantid.user.properties" VESUVIO_IPFOLDER_PATH = os.path.join(VESUVIO_CONFIG_PATH, "ip_files") @@ -70,6 +71,12 @@ def read_config_var(var, throw_on_not_found=True): return result +def get_script_name(): + filename = os.path.basename(read_config_var("caching.inputs")) + scriptName = filename.removesuffix(".py") + return scriptName + + def setup_config_dir(config_dir): success = __mk_dir("config", config_dir) if success: @@ -83,13 +90,11 @@ def setup_config_dir(config_dir): ) -def setup_expr_dir(cache_dir, experiment): - expr_path = os.path.join(cache_dir, "experiments", experiment) - success = __mk_dir("experiment", expr_path) - if success: +def setup_default_inputs(): + if not os.path.isfile(VESUVIO_INPUTS_PATH): copyfile( os.path.join(VESUVIO_PACKAGE_PATH, "config", VESUVIO_INPUTS_FILE), - input_file_path(cache_dir, experiment), + os.path.join(VESUVIO_INPUTS_PATH), ) @@ -114,16 +119,12 @@ def __mk_dir(type, path): def config_set(): - if read_config_var("caching.location", False): + if read_config_var("caching.inputs", False): return True else: return False -def input_file_path(cache_dir, experiment): - return os.path.join(cache_dir, "experiments", experiment, VESUVIO_INPUTS_FILE) - - def check_dir_exists(type, path): if not os.path.isdir(path): print(f"Directory of {type} could not be found at location: {path}") diff --git a/mvesuvio/system_tests/test_analysis.py b/mvesuvio/system_tests/test_analysis.py index 07cfc576..c54eb395 100644 --- a/mvesuvio/system_tests/test_analysis.py +++ b/mvesuvio/system_tests/test_analysis.py @@ -4,7 +4,7 @@ import numpy.testing as nptest from pathlib import Path from mvesuvio.scripts import handle_config -from mvesuvio.system_tests.analysis_inputs import ( +from mvesuvio.system_tests.test_config.expr_for_tests import ( LoadVesuvioBackParameters, LoadVesuvioFrontParameters, BackwardInitialConditions, @@ -13,7 +13,11 @@ BootstrapInitialConditions, UserScriptControls, ) - +import mvesuvio +mvesuvio.set_config( + ip_folder=str(Path(handle_config.VESUVIO_PACKAGE_PATH).joinpath("config", "ip_files")), + inputs_file=str(Path(handle_config.VESUVIO_PACKAGE_PATH).joinpath("system_tests", "test_config", "expr_for_tests.py")) +) ipFilesPath = Path(handle_config.read_config_var("caching.ipfolder")) @@ -38,7 +42,6 @@ def get_current_result(cls): def _run(cls): scattRes, yfitRes = runScript( UserScriptControls(), - "test_expr", LoadVesuvioBackParameters(ipFilesPath), LoadVesuvioFrontParameters(ipFilesPath), BackwardInitialConditions(ipFilesPath), diff --git a/mvesuvio/system_tests/test_bootstrap.py b/mvesuvio/system_tests/test_bootstrap.py index d61f09bc..b0ba957d 100644 --- a/mvesuvio/system_tests/test_bootstrap.py +++ b/mvesuvio/system_tests/test_bootstrap.py @@ -1,10 +1,13 @@ + +# This file needs updating once the bootstrap functunality is properly +# implemented in the mvesuvio package + from mvesuvio.vesuvio_analysis.run_script import runScript import unittest import numpy as np import numpy.testing as nptest from pathlib import Path from mvesuvio.system_tests.tests_IC import ( - scriptName, wsBackIC, wsFrontIC, bckwdIC, @@ -12,7 +15,6 @@ yFitIC, ) - class BootstrapInitialConditions: runBootstrap = True @@ -45,7 +47,7 @@ def _run_analysis(cls): yFitIC.symmetrisationFlag = True bootRes, noneRes = runScript( - userCtr, scriptName, wsBackIC, wsFrontIC, bckwdIC, fwdIC, yFitIC, bootIC, True + userCtr, wsBackIC, wsFrontIC, bckwdIC, fwdIC, yFitIC, bootIC, True ) # TODO: Figure out why doing the two tests simultaneously fails the testing diff --git a/mvesuvio/system_tests/test_config/__init__.py b/mvesuvio/system_tests/test_config/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/mvesuvio/system_tests/analysis_inputs.py b/mvesuvio/system_tests/test_config/expr_for_tests.py similarity index 93% rename from mvesuvio/system_tests/analysis_inputs.py rename to mvesuvio/system_tests/test_config/expr_for_tests.py index 4673db95..4f9dd111 100644 --- a/mvesuvio/system_tests/analysis_inputs.py +++ b/mvesuvio/system_tests/test_config/expr_for_tests.py @@ -107,7 +107,14 @@ def __init__(self, ipFilesPath): class YSpaceFitInitialConditions: - anything = True + showPlots = False + symmetrisationFlag = True + rebinParametersForYSpaceFit = "-20, 0.5, 20" # Needs to be symetric + fitModel = "SINGLE_GAUSSIAN" + runMinos = True + globalFit = None + nGlobalFitGroups = 4 + maskTypeProcedure = None class UserScriptControls: diff --git a/mvesuvio/system_tests/test_config/experiments/test_expr/input_ws/test_expr_empty_backward.nxs b/mvesuvio/system_tests/test_config/expr_for_tests/input_ws/expr_for_tests_empty_backward.nxs similarity index 100% rename from mvesuvio/system_tests/test_config/experiments/test_expr/input_ws/test_expr_empty_backward.nxs rename to mvesuvio/system_tests/test_config/expr_for_tests/input_ws/expr_for_tests_empty_backward.nxs diff --git a/mvesuvio/system_tests/test_config/experiments/test_expr/input_ws/test_expr_empty_forward.nxs b/mvesuvio/system_tests/test_config/expr_for_tests/input_ws/expr_for_tests_empty_forward.nxs similarity index 100% rename from mvesuvio/system_tests/test_config/experiments/test_expr/input_ws/test_expr_empty_forward.nxs rename to mvesuvio/system_tests/test_config/expr_for_tests/input_ws/expr_for_tests_empty_forward.nxs diff --git a/mvesuvio/system_tests/test_config/experiments/test_expr/input_ws/test_expr_raw_backward.nxs b/mvesuvio/system_tests/test_config/expr_for_tests/input_ws/expr_for_tests_raw_backward.nxs similarity index 100% rename from mvesuvio/system_tests/test_config/experiments/test_expr/input_ws/test_expr_raw_backward.nxs rename to mvesuvio/system_tests/test_config/expr_for_tests/input_ws/expr_for_tests_raw_backward.nxs diff --git a/mvesuvio/system_tests/test_config/experiments/test_expr/input_ws/test_expr_raw_forward.nxs b/mvesuvio/system_tests/test_config/expr_for_tests/input_ws/expr_for_tests_raw_forward.nxs similarity index 100% rename from mvesuvio/system_tests/test_config/experiments/test_expr/input_ws/test_expr_raw_forward.nxs rename to mvesuvio/system_tests/test_config/expr_for_tests/input_ws/expr_for_tests_raw_forward.nxs diff --git a/mvesuvio/system_tests/test_config/vesuvio.user.properties b/mvesuvio/system_tests/test_config/vesuvio.user.properties deleted file mode 100644 index 7bf33e58..00000000 --- a/mvesuvio/system_tests/test_config/vesuvio.user.properties +++ /dev/null @@ -1,4 +0,0 @@ -# properties to be used in CI testing. -caching.location=mvesuvio/system_tests/test_config -caching.experiment=test_expr -caching.ipfolder=mvesuvio/config/ip_files diff --git a/mvesuvio/system_tests/test_jackknife.py b/mvesuvio/system_tests/test_jackknife.py index 06eb2a61..558d96ee 100644 --- a/mvesuvio/system_tests/test_jackknife.py +++ b/mvesuvio/system_tests/test_jackknife.py @@ -1,10 +1,13 @@ + +# This file needs updating once the bootstrap functunality is properly +# implemented in the mvesuvio package + from mvesuvio.vesuvio_analysis.run_script import runScript import unittest import numpy as np import numpy.testing as nptest from pathlib import Path from mvesuvio.system_tests.tests_IC import ( - scriptName, wsBackIC, wsFrontIC, bckwdIC, @@ -42,7 +45,7 @@ def _run_analysis(cls): userCtr = UserScriptControls bootRes, noneRes = runScript( - userCtr, scriptName, wsBackIC, wsFrontIC, bckwdIC, fwdIC, yFitIC, bootIC, True + userCtr, wsBackIC, wsFrontIC, bckwdIC, fwdIC, yFitIC, bootIC, True ) cls._jackBackSamples = bootRes["bckwdScat"].bootSamples diff --git a/mvesuvio/system_tests/test_yspace_fit.py b/mvesuvio/system_tests/test_yspace_fit.py index dde35c1e..fdae0eca 100644 --- a/mvesuvio/system_tests/test_yspace_fit.py +++ b/mvesuvio/system_tests/test_yspace_fit.py @@ -5,15 +5,19 @@ import numpy as np import unittest import numpy.testing as nptest -from mvesuvio.system_tests.tests_IC import ( - scriptName, - wsBackIC, - wsFrontIC, - bckwdIC, - fwdIC, - yFitIC, +from mvesuvio.scripts import handle_config +from mvesuvio.system_tests.test_config.expr_for_tests import ( + LoadVesuvioBackParameters, + LoadVesuvioFrontParameters, + BackwardInitialConditions, + ForwardInitialConditions, + YSpaceFitInitialConditions, +) +import mvesuvio +mvesuvio.set_config( + ip_folder=str(Path(handle_config.VESUVIO_PACKAGE_PATH).joinpath("config", "ip_files")), + inputs_file=str(Path(handle_config.VESUVIO_PACKAGE_PATH).joinpath("system_tests", "test_config", "expr_for_tests.py")) ) - np.set_printoptions(suppress=True, precision=8, linewidth=150) @@ -27,6 +31,22 @@ class UserScriptControls: fitInYSpace = "FORWARD" +bootIC = BootstrapInitialConditions +userCtr = UserScriptControls +ipFilesPath = Path(handle_config.read_config_var("caching.ipfolder")) +wsBackIC = LoadVesuvioBackParameters(ipFilesPath) +wsFrontIC = LoadVesuvioFrontParameters(ipFilesPath) +bckwdIC = BackwardInitialConditions(ipFilesPath) +fwdIC = ForwardInitialConditions(ipFilesPath) +yFitIC = YSpaceFitInitialConditions() +scriptName = handle_config.get_script_name() + +fwdIC.noOfMSIterations = 1 +fwdIC.firstSpec = 164 +fwdIC.lastSpec = 175 +yFitIC.fitModel = "SINGLE_GAUSSIAN" + + class AnalysisRunner: _benchmarkResults = None _currentResults = None @@ -67,14 +87,10 @@ def _load_workspaces(cls): @classmethod def _run(cls): - bootIC = BootstrapInitialConditions - userCtr = UserScriptControls - yFitIC.fitModel = "SINGLE_GAUSSIAN" - cls.load_workspaces() # Load data to skip run of routine scattRes, yfitRes = runScript( - userCtr, scriptName, wsBackIC, wsFrontIC, bckwdIC, fwdIC, yFitIC, bootIC, True + userCtr, wsBackIC, wsFrontIC, bckwdIC, fwdIC, yFitIC, bootIC, True ) cls._currentResults = yfitRes diff --git a/mvesuvio/system_tests/test_yspace_fit_GC.py b/mvesuvio/system_tests/test_yspace_fit_GC.py index 3c9d1ab7..804cd082 100644 --- a/mvesuvio/system_tests/test_yspace_fit_GC.py +++ b/mvesuvio/system_tests/test_yspace_fit_GC.py @@ -5,15 +5,19 @@ import numpy as np import unittest import numpy.testing as nptest -from mvesuvio.system_tests.tests_IC import ( - scriptName, - wsBackIC, - wsFrontIC, - bckwdIC, - fwdIC, - yFitIC, +from mvesuvio.scripts import handle_config +from mvesuvio.system_tests.test_config.expr_for_tests import ( + LoadVesuvioBackParameters, + LoadVesuvioFrontParameters, + BackwardInitialConditions, + ForwardInitialConditions, + YSpaceFitInitialConditions, +) +import mvesuvio +mvesuvio.set_config( + ip_folder=str(Path(handle_config.VESUVIO_PACKAGE_PATH).joinpath("config", "ip_files")), + inputs_file=str(Path(handle_config.VESUVIO_PACKAGE_PATH).joinpath("system_tests", "test_config", "expr_for_tests.py")) ) - np.set_printoptions(suppress=True, precision=8, linewidth=150) @@ -27,6 +31,23 @@ class UserScriptControls: fitInYSpace = "FORWARD" +bootIC = BootstrapInitialConditions +userCtr = UserScriptControls +ipFilesPath = Path(handle_config.read_config_var("caching.ipfolder")) +wsBackIC = LoadVesuvioBackParameters(ipFilesPath) +wsFrontIC = LoadVesuvioFrontParameters(ipFilesPath) +bckwdIC = BackwardInitialConditions(ipFilesPath) +fwdIC = ForwardInitialConditions(ipFilesPath) +yFitIC = YSpaceFitInitialConditions() +scriptName = handle_config.get_script_name() + +fwdIC.noOfMSIterations = 1 +fwdIC.firstSpec = 164 +fwdIC.lastSpec = 175 +yFitIC.fitModel = "GC_C4_C6" +yFitIC.symmetrisationFlag = False + + class AnalysisRunner: _benchmarkResults = None _currentResults = None @@ -67,15 +88,10 @@ def _load_workspaces(cls): @classmethod def _run(cls): - bootIC = BootstrapInitialConditions - userCtr = UserScriptControls - yFitIC.fitModel = "GC_C4_C6" - yFitIC.symmetrisationFlag = False - cls.load_workspaces() scattRes, yfitRes = runScript( - userCtr, scriptName, wsBackIC, wsFrontIC, bckwdIC, fwdIC, yFitIC, bootIC, True + userCtr, wsBackIC, wsFrontIC, bckwdIC, fwdIC, yFitIC, bootIC, True ) cls._currentResults = yfitRes diff --git a/mvesuvio/vesuvio_analysis/ICHelpers.py b/mvesuvio/vesuvio_analysis/ICHelpers.py index 0f664350..3be984bb 100644 --- a/mvesuvio/vesuvio_analysis/ICHelpers.py +++ b/mvesuvio/vesuvio_analysis/ICHelpers.py @@ -4,13 +4,17 @@ from mantid.kernel import logger import ntpath -experimentsPath = ( - Path(handle_config.read_config_var("caching.location")) / "experiments" -) +def _get_expr_path(): + inputsPath = Path(handle_config.read_config_var("caching.inputs")) + scriptName = handle_config.get_script_name() + experimentPath = inputsPath.parent / scriptName + return experimentPath -def completeICFromInputs(IC, scriptName, wsIC): + +def completeICFromInputs(IC, wsIC): """Assigns new methods to the initial conditions class from the inputs of that class""" + scriptName = handle_config.get_script_name() assert ( IC.lastSpec > IC.firstSpec @@ -49,12 +53,12 @@ def completeICFromInputs(IC, scriptName, wsIC): IC.InstrParsPath = wsIC.ipfile # Sort out input and output paths - rawPath, emptyPath = setInputWSForSample(wsIC, scriptName) + rawPath, emptyPath = setInputWSForSample(wsIC) IC.userWsRawPath = rawPath IC.userWsEmptyPath = emptyPath - setOutputDirsForSample(IC, scriptName) + setOutputDirsForSample(IC) # Do not run bootstrap sample, by default IC.runningSampleWS = False @@ -65,11 +69,6 @@ def completeICFromInputs(IC, scriptName, wsIC): # Default not running preliminary procedure to estimate HToMass0Ratio IC.runningPreliminary = False - # Set directories for figures - figSavePath = experimentsPath / scriptName / "figures" - figSavePath.mkdir(exist_ok=True) - IC.figSavePath = figSavePath - # Create default of not running original version with histogram data try: IC.runHistData @@ -85,14 +84,17 @@ def completeICFromInputs(IC, scriptName, wsIC): return -def setInputWSForSample(wsIC, sampleName): - inputWSPath = experimentsPath / sampleName / "input_ws" +def setInputWSForSample(wsIC): + experimentPath = _get_expr_path() + scriptName = handle_config.get_script_name() + + inputWSPath = experimentPath / "input_ws" inputWSPath.mkdir(parents=True, exist_ok=True) runningMode = getRunningMode(wsIC) - rawWSName = sampleName + "_" + "raw" + "_" + runningMode + ".nxs" - emptyWSName = sampleName + "_" + "empty" + "_" + runningMode + ".nxs" + rawWSName = scriptName + "_" + "raw" + "_" + runningMode + ".nxs" + emptyWSName = scriptName + "_" + "empty" + "_" + runningMode + ".nxs" rawPath = inputWSPath / rawWSName emptyPath = inputWSPath / emptyWSName @@ -118,8 +120,9 @@ def getRunningMode(wsIC): return runningMode -def setOutputDirsForSample(IC, sampleName): - outputPath = experimentsPath / sampleName / "output_files" +def setOutputDirsForSample(IC): + experimentPath = _get_expr_path() + outputPath = experimentPath / "output_files" outputPath.mkdir(parents=True, exist_ok=True) # Build Filename based on ic @@ -136,6 +139,11 @@ def setOutputDirsForSample(IC, sampleName): IC.resultsSavePath = outputPath / fileName IC.ySpaceFitSavePath = outputPath / fileNameYSpace + + # Set directories for figures + figSavePath = experimentPath / "figures" + figSavePath.mkdir(exist_ok=True) + IC.figSavePath = figSavePath return @@ -208,18 +216,20 @@ def completeBootIC(bootIC, bckwdIC, fwdIC, yFitIC): def setBootstrapDirs(bckwdIC, fwdIC, bootIC, yFitIC): """Form bootstrap output data paths""" + experimentPath = _get_expr_path() + scriptName = handle_config.get_script_name() # Select script name and experiments path sampleName = bckwdIC.scriptName # Name of sample currently running # Used to store running times required to estimate Bootstrap total run time. - bootIC.runTimesPath = experimentsPath / sampleName / "running_times.txt" + bootIC.runTimesPath = experimentPath / "running_times.txt" # Make bootstrap and jackknife data directories if bootIC.bootstrapType == "JACKKNIFE": - bootPath = experimentsPath / sampleName / "jackknife_data" + bootPath = experimentPath / "jackknife_data" else: - bootPath = experimentsPath / sampleName / "bootstrap_data" + bootPath = experimentPath / "bootstrap_data" bootPath.mkdir(exist_ok=True) # Folders for skipped and unskipped MS @@ -317,16 +327,17 @@ def noOfHistsFromTOFBinning(IC): return int((end - start) / spacing) - 1 # To account for last column being ignored -def buildFinalWSName(scriptName: str, procedure: str, IC): +def buildFinalWSName(procedure: str, IC): + scriptName = handle_config.get_script_name() # Format of corrected ws from last iteration name = scriptName + "_" + procedure + "_" + str(IC.noOfMSIterations) return name -def completeYFitIC(yFitIC, sampleName): +def completeYFitIC(yFitIC): + experimentPath = _get_expr_path() # Set directories for figures - - figSavePath = experimentsPath / sampleName / "figures" + figSavePath = experimentPath / "figures" figSavePath.mkdir(exist_ok=True) yFitIC.figSavePath = figSavePath return diff --git a/mvesuvio/vesuvio_analysis/run_script.py b/mvesuvio/vesuvio_analysis/run_script.py index 00ac7f9c..8cd4f10b 100644 --- a/mvesuvio/vesuvio_analysis/run_script.py +++ b/mvesuvio/vesuvio_analysis/run_script.py @@ -18,7 +18,6 @@ def runScript( userCtr, - scriptName, wsBackIC, wsFrontIC, bckwdIC, @@ -28,10 +27,10 @@ def runScript( yes_to_all=False, ): # Set extra attributes from user attributes - completeICFromInputs(fwdIC, scriptName, wsFrontIC) - completeICFromInputs(bckwdIC, scriptName, wsBackIC) + completeICFromInputs(fwdIC, wsFrontIC) + completeICFromInputs(bckwdIC, wsBackIC) completeBootIC(bootIC, bckwdIC, fwdIC, yFitIC) - completeYFitIC(yFitIC, scriptName) + completeYFitIC(yFitIC) checkInputs(userCtr) checkInputs(bootIC) @@ -73,7 +72,7 @@ def runProcedure(): ICs = [] for mode, IC in zip(["BACKWARD", "FORWARD"], [bckwdIC, fwdIC]): if (userCtr.fitInYSpace == mode) | (userCtr.fitInYSpace == "JOINT"): - wsNames.append(buildFinalWSName(scriptName, mode, IC)) + wsNames.append(buildFinalWSName(mode, IC)) ICs.append(IC) # If bootstrap is not None, run bootstrap procedure and finish diff --git a/runner/docker/runner.Dockerfile b/runner/docker/runner.Dockerfile index c545a169..8783c78a 100644 --- a/runner/docker/runner.Dockerfile +++ b/runner/docker/runner.Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:jammy-20231211.1 +FROM ubuntu:jammy-20240227 RUN apt-get update && apt-get install -y \ curl \