diff --git a/EVSVesuvio/original_inputs.py b/EVSVesuvio/original_inputs.py index cde26a90..5a7cf58e 100644 --- a/EVSVesuvio/original_inputs.py +++ b/EVSVesuvio/original_inputs.py @@ -1,13 +1,14 @@ import time import numpy as np from pathlib import Path -from vesuvio_analysis.core_functions.bootstrap import runBootstrap -from vesuvio_analysis.core_functions.bootstrap_analysis import runAnalysisOfStoredBootstrap -from vesuvio_analysis.core_functions.run_script import runScript +from EVSVesuvio.vesuvio_analysis.core_functions.bootstrap import runBootstrap +from EVSVesuvio.vesuvio_analysis.core_functions.bootstrap_analysis import runAnalysisOfStoredBootstrap +from EVSVesuvio.vesuvio_analysis.core_functions.run_script import runScript from mantid.api import AnalysisDataService +from EVSVesuvio.scripts import handle_config -scriptName = Path(__file__).name.split(".")[0] # Take out .py -experimentPath = Path(__file__).absolute().parent / "experiments" / scriptName # Path to the repository +scriptName = handle_config.read_config_var('caching.experiment') +experimentsPath = Path(handle_config.read_config_var('caching.location')) / "experiments" / scriptName # Path to the repository ipFilesPath = Path(__file__).absolute().parent / "vesuvio_analysis" / "ip_files" diff --git a/EVSVesuvio/scripts/__init__.py b/EVSVesuvio/scripts/__init__.py index af648857..85a14ea5 100644 --- a/EVSVesuvio/scripts/__init__.py +++ b/EVSVesuvio/scripts/__init__.py @@ -1,22 +1,20 @@ -"""Package defining top-level application -and entry points. +"""Package defining entry points. """ import argparse import os from shutil import copyfile - -VESUVIO_CONFIG_FILE = "vesuvio.user.properties" +from EVSVesuvio.scripts import handle_config def main(): parser = __set_up_parser() args = parser.parse_args() - config_dir = os.path.join(os.path.expanduser("~"), '.mvesuvio') + config_dir = handle_config.VESUVIO_CONFIG_PATH cache_dir = config_dir if not args.set_cache else args.set_cache experiment = "default" if not args.set_experiment else args.set_experiment if __setup_config_dir(config_dir): - __set_config_vars(config_dir, {'caching.location': cache_dir, + handle_config.set_config_vars({'caching.location': cache_dir, 'caching.experiment': experiment}) __setup_expr_dir(cache_dir, experiment) @@ -31,7 +29,7 @@ def __set_up_parser(): def __setup_config_dir(config_dir): success = __mk_dir('config', config_dir) if success: - copyfile('EVSVesuvio/config/vesuvio.user.properties', f'{config_dir}/{VESUVIO_CONFIG_FILE}') + copyfile('EVSVesuvio/config/vesuvio.user.properties', f'{config_dir}/{handle_config.VESUVIO_CONFIG_FILE}') return success @@ -51,26 +49,6 @@ def __mk_dir(type, path): return success -def __set_config_vars(config_dir, var_dict): - file_path = f'{config_dir}/{VESUVIO_CONFIG_FILE}' - with open(file_path, 'r') as file: - lines = file.readlines() - - updated_lines = [] - for line in lines: - match = False - for var in var_dict: - if line.startswith(var): - updated_lines.append(f'{var}={var_dict[var]}\n') - match = True - break - if not match: - updated_lines.append(line) - - with open(file_path, 'w') as file: - file.writelines(updated_lines) - - if __name__ == '__main__': print("test") main() diff --git a/EVSVesuvio/scripts/handle_config.py b/EVSVesuvio/scripts/handle_config.py new file mode 100644 index 00000000..7ea62272 --- /dev/null +++ b/EVSVesuvio/scripts/handle_config.py @@ -0,0 +1,39 @@ +import os + +VESUVIO_CONFIG_PATH = os.path.join(os.path.expanduser("~"), '.mvesuvio') +VESUVIO_CONFIG_FILE = "vesuvio.user.properties" + + +def set_config_vars(var_dict): + file_path = f'{VESUVIO_CONFIG_PATH}/{VESUVIO_CONFIG_FILE}' + with open(file_path, 'r') as file: + lines = file.readlines() + + updated_lines = [] + for line in lines: + match = False + for var in var_dict: + if line.startswith(var): + updated_lines.append(f'{var}={var_dict[var]}') + match = True + break + if not match: + updated_lines.append(line) + + with open(file_path, 'w') as file: + file.writelines(updated_lines) + + +def read_config_var(var): + file_path = f'{VESUVIO_CONFIG_PATH}/{VESUVIO_CONFIG_FILE}' + with open(file_path, 'r') as file: + lines = file.readlines() + + result = "" + for line in lines: + if line.startswith(var): + result = line.split("=", 2)[1].strip('\n') + break + if not result: + raise ValueError(f'{var} was not found in the vesuvio config') + return result diff --git a/EVSVesuvio/vesuvio_analysis/core_functions/ICHelpers.py b/EVSVesuvio/vesuvio_analysis/core_functions/ICHelpers.py index a823bc5c..fe5bff8c 100644 --- a/EVSVesuvio/vesuvio_analysis/core_functions/ICHelpers.py +++ b/EVSVesuvio/vesuvio_analysis/core_functions/ICHelpers.py @@ -1,8 +1,8 @@ from mantid.simpleapi import LoadVesuvio, SaveNexus from pathlib import Path +from EVSVesuvio.scripts import handle_config -currentPath = Path(__file__).absolute().parent -experimentsPath = currentPath / ".."/ ".." / "experiments" +experimentsPath = Path(handle_config.read_config_var('caching.location')) / "experiments" def completeICFromInputs(IC, scriptName, wsIC): @@ -163,7 +163,6 @@ def setBootstrapDirs(bckwdIC, fwdIC, bootIC, yFitIC): # Select script name and experiments path sampleName = bckwdIC.scriptName # Name of sample currently running - experimentsPath = currentPath/".."/".."/"experiments" # Used to store running times required to estimate Bootstrap total run time. bootIC.runTimesPath = experimentsPath / sampleName / "running_times.txt" diff --git a/EVSVesuvio/vesuvio_analysis/core_functions/bootstrap_analysis.py b/EVSVesuvio/vesuvio_analysis/core_functions/bootstrap_analysis.py index f143dbe7..b3e738c4 100644 --- a/EVSVesuvio/vesuvio_analysis/core_functions/bootstrap_analysis.py +++ b/EVSVesuvio/vesuvio_analysis/core_functions/bootstrap_analysis.py @@ -4,13 +4,8 @@ from EVSVesuvio.vesuvio_analysis.core_functions.fit_in_yspace import selectModelAndPars import numpy as np import matplotlib .pyplot as plt -from pathlib import Path from scipy import stats -currentPath = Path(__file__).parent.absolute() -experimentsPath = currentPath / ".." / ".. " / "experiments" -IPFilesPath = currentPath / ".." / "ip_files" - def runAnalysisOfStoredBootstrap(bckwdIC, fwdIC, yFitIC, bootIC, analysisIC, userCtr):