Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

37795 change polaris pdf norm #38535

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
84cf90b7704c016162deb5def8dec28a
Original file line number Diff line number Diff line change
@@ -1 +1 @@
28c6b5a204a148206ff2c61a8b69a60b
c50f5d06a8f8975e8dbc1cecb5974f50
112 changes: 68 additions & 44 deletions Testing/SystemTests/tests/framework/ISIS_PowderPolarisTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def cleanup(self):
config["datasearch.directories"] = self.existing_config


class FocusTestNoAbsorption(systemtesting.MantidSystemTest):
class FocusTestNoAbsorptionWithRelativeNormalisation(systemtesting.MantidSystemTest):
focus_results = None
existing_config = config["datasearch.directories"]

Expand All @@ -126,29 +126,34 @@ def requiredFiles(self):
def runTest(self):
# Gen vanadium calibration first
setup_mantid_paths()
self.focus_results = run_focus_no_absorption()
self.focus_results = run_focus_no_absorption(mode="PDF")

def validate(self):
# check output files as expected
def generate_error_message(expected_file, output_dir):
return "Unable to find {} in {}.\nContents={}".format(expected_file, output_dir, os.listdir(output_dir))
return validate_normalisation_focus_tests(self, "98533")

def assert_output_file_exists(directory, filename):
self.assertTrue(os.path.isfile(os.path.join(directory, filename)), msg=generate_error_message(filename, directory))
def cleanup(self):
try:
_try_delete(spline_path)
_try_delete(output_dir)
finally:
mantid.mtd.clear()
config["datasearch.directories"] = self.existing_config

user_output = os.path.join(output_dir, "17_1", "Test")
assert_output_file_exists(user_output, "POLARIS98533.nxs")
assert_output_file_exists(user_output, "POLARIS98533.gsas")
output_dat_dir = os.path.join(user_output, "dat_files")
for bankno in range(1, 6):
assert_output_file_exists(output_dat_dir, "POL98533-b_{}-TOF.dat".format(bankno))
assert_output_file_exists(output_dat_dir, "POL98533-b_{}-d.dat".format(bankno))

for ws in self.focus_results:
self.assertEqual(ws.sample().getMaterial().name(), "Si Si")
self.tolerance_is_rel_err = True
self.tolerance = 1e-6
return self.focus_results.name(), "ISIS_Powder-POLARIS98533_FocusSempty.nxs"
class FocusTestNoAbsorptionWithAbsoluteNormalisation(systemtesting.MantidSystemTest):
focus_results = None
existing_config = config["datasearch.directories"]

def requiredFiles(self):
return _gen_required_files()

def runTest(self):
# Gen vanadium calibration first
setup_mantid_paths()
self.focus_results = run_focus_no_absorption(mode="PDF_NORM")

def validate(self):
return validate_normalisation_focus_tests(self, "98534")

def cleanup(self):
try:
Expand Down Expand Up @@ -534,7 +539,7 @@ def run_total_scattering(


def _gen_required_files():
required_run_numbers = ["98531", "98532", "98533"] # create_van : PDF mode # File to focus (Si)
required_run_numbers = ["98531", "98532", "98533", "98534"] # create_van : PDF mode # File to focus (Si)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm OK to have an additional file, but is there a reason why you couldn't use 98533 and just have a different reference file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Short answer is probably no, I'm sure there is a way that could've been done. I just tried to keep it consistent and it seemed that the old test took 98532 and ran the normalisation then compared it to 98533, so I figured we could run a different normalisation and compare it to 98534.


# Generate file names of form "INSTxxxxx.nxs"
input_files = [os.path.join(input_dir, (inst_name + "000" + number + ".nxs")) for number in required_run_numbers]
Expand Down Expand Up @@ -566,8 +571,13 @@ def run_vanadium_calibration(per_detector):
return splined_ws, unsplined_ws


def run_focus_no_absorption(per_detector=False):
run_number = 98533
def run_focus_no_absorption(per_detector=False, mode="PDF"):
if mode == "PDF_NORM":
run_number = 98534
elif mode == "PDF":
run_number = 98533
else:
raise RuntimeError("Invalid mode")
sample_empty = 98532 # Use the vanadium empty again to make it obvious
sample_empty_scale = 0.5 # Set it to 50% scale

Expand All @@ -580,15 +590,14 @@ def run_focus_no_absorption(per_detector=False):
original_splined_path = os.path.join(input_dir, splined_file_name)
shutil.copy(original_splined_path, spline_path)

inst_object = setup_inst_object(mode="PDF")
inst_object = setup_inst_object(mode=mode)
return inst_object.focus(
run_number=run_number,
input_mode="Individual",
do_van_normalisation=True,
do_absorb_corrections=False,
sample_empty=sample_empty,
sample_empty_scale=sample_empty_scale,
van_normalisation_method="Relative",
andy-bridger marked this conversation as resolved.
Show resolved Hide resolved
per_detector_vanadium=per_detector,
)

Expand Down Expand Up @@ -625,30 +634,22 @@ def run_focus_absorption(run_number, paalman_pings=False):
shutil.copy(original_splined_path, spline_path)

inst_object = setup_inst_object("PDF", with_container=True)
focus_kwargs = {}
if paalman_pings:
inst_object._inst_settings.empty_can_subtraction_method = "PaalmanPings" # the default is Simple
inst_object._inst_settings.paalman_pings_events_per_point = 1

return inst_object.focus(
run_number=run_number,
input_mode="Summed",
do_van_normalisation=True,
do_absorb_corrections=True,
sample_empty=sample_empty,
multiple_scattering=False,
van_normalisation_method="Relative",
andy-bridger marked this conversation as resolved.
Show resolved Hide resolved
)
else:
return inst_object.focus(
run_number=run_number,
input_mode="Summed",
do_van_normalisation=True,
do_absorb_corrections=True,
sample_empty=sample_empty,
sample_empty_scale=sample_empty_scale,
multiple_scattering=False,
van_normalisation_method="Relative",
)
focus_kwargs["sample_empty_scale"] = sample_empty_scale

return inst_object.focus(
run_number=run_number,
input_mode="Summed",
do_van_normalisation=True,
do_absorb_corrections=True,
sample_empty=sample_empty,
multiple_scattering=False,
**focus_kwargs,
)


def setup_mantid_paths():
Expand Down Expand Up @@ -701,3 +702,26 @@ def get_bin_number_at_given_r(r_data, r):
diffs = [abs(i - r) for i in r_centres]
idx = diffs.index(min(diffs))
return idx


def validate_normalisation_focus_tests(test, ws_num):
# check output files as expected
def generate_error_message(expected_file, output_dir):
return f"Unable to find {expected_file} in {output_dir}.\nContents={os.listdir(output_dir)}"

def assert_output_file_exists(directory, filename):
test.assertTrue(os.path.isfile(os.path.join(directory, filename)), msg=generate_error_message(filename, directory))

user_output = os.path.join(output_dir, "17_1", "Test")
assert_output_file_exists(user_output, f"POLARIS{ws_num}.nxs")
assert_output_file_exists(user_output, f"POLARIS{ws_num}.gsas")
output_dat_dir = os.path.join(user_output, "dat_files")
for bankno in range(1, 6):
assert_output_file_exists(output_dat_dir, f"POL{ws_num}-b_{bankno}-TOF.dat")
assert_output_file_exists(output_dat_dir, f"POL{ws_num}-b_{bankno}-d.dat")

for ws in test.focus_results:
test.assertEqual(ws.sample().getMaterial().name(), "Si Si")
test.tolerance_is_rel_err = True
test.tolerance = 1e-6
return test.focus_results.name(), f"ISIS_Powder-POLARIS{ws_num}_FocusSempty.nxs"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
81c8bbfd41201606449de36771ce9655
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Added new mode ``mode="pdf_norm"`` to :ref:`ISIS POLARIS powder reduction<isis-powder-diffraction-polaris-ref>` for when the chopper is off/stationary with a default ``van_normalisation_method="absolute"``. The existing ``mode="pdf"`` now has a default ``van_normalisation_method="relative"`` (was previously ``"absolute"``).
4 changes: 3 additions & 1 deletion docs/source/techniques/ISISPowder-Polaris-v1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ and :ref:`focus_polaris_isis-powder-diffraction-ref` method.
This determines which vanadium and empty run numbers
to use whilst processing.

Accepted values are: **PDF** or **Rietveld**
Accepted values are: **PDF**, **PDF_NORM** or **Rietveld**

*Note: This parameter is not case sensitive*

Expand All @@ -371,6 +371,8 @@ Example Input:

polaris_example.create_vanadium(mode="PDF", ...)
# Or
polaris_example.create_vanadium(mode="PDF_NORM", ...)
# Or alternatively
polaris_example.focus(mode="Rietveld", ...)

.. _config_file_polaris_isis-powder-diffraction-ref:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ def get_mode_specific_dict(mode):
return {"focused_cropping_values": "auto", "van_normalisation_method": "Relative"}
mode = mode.lower()
if mode == "pdf":
return {"focused_cropping_values": pdf_focused_cropping_values, "van_normalisation_method": "Relative"}
if mode == "pdf_norm":
# In long run this will replace gudrun
return {"focused_cropping_values": pdf_focused_cropping_values, "van_normalisation_method": "Absolute"}
if mode == "rietveld":
return {"focused_cropping_values": rietveld_focused_cropping_values, "van_normalisation_method": "Relative"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
class POLARIS_CHOPPER_MODES(object):
enum_friendly_name = "Polaris chopper modes"
PDF = "PDF"
PDF_NORM = "PDF_NORM"
Rietveld = "Rietveld"
Loading