Skip to content
This repository was archived by the owner on Nov 14, 2022. It is now read-only.

Commit 739dfe9

Browse files
committed
Add parsing settings from JSON and reading angle
1 parent 119742d commit 739dfe9

File tree

2 files changed

+112
-46
lines changed

2 files changed

+112
-46
lines changed

NDXINTER/reduce.py

Lines changed: 98 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,41 @@
1-
import sys
2-
3-
sys.path.append('/opt/Mantid/scripts')
4-
sys.path.append('/opt/Mantid/scripts/SANS')
5-
sys.path.append('/opt/Mantid/lib')
6-
sys.path.append('/opt/Mantid/scripts/Inelastic')
7-
sys.path.append('/opt/Mantid/scripts/Engineering')
8-
sys.path.append('/opt/Mantid/scripts/Interface')
9-
sys.path.append('/opt/Mantid/scripts/Diffraction')
10-
11-
AUTOREDUCTION_DIR = r"/autoreduce/data-archive/NDXINTER/user/scripts/autoreduction"
12-
sys.path.append(AUTOREDUCTION_DIR)
13-
141
# import mantid algorithms, numpy and matplotlib
152
from mantid.simpleapi import *
163
import matplotlib.pyplot as plt
174
import numpy as np
185
import reduce_vars as web_var
196
import os
7+
import json
208

219
def main(input_file, output_dir):
2210
standard_params = web_var.standard_vars
2311
advanced_params = web_var.advanced_vars
12+
2413
config['defaultsave.directory'] = output_dir
2514

15+
angle = get_angle()
16+
analysis_mode,first_transmission_run_list,second_transmission_run_list,transmission_processing_instructions,processing_instructions,start_overlap,end_overlap,monitor_integration_wavelength_min,monitor_integration_wavelength_max,monitor_background_wavelength_min,monitor_background_wavelength_max,wavelength_min,wavelength_max,i_zero_monitor_index,detector_correction_type = parse_json_settings(angle)
17+
2618
alg=AlgorithmManager.create("ReflectometryISISLoadAndProcess")
2719
properties = {
28-
"InputRunList" : standard_params['input_run_list'],
29-
"FirstTransmissionRunList" : standard_params['first_transmission_run_list'],
30-
"SecondTransmissionRunList" : standard_params['second_transmission_run_list'],
31-
"ThetaIn" : standard_params['theta_in'],
32-
"DetectorCorrectionType" : standard_params['detector_correction_type'],
33-
"MonitorBackgroundWavelengthMin" : standard_params['monitor_background_wavelength_min'],
34-
"MonitorBackgroundWavelengthMax" : standard_params['monitor_background_wavelength_max'],
35-
"MonitorIntegrationWavelengthMin" : standard_params['MonitorIntegrationWavelengthMin'],
36-
"MonitorIntegrationWavelengthMax" : standard_params['MonitorIntegrationWavelengthMax'],
37-
"WavelengthMin" : standard_params['WavelengthMin'],
38-
"WavelengthMax" : standard_params['WavelengthMax'],
39-
"I0MonitorIndex" : standard_params['IZeroMonitorIndex'],
40-
"AnalysisMode" : standard_params['analysis_mode'],
41-
"StartOverlap" : standard_params['StartOverlap'],
42-
"EndOverlap" : standard_params['EndOverlap'],
43-
"TransmissionProcessingInstructions" : standard_params['transmission_processing_instructions'],
44-
"ProcessingInstructions" : standard_params['processing_instructions']
20+
"InputRunList" : input_file,
21+
"FirstTransmissionRunList" : first_transmission_run_list,
22+
"SecondTransmissionRunList" : second_transmission_run_list,
23+
"ThetaIn" : angle,
24+
"DetectorCorrectionType" : detector_correction_type,
25+
"MonitorBackgroundWavelengthMin" : monitor_background_wavelength_min,
26+
"MonitorBackgroundWavelengthMax" : monitor_background_wavelength_max,
27+
"MonitorIntegrationWavelengthMin" : monitor_integration_wavelength_min,
28+
"MonitorIntegrationWavelengthMax" : monitor_integration_wavelength_max,
29+
"WavelengthMin" : wavelength_min,
30+
"WavelengthMax" : wavelength_max,
31+
"I0MonitorIndex" : i_zero_monitor_index,
32+
"AnalysisMode" : analysis_mode,
33+
"StartOverlap" : start_overlap,
34+
"EndOverlap" : end_overlap,
35+
"TransmissionProcessingInstructions" : transmission_processing_instructions,
36+
"ProcessingInstructions" : processing_instructions
4537
}
38+
4639
alg.setProperties(properties)
4740
alg.execute()
4841

@@ -52,6 +45,79 @@ def main(input_file, output_dir):
5245
SaveNexus(OutputWorkspace, os.path.join(output_dir, OutputWorkspace+".nxs"))
5346
SaveNexus(OutputWorkspaceBinned, os.path.join(output_dir, OutputWorkspaceBinned+".nxs"))
5447

55-
if __name__ == "__main__":
56-
main('', '')
48+
def get_angle():
49+
ws=Load('INTER61668')
50+
title = (ws.run().getProperty('run_title').value)
51+
angle = title.split(" th=")[1].split()[0]
52+
return angle
53+
54+
def parse_json_settings(angle):
55+
"""
56+
Autoreduction get settings from JSON file
57+
"""
58+
json_input = r"C:\Users\wyf59278\Documents\repos\reflectometry_reduction\settings.json"
59+
60+
with open(json_input, "r") as read_file:
61+
data = json.load(read_file)
62+
63+
experimentView = data["experimentView"]
64+
65+
if experimentView["analysisModeComboBox"] == 1:
66+
analysis_mode = "MultiDetectorAnalysis"
67+
elif experimentView["analysisModeComboBox"] == 0:
68+
analysis_mode = "PointDetectorAnalysis"
69+
else:
70+
raise Exception # If the value isn't 1 or 0 then it isn't valid
71+
72+
perAngleDefaults = experimentView["perAngleDefaults"]
73+
rows = perAngleDefaults["rows"]
74+
75+
# This looks for the run angle and set other parameters accordingly
76+
angle_found = False
77+
for i in rows:
78+
if i[0] == angle:
79+
angle_found = True
80+
first_transmission_run_list = i[1]
81+
second_transmission_run_list = i[2]
82+
transmission_processing_instructions = i[3]
83+
processing_instructions = i[8]
84+
break
85+
86+
# This is the default case
87+
if not angle_found:
88+
for i in rows:
89+
if i[0] == "":
90+
angle_found = True
91+
first_transmission_run_list = i[1]
92+
second_transmission_run_list = i[2]
93+
transmission_processing_instructions = i[3]
94+
processing_instructions = i[8]
95+
break
96+
97+
if not angle_found:
98+
raise Exception # Excpetion for if neither a pre-defined angle or the default case are found
99+
100+
start_overlap = experimentView["startOverlapEdit"]
101+
102+
end_overlap = experimentView["endOverlapEdit"]
103+
104+
instrumentView = data["instrumentView"]
105+
106+
monitor_integration_wavelength_min = instrumentView["monIntMinEdit"]
107+
monitor_integration_wavelength_max = instrumentView["monIntMaxEdit"]
108+
monitor_background_wavelength_min = instrumentView["monBgMinEdit"]
109+
monitor_background_wavelength_max = instrumentView["monBgMaxEdit"]
110+
wavelength_min = instrumentView["lamMinEdit"]
111+
wavelength_max = instrumentView["lamMaxEdit"]
112+
i_zero_monitor_index = instrumentView["I0MonitorIndex"]
113+
114+
if instrumentView["detectorCorrectionTypeComboBox"] == 1:
115+
detector_correction_type = "RotateAroundSample"
116+
elif instrumentView["detectorCorrectionTypeComboBox"] == 0:
117+
detector_correction_type = "VerticalShift"
118+
else:
119+
raise Exception # If the value isn't 1 or 0 then it isn't valid
120+
121+
return analysis_mode,first_transmission_run_list,second_transmission_run_list,transmission_processing_instructions,processing_instructions,start_overlap,end_overlap,monitor_integration_wavelength_min,monitor_integration_wavelength_max,monitor_background_wavelength_min,monitor_background_wavelength_max,wavelength_min,wavelength_max,i_zero_monitor_index,detector_correction_type
57122

123+
main('INTER00061668.nxs', r"C:\Users\wyf59278\Documents\reduction")

NDXINTER/reduce_vars.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
standard_vars = {
22
'input_run_list' : "INTER00061667",
3-
'first_transmission_run_list' : "INTER00061705",
4-
'second_transmission_run_list' : "INTER00061669",
53
'theta_in': 0.7,
6-
'detector_correction_type': "RotateAroundSample",
7-
'monitor_background_wavelength_min': 0.0,
8-
'monitor_background_wavelength_max': 1.0,
4+
95
'analysis_mode': "MultiDetectorAnalysis",
6+
'first_transmission_run_list' : "INTER00061705",
7+
'second_transmission_run_list' : "INTER00061669",
108
'transmission_processing_instructions': "76-85",
11-
'processing_instructions': "80-84"
12-
'MonitorIntegrationWavelengthMin' : 4.0,
13-
'MonitorIntegrationWavelengthMax' : 10.0,
14-
'WavelengthMin' : 1.5,
15-
'WavelengthMax' : 17.0,
16-
'StartOverlap' : 10.0,
17-
'EndOverlap' : 12.0,
18-
'IZeroMonitorIndex' : 2
9+
'processing_instructions': "80-84",
10+
'start_overlap' : 10.0,
11+
'end_overlap' : 12.0
1912
}
2013
advanced_vars = {
14+
'monitor_integration_wavelength_min' : 4.0,
15+
'monitor_integration_wavelength_max' : 10.0,
16+
'monitor_background_wavelength_min': 17.0,
17+
'monitor_background_wavelength_max': 18.0,
18+
'wavelength_min' : 1.5,
19+
'wavelength_max' : 17.0,
20+
'i_zero_monitor_index' : 2,
21+
'detector_correction_type': "VerticalShift"
2122
}
22-

0 commit comments

Comments
 (0)