From b38ec71bb07fb069b543ac879310d3e76af3ecf7 Mon Sep 17 00:00:00 2001 From: Mohammed Almakki Date: Thu, 6 Apr 2023 15:47:57 +0100 Subject: [PATCH 1/6] Add multiple scattering correction --- scripts/Diffraction/isis_powder/osiris.py | 29 ++++++++++++++++++- .../osiris_routines/osiris_param_mapping.py | 2 ++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/scripts/Diffraction/isis_powder/osiris.py b/scripts/Diffraction/isis_powder/osiris.py index 495d6309af2c..4f4c0bbf1e21 100644 --- a/scripts/Diffraction/isis_powder/osiris.py +++ b/scripts/Diffraction/isis_powder/osiris.py @@ -221,6 +221,9 @@ def _apply_absorb_corrections(self, run_details, ws_to_correct): ws_to_correct = ws_to_correct / corrections + if self._inst_settings.multiple_scattering: + ws_to_correct = self._apply_discus_multiple_scattering(ws_to_correct) + if previous_units != ws_units.wavelength: ws_to_correct = mantid.ConvertUnits( InputWorkspace=ws_to_correct, @@ -244,13 +247,37 @@ def _apply_paalmanpings_absorb_and_subtract_empty(self, workspace, summed_empty, :return: The corrected workspace. """ mantid.SetInstrumentParameter(Workspace=workspace, ParameterName="deltaE-mode", Value="Elastic") - return absorb_corrections.apply_paalmanpings_absorb_and_subtract_empty( + paalman_corrected = absorb_corrections.apply_paalmanpings_absorb_and_subtract_empty( workspace=workspace, summed_empty=summed_empty, sample_details=sample_details, paalman_pings_events_per_point=paalman_pings_events_per_point, ) + if self._inst_settings.multiple_scattering: + return self._apply_discus_multiple_scattering(paalman_corrected) + + return paalman_corrected + + def _apply_discus_multiple_scattering(self, ws_to_correct): + X = [1.0] + Y = [1.0] + Sofq_isotropic = mantid.CreateWorkspace(DataX=X, DataY=Y, UnitX="MomentumTransfer") + + ws_to_correct = mantid.ConvertUnits(InputWorkspace=ws_to_correct, OutputWorkspace=ws_to_correct, Target="Momentum") + + mantid.DiscusMultipleScatteringCorrection( + InputWorkspace=ws_to_correct, + StructureFactorWorkspace=Sofq_isotropic, + NeutronPathsSingle=100, + NeutronPathsMultiple=100, + OutputWorkspace="MSResults", + ) + + ratio = mantid.mtd["MSResults_Ratio_Single_To_All"] + + return ws_to_correct * ratio + def apply_drange_cropping(self, run_number_string, focused_ws): """ Applies dspacing range cropping to a focused workspace. diff --git a/scripts/Diffraction/isis_powder/osiris_routines/osiris_param_mapping.py b/scripts/Diffraction/isis_powder/osiris_routines/osiris_param_mapping.py index b0e37c592cf6..f8141be855ac 100644 --- a/scripts/Diffraction/isis_powder/osiris_routines/osiris_param_mapping.py +++ b/scripts/Diffraction/isis_powder/osiris_routines/osiris_param_mapping.py @@ -36,5 +36,7 @@ ), ParamMapEntry(ext_name="paalman_pings_events_per_point", int_name="paalman_pings_events_per_point", optional=True), ParamMapEntry(ext_name="simple_events_per_point", int_name="simple_events_per_point", optional=True), + ParamMapEntry(ext_name="multiple_scattering", int_name="multiple_scattering", optional=True), + ParamMapEntry(ext_name="vanadium_normalization_cutoff", int_name="van_norm_cutoff", optional=True), ] attr_mapping.extend(PARAM_MAPPING) From 566e3dcb9616c6dab364ea93413812e098cc4c06 Mon Sep 17 00:00:00 2001 From: Mohammed Almakki Date: Mon, 26 Jun 2023 12:53:31 +0100 Subject: [PATCH 2/6] Add neutron paths param --- scripts/Diffraction/isis_powder/osiris.py | 14 ++++++++++++-- .../osiris_routines/osiris_param_mapping.py | 3 ++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/scripts/Diffraction/isis_powder/osiris.py b/scripts/Diffraction/isis_powder/osiris.py index 4f4c0bbf1e21..9a2975773a6a 100644 --- a/scripts/Diffraction/isis_powder/osiris.py +++ b/scripts/Diffraction/isis_powder/osiris.py @@ -260,6 +260,16 @@ def _apply_paalmanpings_absorb_and_subtract_empty(self, workspace, summed_empty, return paalman_corrected def _apply_discus_multiple_scattering(self, ws_to_correct): + if self._inst_settings.neutron_paths_single: + neutron_paths_single = int(self._inst_settings.neutron_paths_single) + else: + neutron_paths_single = 100 + + if self._inst_settings.neutron_paths_multiple: + neutron_paths_multiple = int(self._inst_settings.neutron_paths_multiple) + else: + neutron_paths_multiple = 100 + X = [1.0] Y = [1.0] Sofq_isotropic = mantid.CreateWorkspace(DataX=X, DataY=Y, UnitX="MomentumTransfer") @@ -269,8 +279,8 @@ def _apply_discus_multiple_scattering(self, ws_to_correct): mantid.DiscusMultipleScatteringCorrection( InputWorkspace=ws_to_correct, StructureFactorWorkspace=Sofq_isotropic, - NeutronPathsSingle=100, - NeutronPathsMultiple=100, + NeutronPathsSingle=neutron_paths_single, + NeutronPathsMultiple=neutron_paths_multiple, OutputWorkspace="MSResults", ) diff --git a/scripts/Diffraction/isis_powder/osiris_routines/osiris_param_mapping.py b/scripts/Diffraction/isis_powder/osiris_routines/osiris_param_mapping.py index f8141be855ac..f05d792b56f4 100644 --- a/scripts/Diffraction/isis_powder/osiris_routines/osiris_param_mapping.py +++ b/scripts/Diffraction/isis_powder/osiris_routines/osiris_param_mapping.py @@ -37,6 +37,7 @@ ParamMapEntry(ext_name="paalman_pings_events_per_point", int_name="paalman_pings_events_per_point", optional=True), ParamMapEntry(ext_name="simple_events_per_point", int_name="simple_events_per_point", optional=True), ParamMapEntry(ext_name="multiple_scattering", int_name="multiple_scattering", optional=True), - ParamMapEntry(ext_name="vanadium_normalization_cutoff", int_name="van_norm_cutoff", optional=True), + ParamMapEntry(ext_name="neutron_paths_single", int_name="neutron_paths_single", optional=True), + ParamMapEntry(ext_name="neutron_paths_multiple", int_name="neutron_paths_multiple", optional=True), ] attr_mapping.extend(PARAM_MAPPING) From 02cdcfd939e83874cd9af367067623f74482a403 Mon Sep 17 00:00:00 2001 From: Mohammed Almakki Date: Tue, 15 Aug 2023 11:55:15 +0100 Subject: [PATCH 3/6] Add system test --- .../tests/framework/ISIS_PowderOsirisTest.py | 39 +++++++++++++++++++ ...32_d_multiple_scattering_corrected.nxs.md5 | 1 + 2 files changed, 40 insertions(+) create mode 100644 Testing/SystemTests/tests/framework/reference/OSI120032_d_multiple_scattering_corrected.nxs.md5 diff --git a/Testing/SystemTests/tests/framework/ISIS_PowderOsirisTest.py b/Testing/SystemTests/tests/framework/ISIS_PowderOsirisTest.py index 96fa1b678405..62a6673dbbf8 100644 --- a/Testing/SystemTests/tests/framework/ISIS_PowderOsirisTest.py +++ b/Testing/SystemTests/tests/framework/ISIS_PowderOsirisTest.py @@ -54,6 +54,9 @@ def run_diffraction_focusing( sample_details=None, paalman_pings_events_per_point=None, simple_events_per_point=None, + neutron_paths_multiple=None, + neutron_paths_single=None, + multiple_scattering=False, ): sample_runs = sample_runs # Choose full drange set in the cycle 1_1 @@ -78,6 +81,9 @@ def run_diffraction_focusing( empty_can_subtraction_method=empty_can_subtraction_method, paalman_pings_events_per_point=paalman_pings_events_per_point, simple_events_per_point=simple_events_per_point, + neutron_paths_multiple=neutron_paths_multiple, + neutron_paths_single=neutron_paths_single, + multiple_scattering=multiple_scattering, ) focussed_rel_path = os.path.join("1_1", user_name, output_file) @@ -251,3 +257,36 @@ def runTest(self): def skipTests(self): return False + + +class OSIRISDiffractionFocusingWithMultipleScattering(_OSIRISDiffractionFocusingTest): + refrence_ws_name = "OSI120032_d_multiple_scattering_corrected.nxs" + required_run_files = [ + "OSI82717.nxs", + "OSI82718.nxs", # empty can + "OSIRIS00119963.nxs", + "OSIRIS00119964.nxs", # van + "OSIRIS00120032.nxs", + ] + + def runTest(self): + super().runPreTest() + sample_details = SampleDetails(radius=1.1, height=8, center=[0, 0, 0], shape="cylinder") + sample_details.set_material(chemical_formula="Cr2-Ga-N", number_density=10.0) + sample_details.set_container(chemical_formula="Al", number_density=2.7, radius=1.2) + + self.results = run_diffraction_focusing( + "120032", + "Test_Multiple_Scattering", + "OSI120032_d_spacing.nxs", + absorb_corrections=True, + empty_can_subtraction_method="Simple", + sample_details=sample_details, + multiple_scattering=True, + simple_events_per_point=100, + neutron_paths_single=5, + neutron_paths_multiple=5, + ) + + def skipTests(self): + return False diff --git a/Testing/SystemTests/tests/framework/reference/OSI120032_d_multiple_scattering_corrected.nxs.md5 b/Testing/SystemTests/tests/framework/reference/OSI120032_d_multiple_scattering_corrected.nxs.md5 new file mode 100644 index 000000000000..21835aee4c20 --- /dev/null +++ b/Testing/SystemTests/tests/framework/reference/OSI120032_d_multiple_scattering_corrected.nxs.md5 @@ -0,0 +1 @@ +6212445a160423ec7e8db3504c5c9609 \ No newline at end of file From b15f6f73d233717180f54e84fe1e8538ab19ae3a Mon Sep 17 00:00:00 2001 From: Mohammed Almakki Date: Tue, 5 Sep 2023 17:02:01 +0100 Subject: [PATCH 4/6] Add sample_details not provided check --- scripts/Diffraction/isis_powder/routines/focus.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/Diffraction/isis_powder/routines/focus.py b/scripts/Diffraction/isis_powder/routines/focus.py index c9e474057aa2..81d865e76743 100644 --- a/scripts/Diffraction/isis_powder/routines/focus.py +++ b/scripts/Diffraction/isis_powder/routines/focus.py @@ -162,6 +162,9 @@ def _absorb_and_empty_corrections( empty_can_subtraction_method, paalman_pings_events_per_point, ): + if absorb and sample_details is None: + raise TypeError("To apply absorption correction you need to supply `sample_details` using `set_sample_details` method") + if absorb and empty_can_subtraction_method == "PaalmanPings": if run_details.sample_empty: # need summed_empty including container input_workspace = instrument._apply_paalmanpings_absorb_and_subtract_empty( From 6c798c2c407e25365f35b995817c46605fed8019 Mon Sep 17 00:00:00 2001 From: Mohammed Almakki Date: Wed, 6 Sep 2023 10:57:41 +0100 Subject: [PATCH 5/6] Move the check to osiris only --- scripts/Diffraction/isis_powder/osiris.py | 3 +++ scripts/Diffraction/isis_powder/routines/focus.py | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/Diffraction/isis_powder/osiris.py b/scripts/Diffraction/isis_powder/osiris.py index 9a2975773a6a..1994f5258a5a 100644 --- a/scripts/Diffraction/isis_powder/osiris.py +++ b/scripts/Diffraction/isis_powder/osiris.py @@ -189,6 +189,9 @@ def _apply_absorb_corrections(self, run_details, ws_to_correct): else: events_per_point = 1000 + if self._sample_details is None: + raise TypeError("To apply absorption correction you need to supply `sample_details` using `set_sample_details` method") + container_geometry = self._sample_details.generate_container_geometry() container_material = self._sample_details.generate_container_material() if container_geometry and container_material: diff --git a/scripts/Diffraction/isis_powder/routines/focus.py b/scripts/Diffraction/isis_powder/routines/focus.py index 81d865e76743..c9e474057aa2 100644 --- a/scripts/Diffraction/isis_powder/routines/focus.py +++ b/scripts/Diffraction/isis_powder/routines/focus.py @@ -162,9 +162,6 @@ def _absorb_and_empty_corrections( empty_can_subtraction_method, paalman_pings_events_per_point, ): - if absorb and sample_details is None: - raise TypeError("To apply absorption correction you need to supply `sample_details` using `set_sample_details` method") - if absorb and empty_can_subtraction_method == "PaalmanPings": if run_details.sample_empty: # need summed_empty including container input_workspace = instrument._apply_paalmanpings_absorb_and_subtract_empty( From 937076aa73bfa8b268bd1290a26fd413c2bd85c6 Mon Sep 17 00:00:00 2001 From: Mohammed Almakki Date: Thu, 7 Sep 2023 10:31:34 +0100 Subject: [PATCH 6/6] Update tests wit approximate number densities --- .../tests/framework/ISIS_PowderOsirisTest.py | 30 +++++++++---------- ...32_d_multiple_scattering_corrected.nxs.md5 | 2 +- ...120032_d_spacing_paalman_corrected.nxs.md5 | 2 +- ...I120032_d_spacing_simple_corrected.nxs.md5 | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Testing/SystemTests/tests/framework/ISIS_PowderOsirisTest.py b/Testing/SystemTests/tests/framework/ISIS_PowderOsirisTest.py index 62a6673dbbf8..227cd4f36b46 100644 --- a/Testing/SystemTests/tests/framework/ISIS_PowderOsirisTest.py +++ b/Testing/SystemTests/tests/framework/ISIS_PowderOsirisTest.py @@ -109,6 +109,14 @@ def setup_inst_object(user_name, with_container=False): return inst_obj +def setup_sample_details(): + sample_details = SampleDetails(radius=1.1, height=8, center=[0, 0, 0], shape="cylinder") + sample_details.set_material(chemical_formula="Cr2-Ga-N", number_density=0.02) + sample_details.set_container(chemical_formula="Al", mass_density=2.71, radius=1.2) + + return sample_details + + def _try_delete(path): try: # Use this instead of os.remove as we could be passed a non-empty dir @@ -200,18 +208,14 @@ def skipTests(self): class OSIRISDiffractionFocusingWithSimpleAbsorptionCorrection(_OSIRISDiffractionFocusingTest): refrence_ws_name = "OSI120032_d_spacing_simple_corrected.nxs" required_run_files = [ - "OSI82717.nxs", - "OSI82718.nxs", # empty can + "OSI82717.nxs", # empty can "OSIRIS00119963.nxs", - "OSIRIS00119964.nxs", # van - "OSIRIS00120032.nxs", + "OSIRIS00120032.nxs", # van ] def runTest(self): super().runPreTest() - sample_details = SampleDetails(radius=1.1, height=8, center=[0, 0, 0], shape="cylinder") - sample_details.set_material(chemical_formula="Cr2-Ga-N", number_density=10.0) - sample_details.set_container(chemical_formula="Al", number_density=2.7, radius=1.2) + sample_details = setup_sample_details() self.results = run_diffraction_focusing( "120032", @@ -230,9 +234,7 @@ def skipTests(self): class OSIRISDiffractionFocusingWithPaalmanPingsAbsorptionCorrection(_OSIRISDiffractionFocusingTest): refrence_ws_name = "OSI120032_d_spacing_paalman_corrected.nxs" required_run_files = [ - "OSI82717.nxs", "OSI82718.nxs", # empty can - "OSIRIS00119963.nxs", "OSIRIS00119964.nxs", # van "OSIRIS00120032.nxs", ] @@ -241,9 +243,7 @@ def runTest(self): self.tolerance = 1e-8 self.tolerance_is_rel_err = True super().runPreTest() - sample_details = SampleDetails(radius=1.1, height=8, center=[0, 0, 0], shape="cylinder") - sample_details.set_material(chemical_formula="Cr2-Ga-N", number_density=10.0) - sample_details.set_container(chemical_formula="Al", number_density=2.7, radius=1.2) + sample_details = setup_sample_details() self.results = run_diffraction_focusing( "120032", @@ -271,9 +271,7 @@ class OSIRISDiffractionFocusingWithMultipleScattering(_OSIRISDiffractionFocusing def runTest(self): super().runPreTest() - sample_details = SampleDetails(radius=1.1, height=8, center=[0, 0, 0], shape="cylinder") - sample_details.set_material(chemical_formula="Cr2-Ga-N", number_density=10.0) - sample_details.set_container(chemical_formula="Al", number_density=2.7, radius=1.2) + sample_details = setup_sample_details() self.results = run_diffraction_focusing( "120032", @@ -288,5 +286,7 @@ def runTest(self): neutron_paths_multiple=5, ) + mantid.SaveNexus(InputWorkspace=self.results, Filename=r"C:\Users\joy22959\Documents\test\multiscatt") + def skipTests(self): return False diff --git a/Testing/SystemTests/tests/framework/reference/OSI120032_d_multiple_scattering_corrected.nxs.md5 b/Testing/SystemTests/tests/framework/reference/OSI120032_d_multiple_scattering_corrected.nxs.md5 index 21835aee4c20..d6bff7540156 100644 --- a/Testing/SystemTests/tests/framework/reference/OSI120032_d_multiple_scattering_corrected.nxs.md5 +++ b/Testing/SystemTests/tests/framework/reference/OSI120032_d_multiple_scattering_corrected.nxs.md5 @@ -1 +1 @@ -6212445a160423ec7e8db3504c5c9609 \ No newline at end of file +534b1473c5f9827fec49e90563e7905c \ No newline at end of file diff --git a/Testing/SystemTests/tests/framework/reference/OSI120032_d_spacing_paalman_corrected.nxs.md5 b/Testing/SystemTests/tests/framework/reference/OSI120032_d_spacing_paalman_corrected.nxs.md5 index 72d6a21cc591..20e122f43a36 100644 --- a/Testing/SystemTests/tests/framework/reference/OSI120032_d_spacing_paalman_corrected.nxs.md5 +++ b/Testing/SystemTests/tests/framework/reference/OSI120032_d_spacing_paalman_corrected.nxs.md5 @@ -1 +1 @@ -73a30dc9bf46d636b47974003819f4cc \ No newline at end of file +e4f663f1311e30a217701e9f03acb5d3 \ No newline at end of file diff --git a/Testing/SystemTests/tests/framework/reference/OSI120032_d_spacing_simple_corrected.nxs.md5 b/Testing/SystemTests/tests/framework/reference/OSI120032_d_spacing_simple_corrected.nxs.md5 index ae39c85bdafe..f6abebcb66c9 100644 --- a/Testing/SystemTests/tests/framework/reference/OSI120032_d_spacing_simple_corrected.nxs.md5 +++ b/Testing/SystemTests/tests/framework/reference/OSI120032_d_spacing_simple_corrected.nxs.md5 @@ -1 +1 @@ -994ad405b8b6fe3763a0b4bc313420bc \ No newline at end of file +409654effe6096a197d437a4cc7d3f92 \ No newline at end of file