Skip to content
Snippets Groups Projects
Commit 8dd1de60 authored by Sam Jenkins's avatar Sam Jenkins
Browse files

Re #24512 added texture mode to focus

parent ff9e1a85
No related branches found
No related tags found
No related merge requests found
...@@ -18,8 +18,8 @@ class EnginX: ...@@ -18,8 +18,8 @@ class EnginX:
self.van_run = kwargs.get("vanadium_run") self.van_run = kwargs.get("vanadium_run")
if "output_directory" in kwargs: if "output_directory" in kwargs:
location = "{0}/{1}/{2}" location = "{0}/{1}/{2}"
self.calibration_directory = location.format(kwargs.get("output_directory"), self.user,"Calibration") self.calibration_directory = location.format(kwargs.get("output_directory"), self.user, "Calibration")
self.focus_directory = location.format(kwargs.get("output_directory"), self.user,Focus) self.focus_directory = location.format(kwargs.get("output_directory"), self.user, "Focus")
else: else:
raise KeyError("You must set an output_directory") raise KeyError("You must set an output_directory")
...@@ -51,14 +51,18 @@ class EnginX: ...@@ -51,14 +51,18 @@ class EnginX:
if "run_number" in kwargs: if "run_number" in kwargs:
run_no = kwargs.get("run_number") run_no = kwargs.get("run_number")
else: else:
return raise KeyError("Cannot focus without run_number")
van_curves_file, van_int_file = self._get_van_names() van_curves_file, van_int_file = self._get_van_names()
if "cropped" in kwargs: if "grouping_file" in kwargs:
grouping_file = os.path.join(self.calibration_directory, kwargs.get("grouping_file"))
Focus.focus_texture_mode(van_curves_file, van_int_file, run_no,
self.focus_directory, grouping_file)
elif "cropped" in kwargs:
if kwargs.get("cropped") == "banks": if kwargs.get("cropped") == "banks":
Focus.focus_cropped(False, kwargs.get("bank"), van_curves_file, van_int_file, run_no, Focus.focus_cropped(False, False, kwargs.get("bank"), van_curves_file, van_int_file, run_no,
self.focus_directory) self.focus_directory)
elif kwargs.get("cropped") == "spectra": elif kwargs.get("cropped") == "spectra":
Focus.focus_cropped(True, kwargs.get("spectra"), van_curves_file, van_int_file, run_no, Focus.focus_cropped(True, False, kwargs.get("spectra"), van_curves_file, van_int_file, run_no,
self.focus_directory) self.focus_directory)
else: else:
Focus.focus_whole(van_curves_file, van_int_file, run_no, Focus.focus_whole(van_curves_file, van_int_file, run_no,
......
...@@ -8,6 +8,7 @@ from __future__ import (absolute_import, division, print_function) ...@@ -8,6 +8,7 @@ from __future__ import (absolute_import, division, print_function)
import mantid.simpleapi as simple import mantid.simpleapi as simple
import os import os
import csv
def focus_whole(van_curves, van_int, run_number, focus_dir): def focus_whole(van_curves, van_int, run_number, focus_dir):
...@@ -19,7 +20,7 @@ def focus_whole(van_curves, van_int, run_number, focus_dir): ...@@ -19,7 +20,7 @@ def focus_whole(van_curves, van_int, run_number, focus_dir):
simple.EnggFocus(InputWorkspace=ws_to_focus, OutputWorkspace=output_ws, simple.EnggFocus(InputWorkspace=ws_to_focus, OutputWorkspace=output_ws,
VanIntegrationWorkspace=van_integrated_ws, VanCurvesWorkspace=van_curves_ws, VanIntegrationWorkspace=van_integrated_ws, VanCurvesWorkspace=van_curves_ws,
Bank=str(i)) Bank=str(i))
_save_out(output_ws, run_number, str(i), focus_dir) _save_out(output_ws, run_number, str(i), focus_dir, "ENGINX_{}_{}")
print("done") print("done")
...@@ -35,22 +36,54 @@ def focus_cropped(use_spectra, crop_on, van_curves, van_int, run_number, focus_d ...@@ -35,22 +36,54 @@ def focus_cropped(use_spectra, crop_on, van_curves, van_int, run_number, focus_d
simple.EnggFocus(InputWorkspace=ws_to_focus, OutputWorkspace=output_ws, simple.EnggFocus(InputWorkspace=ws_to_focus, OutputWorkspace=output_ws,
VanIntegrationWorkspace=van_integrated_ws, VanCurvesWorkspace=van_curves_ws, VanIntegrationWorkspace=van_integrated_ws, VanCurvesWorkspace=van_curves_ws,
Bank=bank.get(crop_on)) Bank=bank.get(crop_on))
_save_out(output_ws, run_number, crop_on, focus_dir) _save_out(output_ws, run_number, crop_on, focus_dir, "ENGINX_{}_{}")
else: else:
output_ws = output_ws.format("", "") output_ws = output_ws.format("", "")
simple.EnggFocus(InputWorkspace=ws_to_focus, OutputWorkspace=output_ws, simple.EnggFocus(InputWorkspace=ws_to_focus, OutputWorkspace=output_ws,
VanIntegrationWorkspace=van_integrated_ws, VanIntegrationWorkspace=van_integrated_ws,
VanCurvesWorkspace=van_curves_ws, SpectrumNumbers=crop_on) VanCurvesWorkspace=van_curves_ws, SpectrumNumbers=crop_on)
_save_out(output_ws, run_number, "cropped", focus_dir) _save_out(output_ws, run_number, "cropped", focus_dir, "ENGINX_{}_bank_{}")
def _save_out(output, run_number, bank_id, output_dir): def focus_texture_mode(van_curves, van_int, run_number, focus_dir, dg_file):
if type(bank_id)is str: van_curves_ws, van_integrated_ws, ws_to_focus = _prepare_focus(run_number, van_curves, van_int)
filename = os.path.join(output_dir, "ENGINX_{}_bank_{}".format(run_number, bank_id)) banks = {}
else: with open(dg_file) as grouping_file:
filename = os.path.join(output_dir, "ENGINX_{}_{}".format(run_number, bank_id)) group_reader = csv.reader(_decomment_csv(grouping_file), delimiter=',')
simple.SaveFocusedXYE(InputWorkspace=output, Filename=filename, SplitFiles=False, StartAtBankNumber=bank_id)
simple.SaveGSS(InputWorkspace=output, Filename=filename, SplitFiles=False, Bank=bank_id) for row in group_reader:
simple.SaveOpenGenieAscii(InputWorkspace=output, Filename=filename, OpenGenieFormat="ENGIN-X Format") banks.update({row[0]: ','.join(row[1:])})
simple.SaveNexus(InputWorkspace=output, Filename=filename)
simple.ExportSampleLogsToHDF5(InputWorkspace=output, Filename=filename, Blacklist="bankid") for bank in banks:
output_ws = "engg_focusing_output_ws_texture_bank_{}"
output_ws = output_ws.format(bank)
print(banks.get(bank))
simple.EnggFocus(InputWorkspace=ws_to_focus, OutputWorkspace=output_ws,
VanIntegrationWorkspace=van_integrated_ws, VanCurvesWorkspace=van_curves_ws,
SpectrumNumbers=banks.get(bank))
_save_out(output_ws, run_number, bank, focus_dir, "ENGINX_{}_texture_{}")
def _prepare_focus(run_number, van_curves, van_int):
ws_to_focus = simple.Load(Filename="ENGINX" + run_number, OutputWorkspace="engg_focus_input")
van_integrated_ws = simple.Load(Filename=van_int)
van_curves_ws = simple.Load(Filename=van_curves)
return van_curves_ws, van_integrated_ws, ws_to_focus
def _save_out(output, run_number, bank_id, output_dir, join_string):
filename = os.path.join(output_dir, join_string.format(run_number, bank_id))
hdf5_name = os.path.join(output_dir, run_number + ".hdf5")
simple.SaveFocusedXYE(InputWorkspace=output, Filename=filename + ".dat", SplitFiles=False,
StartAtBankNumber=bank_id)
simple.SaveGSS(InputWorkspace=output, Filename=filename + ".gss", SplitFiles=False, Bank=bank_id)
simple.SaveOpenGenieAscii(InputWorkspace=output, Filename=filename + ".his", OpenGenieFormat="ENGIN-X Format")
simple.SaveNexus(InputWorkspace=output, Filename=filename + ".nxs")
simple.ExportSampleLogsToHDF5(InputWorkspace=output, Filename=hdf5_name, Blacklist="bankid")
def _decomment_csv(csvfile):
for row in csvfile:
raw = row.split('#')[0].strip()
if raw:
yield raw
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment