Skip to content

Commit 184cf2e

Browse files
authored
Merge pull request #82 from mantidproject/0_satisfy_flake8
Satisfy flake 8 and run black to improve formatting quality.
2 parents f104985 + 59d14e2 commit 184cf2e

21 files changed

+2043
-1111
lines changed

EVSVesuvio/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
"""
88

99
version_info = (0, 0, 0)
10-
__version__ = '.'.join(map(str, version_info))
11-
__project_url__ = 'https://github.com/mantidproject/vesuvio'
10+
__version__ = ".".join(map(str, version_info))
11+
__project_url__ = "https://github.com/mantidproject/vesuvio"

EVSVesuvio/analysis_runner.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@
77

88

99
def run(yes_to_all=False):
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
10+
scriptName = handle_config.read_config_var("caching.experiment")
11+
experimentsPath = (
12+
Path(handle_config.read_config_var("caching.location"))
13+
/ "experiments"
14+
/ scriptName
15+
) # Path to the repository
1216
inputs_path = experimentsPath / "analysis_inputs.py"
13-
ipFilesPath = Path(handle_config.read_config_var('caching.ipfolder'))
17+
ipFilesPath = Path(handle_config.read_config_var("caching.ipfolder"))
1418
ai = import_from_path(inputs_path, "analysis_inputs")
1519

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

26-
runScript(userCtr, scriptName, wsBackIC, wsFrontIC, bckwdIC, fwdIC, yFitIC, bootIC, yes_to_all)
30+
runScript(
31+
userCtr,
32+
scriptName,
33+
wsBackIC,
34+
wsFrontIC,
35+
bckwdIC,
36+
fwdIC,
37+
yFitIC,
38+
bootIC,
39+
yes_to_all,
40+
)
2741

2842
end_time = time.time()
29-
print("\nRunning time: ", end_time-start_time, " seconds")
43+
print("\nRunning time: ", end_time - start_time, " seconds")
3044

3145

3246
def import_from_path(path, name):
@@ -37,5 +51,5 @@ def import_from_path(path, name):
3751
return module
3852

3953

40-
if __name__ == '__main__':
54+
if __name__ == "__main__":
4155
run()

EVSVesuvio/config/analysis_inputs.py

Lines changed: 68 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,44 @@
33

44
class LoadVesuvioBackParameters:
55
def __init__(self, ipFilesPath):
6-
self.ipfile=ipFilesPath / "ip2019.par"
6+
self.ipfile = ipFilesPath / "ip2019.par"
77

8-
runs="43066-43076" # 77K # The numbers of the runs to be analysed
9-
empty_runs="41876-41923" # 77K # The numbers of the empty runs to be subtracted
10-
mode='DoubleDifference'
8+
runs = "43066-43076" # 77K # The numbers of the runs to be analysed
9+
empty_runs = (
10+
"41876-41923" # 77K # The numbers of the empty runs to be subtracted
11+
)
12+
mode = "DoubleDifference"
1113

12-
subEmptyFromRaw = True # Flag to control wether empty ws gets subtracted from raw
13-
scaleEmpty = 1 # None or scaling factor
14+
subEmptyFromRaw = True # Flag to control wether empty ws gets subtracted from raw
15+
scaleEmpty = 1 # None or scaling factor
1416
scaleRaw = 1
1517

1618

1719
class LoadVesuvioFrontParameters:
1820
def __init__(self, ipFilesPath):
19-
self.ipfile=ipFilesPath / "ip2018_3.par"
21+
self.ipfile = ipFilesPath / "ip2018_3.par"
2022

21-
runs='43066-43076' # 100K # The numbers of the runs to be analysed
22-
empty_runs='43868-43911' # 100K # The numbers of the empty runs to be subtracted
23-
mode='SingleDifference'
23+
runs = "43066-43076" # 100K # The numbers of the runs to be analysed
24+
empty_runs = (
25+
"43868-43911" # 100K # The numbers of the empty runs to be subtracted
26+
)
27+
mode = "SingleDifference"
2428

25-
subEmptyFromRaw = False # Flag to control wether empty ws gets subtracted from raw
26-
scaleEmpty = 1 # None or scaling factor
29+
subEmptyFromRaw = False # Flag to control wether empty ws gets subtracted from raw
30+
scaleEmpty = 1 # None or scaling factor
2731
scaleRaw = 1
2832

2933

3034
class GeneralInitialConditions:
3135
"""Used to define initial conditions shared by both Back and Forward scattering"""
36+
3237
# Sample slab parameters
3338
vertical_width, horizontal_width, thickness = 0.1, 0.1, 0.001 # Expressed in meters
3439

3540

3641
class BackwardInitialConditions(GeneralInitialConditions):
3742
def __init__(self, ipFilesPath):
38-
self.InstrParsPath=ipFilesPath / "ip2018_3.par"
43+
self.InstrParsPath = ipFilesPath / "ip2018_3.par"
3944

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

4752
# Intensities, NCP widths, NCP centers
48-
initPars = np.array([
49-
1, 12, 0.,
50-
1, 12, 0.,
51-
1, 12.5, 0.
52-
])
53-
bounds = np.array([
54-
[0, np.nan], [8, 16], [-3, 1],
55-
[0, np.nan], [8, 16], [-3, 1],
56-
[0, np.nan], [11, 14], [-3, 1]
57-
])
53+
initPars = np.array([1, 12, 0.0, 1, 12, 0.0, 1, 12.5, 0.0])
54+
bounds = np.array(
55+
[
56+
[0, np.nan],
57+
[8, 16],
58+
[-3, 1],
59+
[0, np.nan],
60+
[8, 16],
61+
[-3, 1],
62+
[0, np.nan],
63+
[11, 14],
64+
[-3, 1],
65+
]
66+
)
5867
constraints = ()
5968

60-
noOfMSIterations = 3 #4
61-
firstSpec = 3 #3
62-
lastSpec = 134 #134
69+
noOfMSIterations = 3 # 4
70+
firstSpec = 3 # 3
71+
lastSpec = 134 # 134
6372

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

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

7079
# # Parameters of workspaces in input_ws
71-
tofBinning='275.,1.,420' # Binning of ToF spectra
80+
tofBinning = "275.,1.,420" # Binning of ToF spectra
7281
maskTOFRange = None
7382

74-
transmission_guess = 0.8537 # Experimental value from VesuvioTransmission
83+
transmission_guess = 0.8537 # Experimental value from VesuvioTransmission
7584
multiple_scattering_order = 2
76-
number_of_events = 1.e5
85+
number_of_events = 1.0e5
7786

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

8392
class ForwardInitialConditions(GeneralInitialConditions):
8493
def __init__(self, ipFilesPath):
85-
self.InstrParsPath=ipFilesPath / "ip2018_3.par"
94+
self.InstrParsPath = ipFilesPath / "ip2018_3.par"
8695

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

8998
# Intensities, NCP widths, NCP centers
90-
initPars = np.array([
91-
1, 4.7, 0,
92-
1, 12.71, 0.,
93-
1, 8.76, 0.,
94-
1, 13.897, 0.
95-
])
96-
bounds = np.array([
97-
[0, np.nan], [3, 6], [-3, 1],
98-
[0, np.nan], [12.71, 12.71], [-3, 1],
99-
[0, np.nan], [8.76, 8.76], [-3, 1],
100-
[0, np.nan], [13.897, 13.897], [-3, 1]
101-
])
99+
initPars = np.array([1, 4.7, 0, 1, 12.71, 0.0, 1, 8.76, 0.0, 1, 13.897, 0.0])
100+
bounds = np.array(
101+
[
102+
[0, np.nan],
103+
[3, 6],
104+
[-3, 1],
105+
[0, np.nan],
106+
[12.71, 12.71],
107+
[-3, 1],
108+
[0, np.nan],
109+
[8.76, 8.76],
110+
[-3, 1],
111+
[0, np.nan],
112+
[13.897, 13.897],
113+
[-3, 1],
114+
]
115+
)
102116
constraints = ()
103117

104-
noOfMSIterations = 0 #4
105-
firstSpec = 144 #144
106-
lastSpec = 182 #182
118+
noOfMSIterations = 0 # 4
119+
firstSpec = 144 # 144
120+
lastSpec = 182 # 182
107121

108122
# Boolean Flags to control script
109123
MSCorrectionFlag = True
110124
GammaCorrectionFlag = True
111125

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

114-
tofBinning="110,1,430" # Binning of ToF spectra
128+
tofBinning = "110,1,430" # Binning of ToF spectra
115129
maskTOFRange = None
116130

117-
transmission_guess = 0.8537 # Experimental value from VesuvioTransmission
131+
transmission_guess = 0.8537 # Experimental value from VesuvioTransmission
118132
multiple_scattering_order = 2
119-
number_of_events = 1.e5
133+
number_of_events = 1.0e5
120134

121135
# Original data uses histogram data instead of point data
122136
runHistData = True
@@ -126,19 +140,19 @@ def __init__(self, ipFilesPath):
126140
class YSpaceFitInitialConditions:
127141
showPlots = True
128142
symmetrisationFlag = True
129-
rebinParametersForYSpaceFit = "-25, 0.5, 25" # Needs to be symetric
130-
fitModel = "Gaussian3D" # Options: 'SINGLE_GAUSSIAN', 'GC_C4', 'GC_C6', 'GC_C4_C6', 'DOUBLE_WELL', 'ANSIO_GAUSSIAN', 'Gaussian3D'
143+
rebinParametersForYSpaceFit = "-25, 0.5, 25" # Needs to be symetric
144+
fitModel = "Gaussian3D" # Options: 'SINGLE_GAUSSIAN', 'GC_C4', 'GC_C6', 'GC_C4_C6', 'DOUBLE_WELL', 'ANSIO_GAUSSIAN', 'Gaussian3D'
131145
runMinos = True
132-
globalFit = True # Performs global fit with Minuit by default
133-
nGlobalFitGroups = 4 # Number or string "ALL"
134-
maskTypeProcedure = "NAN" # Options: 'NCP', 'NAN', None
146+
globalFit = True # Performs global fit with Minuit by default
147+
nGlobalFitGroups = 4 # Number or string "ALL"
148+
maskTypeProcedure = "NAN" # Options: 'NCP', 'NAN', None
135149

136150

137151
class UserScriptControls:
138152
runRoutine = True
139153

140154
# Choose main procedure to run
141-
procedure = "FORWARD" # Options: None, "BACKWARD", "FORWARD", "JOINT"
155+
procedure = "FORWARD" # Options: None, "BACKWARD", "FORWARD", "JOINT"
142156

143157
# Choose on which ws to perform the fit in y space
144158
fitInYSpace = "FORWARD" # Options: None, "BACKWARD", "FORWARD", "JOINT"

EVSVesuvio/scripts/__init__.py

Lines changed: 57 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,33 @@ def main():
1818

1919

2020
def __set_up_parser():
21-
parser = argparse.ArgumentParser(description="Package to analyse Vesuvio instrument data")
22-
subparsers = parser.add_subparsers(dest='command', required=True)
21+
parser = argparse.ArgumentParser(
22+
description="Package to analyse Vesuvio instrument data"
23+
)
24+
subparsers = parser.add_subparsers(dest="command", required=True)
2325
config_parser = subparsers.add_parser("config", help="set mvesuvio configuration")
24-
config_parser.add_argument("--set-cache", "-c", help="set the cache directory", default="", type=str)
25-
config_parser.add_argument("--set-ipfolder", "-p", help="set the intrument parameters directory", default="", type=str)
26-
config_parser.add_argument("--set-experiment", "-e", help="set the current experiment", default="", type=str)
26+
config_parser.add_argument(
27+
"--set-cache", "-c", help="set the cache directory", default="", type=str
28+
)
29+
config_parser.add_argument(
30+
"--set-ipfolder",
31+
"-p",
32+
help="set the intrument parameters directory",
33+
default="",
34+
type=str,
35+
)
36+
config_parser.add_argument(
37+
"--set-experiment",
38+
"-e",
39+
help="set the current experiment",
40+
default="",
41+
type=str,
42+
)
2743

2844
run_parser = subparsers.add_parser("run", help="run mvesuvio analysis")
29-
run_parser.add_argument("--yes", "-y", help="Say yes to all input prompts", action='store_true')
45+
run_parser.add_argument(
46+
"--yes", "-y", help="Say yes to all input prompts", action="store_true"
47+
)
3048
return parser
3149

3250

@@ -36,28 +54,51 @@ def __setup_config(args):
3654
ipfolder_dir = handle_config.VESUVIO_IPFOLDER_PATH
3755

3856
if handle_config.config_set():
39-
cache_dir = handle_config.read_config_var('caching.location') if not args or not args.set_cache else args.set_cache
40-
experiment = handle_config.read_config_var('caching.experiment') if not args or not args.set_experiment else args.set_experiment
41-
ipfolder_dir = handle_config.read_config_var('caching.ipfolder') if not args or not args.set_ipfolder else args.set_ipfolder
57+
cache_dir = (
58+
handle_config.read_config_var("caching.location")
59+
if not args or not args.set_cache
60+
else args.set_cache
61+
)
62+
experiment = (
63+
handle_config.read_config_var("caching.experiment")
64+
if not args or not args.set_experiment
65+
else args.set_experiment
66+
)
67+
ipfolder_dir = (
68+
handle_config.read_config_var("caching.ipfolder")
69+
if not args or not args.set_ipfolder
70+
else args.set_ipfolder
71+
)
4272
else:
4373
cache_dir = config_dir if not args or not args.set_cache else args.set_cache
44-
experiment = "default" if not args or not args.set_experiment else args.set_experiment
45-
ipfolder_dir = ipfolder_dir if not args or not args.set_ipfolder else args.set_ipfolder
74+
experiment = (
75+
"default" if not args or not args.set_experiment else args.set_experiment
76+
)
77+
ipfolder_dir = (
78+
ipfolder_dir if not args or not args.set_ipfolder else args.set_ipfolder
79+
)
4680

4781
handle_config.setup_default_ipfile_dir()
4882

49-
handle_config.set_config_vars({'caching.location': cache_dir,
50-
'caching.experiment': experiment,
51-
'caching.ipfolder': ipfolder_dir})
83+
handle_config.set_config_vars(
84+
{
85+
"caching.location": cache_dir,
86+
"caching.experiment": experiment,
87+
"caching.ipfolder": ipfolder_dir,
88+
}
89+
)
5290
handle_config.setup_expr_dir(cache_dir, experiment)
5391
handle_config.check_dir_exists("IP folder", ipfolder_dir)
5492

5593

5694
def __run_analysis(yes_to_all):
57-
environ['MANTIDPROPERTIES'] = path.join(handle_config.VESUVIO_CONFIG_PATH, "Mantid.user.properties")
95+
environ["MANTIDPROPERTIES"] = path.join(
96+
handle_config.VESUVIO_CONFIG_PATH, "Mantid.user.properties"
97+
)
5898
from EVSVesuvio import analysis_runner
99+
59100
analysis_runner.run(yes_to_all)
60101

61102

62-
if __name__ == '__main__':
103+
if __name__ == "__main__":
63104
main()

0 commit comments

Comments
 (0)