Skip to content

Commit

Permalink
ammend script to work with cache dir
Browse files Browse the repository at this point in the history
  • Loading branch information
MialLewis committed Nov 10, 2023
1 parent 292adc5 commit 6a39a0e
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 40 deletions.
11 changes: 6 additions & 5 deletions EVSVesuvio/original_inputs.py
Original file line number Diff line number Diff line change
@@ -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"


Expand Down
32 changes: 5 additions & 27 deletions EVSVesuvio/scripts/__init__.py
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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


Expand All @@ -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()
39 changes: 39 additions & 0 deletions EVSVesuvio/scripts/handle_config.py
Original file line number Diff line number Diff line change
@@ -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
5 changes: 2 additions & 3 deletions EVSVesuvio/vesuvio_analysis/core_functions/ICHelpers.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down

0 comments on commit 6a39a0e

Please sign in to comment.