Skip to content

Commit

Permalink
Merge pull request #105 from mantidproject/simplifying-directories
Browse files Browse the repository at this point in the history
Changing user experience
  • Loading branch information
GuiMacielPereira authored Apr 10, 2024
2 parents 0373209 + feeb473 commit 7faf09a
Show file tree
Hide file tree
Showing 25 changed files with 172 additions and 131 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ci_tests_nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
python -m unittest discover -s ./mvesuvio/system_tests
3 changes: 1 addition & 2 deletions .github/workflows/pr_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -54,4 +53,4 @@ jobs:
# Report coverage
#- name: Report Coverage
# run: coverage report
# run: coverage report
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 7 additions & 13 deletions mvesuvio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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):
Expand Down
1 change: 1 addition & 0 deletions mvesuvio/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.0.0"
10 changes: 2 additions & 8 deletions mvesuvio/analysis_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -29,7 +24,6 @@ def run(yes_to_all=False):

runScript(
userCtr,
scriptName,
wsBackIC,
wsFrontIC,
bckwdIC,
Expand Down
13 changes: 12 additions & 1 deletion mvesuvio/config/analysis_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand 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()
3 changes: 1 addition & 2 deletions mvesuvio/config/vesuvio.user.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# properties that suit your particular installation.
caching.location=
caching.experiment=
caching.inputs=
caching.ipfolder=
35 changes: 12 additions & 23 deletions mvesuvio/scripts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,21 @@ 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"
)
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",
Expand All @@ -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(
Expand All @@ -55,42 +50,36 @@ 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")
if not args or not args.set_ipfolder
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)


Expand Down
21 changes: 11 additions & 10 deletions mvesuvio/scripts/handle_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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:
Expand All @@ -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),
)


Expand All @@ -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}")
Expand Down
9 changes: 6 additions & 3 deletions mvesuvio/system_tests/test_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"))

Expand All @@ -38,7 +42,6 @@ def get_current_result(cls):
def _run(cls):
scattRes, yfitRes = runScript(
UserScriptControls(),
"test_expr",
LoadVesuvioBackParameters(ipFilesPath),
LoadVesuvioFrontParameters(ipFilesPath),
BackwardInitialConditions(ipFilesPath),
Expand Down
8 changes: 5 additions & 3 deletions mvesuvio/system_tests/test_bootstrap.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@

# 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,
fwdIC,
yFitIC,
)


class BootstrapInitialConditions:
runBootstrap = True

Expand Down Expand Up @@ -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
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 0 additions & 4 deletions mvesuvio/system_tests/test_config/vesuvio.user.properties

This file was deleted.

7 changes: 5 additions & 2 deletions mvesuvio/system_tests/test_jackknife.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 7faf09a

Please sign in to comment.