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

Commit 1323131

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

File tree

2 files changed

+112
-32
lines changed

2 files changed

+112
-32
lines changed

NDXINTER/reduce.py

Lines changed: 98 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,38 @@
1717
import numpy as np
1818
import reduce_vars as web_var
1919
import os
20+
import json
2021

2122
def main(input_file, output_dir):
2223
standard_params = web_var.standard_vars
2324
advanced_params = web_var.advanced_vars
25+
2426
config['defaultsave.directory'] = output_dir
2527

28+
angle = get_angle()
29+
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)
30+
2631
alg=AlgorithmManager.create("ReflectometryISISLoadAndProcess")
2732
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']
33+
"InputRunList" : input_file,
34+
"FirstTransmissionRunList" : first_transmission_run_list,
35+
"SecondTransmissionRunList" : second_transmission_run_list,
36+
"ThetaIn" : angle,
37+
"DetectorCorrectionType" : detector_correction_type,
38+
"MonitorBackgroundWavelengthMin" : monitor_background_wavelength_min,
39+
"MonitorBackgroundWavelengthMax" : monitor_background_wavelength_max,
40+
"MonitorIntegrationWavelengthMin" : monitor_integration_wavelength_min,
41+
"MonitorIntegrationWavelengthMax" : monitor_integration_wavelength_max,
42+
"WavelengthMin" : wavelength_min,
43+
"WavelengthMax" : wavelength_max,
44+
"I0MonitorIndex" : i_zero_monitor_index,
45+
"AnalysisMode" : analysis_mode,
46+
"StartOverlap" : start_overlap,
47+
"EndOverlap" : end_overlap,
48+
"TransmissionProcessingInstructions" : transmission_processing_instructions,
49+
"ProcessingInstructions" : processing_instructions
4550
}
51+
4652
alg.setProperties(properties)
4753
alg.execute()
4854

@@ -52,6 +58,79 @@ def main(input_file, output_dir):
5258
SaveNexus(OutputWorkspace, os.path.join(output_dir, OutputWorkspace+".nxs"))
5359
SaveNexus(OutputWorkspaceBinned, os.path.join(output_dir, OutputWorkspaceBinned+".nxs"))
5460

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

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

NDXINTER/reduce_vars.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
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
}
2223

0 commit comments

Comments
 (0)