Skip to content

Commit

Permalink
update flake8 config and use black
Browse files Browse the repository at this point in the history
  • Loading branch information
MialLewis committed Dec 15, 2023
1 parent c3b9388 commit 59d14e2
Show file tree
Hide file tree
Showing 21 changed files with 2,043 additions and 1,111 deletions.
4 changes: 2 additions & 2 deletions EVSVesuvio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"""

version_info = (0, 0, 0)
__version__ = '.'.join(map(str, version_info))
__project_url__ = 'https://github.com/mantidproject/vesuvio'
__version__ = ".".join(map(str, version_info))
__project_url__ = "https://github.com/mantidproject/vesuvio"
26 changes: 20 additions & 6 deletions EVSVesuvio/analysis_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@


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
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"
ipFilesPath = Path(handle_config.read_config_var('caching.ipfolder'))
ipFilesPath = Path(handle_config.read_config_var("caching.ipfolder"))
ai = import_from_path(inputs_path, "analysis_inputs")

start_time = time.time()
Expand All @@ -23,10 +27,20 @@ def run(yes_to_all=False):
bootIC = ai.BootstrapInitialConditions
userCtr = ai.UserScriptControls

runScript(userCtr, scriptName, wsBackIC, wsFrontIC, bckwdIC, fwdIC, yFitIC, bootIC, yes_to_all)
runScript(
userCtr,
scriptName,
wsBackIC,
wsFrontIC,
bckwdIC,
fwdIC,
yFitIC,
bootIC,
yes_to_all,
)

end_time = time.time()
print("\nRunning time: ", end_time-start_time, " seconds")
print("\nRunning time: ", end_time - start_time, " seconds")


def import_from_path(path, name):
Expand All @@ -37,5 +51,5 @@ def import_from_path(path, name):
return module


if __name__ == '__main__':
if __name__ == "__main__":
run()
122 changes: 68 additions & 54 deletions EVSVesuvio/config/analysis_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,44 @@

class LoadVesuvioBackParameters:
def __init__(self, ipFilesPath):
self.ipfile=ipFilesPath / "ip2019.par"
self.ipfile = ipFilesPath / "ip2019.par"

runs="43066-43076" # 77K # The numbers of the runs to be analysed
empty_runs="41876-41923" # 77K # The numbers of the empty runs to be subtracted
mode='DoubleDifference'
runs = "43066-43076" # 77K # The numbers of the runs to be analysed
empty_runs = (
"41876-41923" # 77K # The numbers of the empty runs to be subtracted
)
mode = "DoubleDifference"

subEmptyFromRaw = True # Flag to control wether empty ws gets subtracted from raw
scaleEmpty = 1 # None or scaling factor
subEmptyFromRaw = True # Flag to control wether empty ws gets subtracted from raw
scaleEmpty = 1 # None or scaling factor
scaleRaw = 1


class LoadVesuvioFrontParameters:
def __init__(self, ipFilesPath):
self.ipfile=ipFilesPath / "ip2018_3.par"
self.ipfile = ipFilesPath / "ip2018_3.par"

runs='43066-43076' # 100K # The numbers of the runs to be analysed
empty_runs='43868-43911' # 100K # The numbers of the empty runs to be subtracted
mode='SingleDifference'
runs = "43066-43076" # 100K # The numbers of the runs to be analysed
empty_runs = (
"43868-43911" # 100K # The numbers of the empty runs to be subtracted
)
mode = "SingleDifference"

subEmptyFromRaw = False # Flag to control wether empty ws gets subtracted from raw
scaleEmpty = 1 # None or scaling factor
subEmptyFromRaw = False # Flag to control wether empty ws gets subtracted from raw
scaleEmpty = 1 # None or scaling factor
scaleRaw = 1


class GeneralInitialConditions:
"""Used to define initial conditions shared by both Back and Forward scattering"""

# Sample slab parameters
vertical_width, horizontal_width, thickness = 0.1, 0.1, 0.001 # Expressed in meters


class BackwardInitialConditions(GeneralInitialConditions):
def __init__(self, ipFilesPath):
self.InstrParsPath=ipFilesPath / "ip2018_3.par"
self.InstrParsPath = ipFilesPath / "ip2018_3.par"

HToMassIdxRatio = 19.0620008206 # Set to zero or None when H is not present
massIdx = 0
Expand All @@ -45,21 +50,25 @@ def __init__(self, ipFilesPath):
# noOfMasses = len(masses)

# Intensities, NCP widths, NCP centers
initPars = np.array([
1, 12, 0.,
1, 12, 0.,
1, 12.5, 0.
])
bounds = np.array([
[0, np.nan], [8, 16], [-3, 1],
[0, np.nan], [8, 16], [-3, 1],
[0, np.nan], [11, 14], [-3, 1]
])
initPars = np.array([1, 12, 0.0, 1, 12, 0.0, 1, 12.5, 0.0])
bounds = np.array(
[
[0, np.nan],
[8, 16],
[-3, 1],
[0, np.nan],
[8, 16],
[-3, 1],
[0, np.nan],
[11, 14],
[-3, 1],
]
)
constraints = ()

noOfMSIterations = 3 #4
firstSpec = 3 #3
lastSpec = 134 #134
noOfMSIterations = 3 # 4
firstSpec = 3 # 3
lastSpec = 134 # 134

maskedSpecAllNo = np.array([18, 34, 42, 43, 59, 60, 62, 118, 119, 133])

Expand All @@ -68,12 +77,12 @@ def __init__(self, ipFilesPath):
GammaCorrectionFlag = False

# # Parameters of workspaces in input_ws
tofBinning='275.,1.,420' # Binning of ToF spectra
tofBinning = "275.,1.,420" # Binning of ToF spectra
maskTOFRange = None

transmission_guess = 0.8537 # Experimental value from VesuvioTransmission
transmission_guess = 0.8537 # Experimental value from VesuvioTransmission
multiple_scattering_order = 2
number_of_events = 1.e5
number_of_events = 1.0e5

# Original data uses histogram data instead of point data
runHistData = True
Expand All @@ -82,41 +91,46 @@ def __init__(self, ipFilesPath):

class ForwardInitialConditions(GeneralInitialConditions):
def __init__(self, ipFilesPath):
self.InstrParsPath=ipFilesPath / "ip2018_3.par"
self.InstrParsPath = ipFilesPath / "ip2018_3.par"

masses = np.array([1.0079, 12, 16, 27])

# Intensities, NCP widths, NCP centers
initPars = np.array([
1, 4.7, 0,
1, 12.71, 0.,
1, 8.76, 0.,
1, 13.897, 0.
])
bounds = np.array([
[0, np.nan], [3, 6], [-3, 1],
[0, np.nan], [12.71, 12.71], [-3, 1],
[0, np.nan], [8.76, 8.76], [-3, 1],
[0, np.nan], [13.897, 13.897], [-3, 1]
])
initPars = np.array([1, 4.7, 0, 1, 12.71, 0.0, 1, 8.76, 0.0, 1, 13.897, 0.0])
bounds = np.array(
[
[0, np.nan],
[3, 6],
[-3, 1],
[0, np.nan],
[12.71, 12.71],
[-3, 1],
[0, np.nan],
[8.76, 8.76],
[-3, 1],
[0, np.nan],
[13.897, 13.897],
[-3, 1],
]
)
constraints = ()

noOfMSIterations = 0 #4
firstSpec = 144 #144
lastSpec = 182 #182
noOfMSIterations = 0 # 4
firstSpec = 144 # 144
lastSpec = 182 # 182

# Boolean Flags to control script
MSCorrectionFlag = True
GammaCorrectionFlag = True

maskedSpecAllNo = np.array([173, 174, 179])

tofBinning="110,1,430" # Binning of ToF spectra
tofBinning = "110,1,430" # Binning of ToF spectra
maskTOFRange = None

transmission_guess = 0.8537 # Experimental value from VesuvioTransmission
transmission_guess = 0.8537 # Experimental value from VesuvioTransmission
multiple_scattering_order = 2
number_of_events = 1.e5
number_of_events = 1.0e5

# Original data uses histogram data instead of point data
runHistData = True
Expand All @@ -126,19 +140,19 @@ def __init__(self, ipFilesPath):
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'
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'
runMinos = True
globalFit = True # Performs global fit with Minuit by default
nGlobalFitGroups = 4 # Number or string "ALL"
maskTypeProcedure = "NAN" # Options: 'NCP', 'NAN', None
globalFit = True # Performs global fit with Minuit by default
nGlobalFitGroups = 4 # Number or string "ALL"
maskTypeProcedure = "NAN" # Options: 'NCP', 'NAN', None


class UserScriptControls:
runRoutine = True

# Choose main procedure to run
procedure = "FORWARD" # Options: None, "BACKWARD", "FORWARD", "JOINT"
procedure = "FORWARD" # Options: None, "BACKWARD", "FORWARD", "JOINT"

# Choose on which ws to perform the fit in y space
fitInYSpace = "FORWARD" # Options: None, "BACKWARD", "FORWARD", "JOINT"
Expand Down
73 changes: 57 additions & 16 deletions EVSVesuvio/scripts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,33 @@ def main():


def __set_up_parser():
parser = argparse.ArgumentParser(description="Package to analyse Vesuvio instrument data")
subparsers = parser.add_subparsers(dest='command', required=True)
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)
config_parser.add_argument("--set-ipfolder", "-p", help="set the intrument parameters directory", default="", type=str)
config_parser.add_argument("--set-experiment", "-e", help="set the current experiment", default="", type=str)
config_parser.add_argument(
"--set-cache", "-c", help="set the cache directory", default="", type=str
)
config_parser.add_argument(
"--set-ipfolder",
"-p",
help="set the intrument parameters directory",
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("--yes", "-y", help="Say yes to all input prompts", action='store_true')
run_parser.add_argument(
"--yes", "-y", help="Say yes to all input prompts", action="store_true"
)
return parser


Expand All @@ -36,28 +54,51 @@ def __setup_config(args):
ipfolder_dir = handle_config.VESUVIO_IPFOLDER_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
ipfolder_dir = handle_config.read_config_var('caching.ipfolder') if not args or not args.set_ipfolder else args.set_ipfolder
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
)
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
ipfolder_dir = ipfolder_dir if not args or not args.set_ipfolder else args.set_ipfolder
experiment = (
"default" if not args or not args.set_experiment else args.set_experiment
)
ipfolder_dir = (
ipfolder_dir if not args or not args.set_ipfolder else args.set_ipfolder
)

handle_config.setup_default_ipfile_dir()

handle_config.set_config_vars({'caching.location': cache_dir,
'caching.experiment': experiment,
'caching.ipfolder': ipfolder_dir})
handle_config.set_config_vars(
{
"caching.location": cache_dir,
"caching.experiment": experiment,
"caching.ipfolder": ipfolder_dir,
}
)
handle_config.setup_expr_dir(cache_dir, experiment)
handle_config.check_dir_exists("IP folder", ipfolder_dir)


def __run_analysis(yes_to_all):
environ['MANTIDPROPERTIES'] = path.join(handle_config.VESUVIO_CONFIG_PATH, "Mantid.user.properties")
environ["MANTIDPROPERTIES"] = path.join(
handle_config.VESUVIO_CONFIG_PATH, "Mantid.user.properties"
)
from EVSVesuvio import analysis_runner

analysis_runner.run(yes_to_all)


if __name__ == '__main__':
if __name__ == "__main__":
main()
Loading

0 comments on commit 59d14e2

Please sign in to comment.