Skip to content

Commit 6a39a0e

Browse files
committed
ammend script to work with cache dir
1 parent 292adc5 commit 6a39a0e

File tree

5 files changed

+52
-40
lines changed

5 files changed

+52
-40
lines changed

EVSVesuvio/original_inputs.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import time
22
import numpy as np
33
from pathlib import Path
4-
from vesuvio_analysis.core_functions.bootstrap import runBootstrap
5-
from vesuvio_analysis.core_functions.bootstrap_analysis import runAnalysisOfStoredBootstrap
6-
from vesuvio_analysis.core_functions.run_script import runScript
4+
from EVSVesuvio.vesuvio_analysis.core_functions.bootstrap import runBootstrap
5+
from EVSVesuvio.vesuvio_analysis.core_functions.bootstrap_analysis import runAnalysisOfStoredBootstrap
6+
from EVSVesuvio.vesuvio_analysis.core_functions.run_script import runScript
77
from mantid.api import AnalysisDataService
8+
from EVSVesuvio.scripts import handle_config
89

9-
scriptName = Path(__file__).name.split(".")[0] # Take out .py
10-
experimentPath = Path(__file__).absolute().parent / "experiments" / scriptName # Path to the repository
10+
scriptName = handle_config.read_config_var('caching.experiment')
11+
experimentsPath = Path(handle_config.read_config_var('caching.location')) / "experiments" / scriptName # Path to the repository
1112
ipFilesPath = Path(__file__).absolute().parent / "vesuvio_analysis" / "ip_files"
1213

1314

EVSVesuvio/scripts/__init__.py

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1-
"""Package defining top-level application
2-
and entry points.
1+
"""Package defining entry points.
32
"""
43
import argparse
54
import os
65
from shutil import copyfile
7-
8-
VESUVIO_CONFIG_FILE = "vesuvio.user.properties"
6+
from EVSVesuvio.scripts import handle_config
97

108

119
def main():
1210
parser = __set_up_parser()
1311
args = parser.parse_args()
14-
config_dir = os.path.join(os.path.expanduser("~"), '.mvesuvio')
12+
config_dir = handle_config.VESUVIO_CONFIG_PATH
1513
cache_dir = config_dir if not args.set_cache else args.set_cache
1614
experiment = "default" if not args.set_experiment else args.set_experiment
1715

1816
if __setup_config_dir(config_dir):
19-
__set_config_vars(config_dir, {'caching.location': cache_dir,
17+
handle_config.set_config_vars({'caching.location': cache_dir,
2018
'caching.experiment': experiment})
2119
__setup_expr_dir(cache_dir, experiment)
2220

@@ -31,7 +29,7 @@ def __set_up_parser():
3129
def __setup_config_dir(config_dir):
3230
success = __mk_dir('config', config_dir)
3331
if success:
34-
copyfile('EVSVesuvio/config/vesuvio.user.properties', f'{config_dir}/{VESUVIO_CONFIG_FILE}')
32+
copyfile('EVSVesuvio/config/vesuvio.user.properties', f'{config_dir}/{handle_config.VESUVIO_CONFIG_FILE}')
3533
return success
3634

3735

@@ -51,26 +49,6 @@ def __mk_dir(type, path):
5149
return success
5250

5351

54-
def __set_config_vars(config_dir, var_dict):
55-
file_path = f'{config_dir}/{VESUVIO_CONFIG_FILE}'
56-
with open(file_path, 'r') as file:
57-
lines = file.readlines()
58-
59-
updated_lines = []
60-
for line in lines:
61-
match = False
62-
for var in var_dict:
63-
if line.startswith(var):
64-
updated_lines.append(f'{var}={var_dict[var]}\n')
65-
match = True
66-
break
67-
if not match:
68-
updated_lines.append(line)
69-
70-
with open(file_path, 'w') as file:
71-
file.writelines(updated_lines)
72-
73-
7452
if __name__ == '__main__':
7553
print("test")
7654
main()

EVSVesuvio/scripts/handle_config.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import os
2+
3+
VESUVIO_CONFIG_PATH = os.path.join(os.path.expanduser("~"), '.mvesuvio')
4+
VESUVIO_CONFIG_FILE = "vesuvio.user.properties"
5+
6+
7+
def set_config_vars(var_dict):
8+
file_path = f'{VESUVIO_CONFIG_PATH}/{VESUVIO_CONFIG_FILE}'
9+
with open(file_path, 'r') as file:
10+
lines = file.readlines()
11+
12+
updated_lines = []
13+
for line in lines:
14+
match = False
15+
for var in var_dict:
16+
if line.startswith(var):
17+
updated_lines.append(f'{var}={var_dict[var]}')
18+
match = True
19+
break
20+
if not match:
21+
updated_lines.append(line)
22+
23+
with open(file_path, 'w') as file:
24+
file.writelines(updated_lines)
25+
26+
27+
def read_config_var(var):
28+
file_path = f'{VESUVIO_CONFIG_PATH}/{VESUVIO_CONFIG_FILE}'
29+
with open(file_path, 'r') as file:
30+
lines = file.readlines()
31+
32+
result = ""
33+
for line in lines:
34+
if line.startswith(var):
35+
result = line.split("=", 2)[1].strip('\n')
36+
break
37+
if not result:
38+
raise ValueError(f'{var} was not found in the vesuvio config')
39+
return result

EVSVesuvio/vesuvio_analysis/core_functions/ICHelpers.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from mantid.simpleapi import LoadVesuvio, SaveNexus
22
from pathlib import Path
3+
from EVSVesuvio.scripts import handle_config
34

4-
currentPath = Path(__file__).absolute().parent
5-
experimentsPath = currentPath / ".."/ ".." / "experiments"
5+
experimentsPath = Path(handle_config.read_config_var('caching.location')) / "experiments"
66

77

88
def completeICFromInputs(IC, scriptName, wsIC):
@@ -163,7 +163,6 @@ def setBootstrapDirs(bckwdIC, fwdIC, bootIC, yFitIC):
163163

164164
# Select script name and experiments path
165165
sampleName = bckwdIC.scriptName # Name of sample currently running
166-
experimentsPath = currentPath/".."/".."/"experiments"
167166

168167
# Used to store running times required to estimate Bootstrap total run time.
169168
bootIC.runTimesPath = experimentsPath / sampleName / "running_times.txt"

EVSVesuvio/vesuvio_analysis/core_functions/bootstrap_analysis.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@
44
from EVSVesuvio.vesuvio_analysis.core_functions.fit_in_yspace import selectModelAndPars
55
import numpy as np
66
import matplotlib .pyplot as plt
7-
from pathlib import Path
87
from scipy import stats
98

10-
currentPath = Path(__file__).parent.absolute()
11-
experimentsPath = currentPath / ".." / ".. " / "experiments"
12-
IPFilesPath = currentPath / ".." / "ip_files"
13-
149

1510
def runAnalysisOfStoredBootstrap(bckwdIC, fwdIC, yFitIC, bootIC, analysisIC, userCtr):
1611

0 commit comments

Comments
 (0)