forked from mantidproject/mantid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request mantidproject#36588 from koshchii/dns_gui_single_c…
…rystal_elastic_upload_main_skeleton_part_1 Main skeleton for Single Crystal Elastic mode of DNS Reduction GUI
- Loading branch information
Showing
31 changed files
with
1,314 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
...tidqtinterfaces/mantidqtinterfaces/dns_single_crystal_elastic/data_structures/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Mantid Repository : https://github.com/mantidproject/mantid | ||
# | ||
# Copyright © 2023 ISIS Rutherford Appleton Laboratory UKRI, | ||
# NScD Oak Ridge National Laboratory, European Spallation Source | ||
# & Institut Laue - Langevin | ||
# SPDX - License - Identifier: GPL - 3.0 + |
112 changes: 112 additions & 0 deletions
112
...s/mantidqtinterfaces/dns_single_crystal_elastic/data_structures/dns_single_crystal_map.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
# Mantid Repository : https://github.com/mantidproject/mantid | ||
# | ||
# Copyright © 2023 ISIS Rutherford Appleton Laboratory UKRI, | ||
# NScD Oak Ridge National Laboratory, European Spallation Source | ||
# & Institut Laue - Langevin | ||
# SPDX - License - Identifier: GPL - 3.0 + | ||
|
||
""" | ||
Class which loads and stores a single DNS datafile in a dictionary. | ||
""" | ||
|
||
import numpy as np | ||
from matplotlib import path | ||
from matplotlib import tri | ||
from mantidqtinterfaces.dns_powder_tof.data_structures.object_dict import ObjectDict | ||
from mantidqtinterfaces.dns_single_crystal_elastic.plot.elastic_single_crystal_helpers import angle_to_q | ||
|
||
|
||
def _get_mesh(omega, two_theta, z_mesh): | ||
omega_mesh_no_nan, two_theta_mesh_no_nan = np.meshgrid(omega, two_theta) | ||
not_nan_pos = ~np.isnan(z_mesh) | ||
omega_mesh_no_nan = omega_mesh_no_nan[not_nan_pos] | ||
two_theta_mesh_no_nan = two_theta_mesh_no_nan[not_nan_pos] | ||
z_mesh_no_nan = z_mesh[not_nan_pos] | ||
return omega_mesh_no_nan, two_theta_mesh_no_nan, z_mesh_no_nan | ||
|
||
|
||
def _get_unique(omega_mesh, two_theta_mesh): | ||
omega = np.unique(omega_mesh) | ||
two_theta = np.unique(two_theta_mesh) | ||
return omega, two_theta | ||
|
||
|
||
def _get_q_mesh(omega_mesh, two_theta_mesh, wavelength): | ||
q_x, q_y = angle_to_q(two_theta=two_theta_mesh, omega=omega_mesh, wavelength=wavelength) | ||
return q_x, q_y | ||
|
||
|
||
def _get_hkl_mesh(qx_mesh, qy_mesh, dx, dy): | ||
hklx_mesh = qx_mesh * dx / 2.0 / np.pi | ||
hkly_mesh = qy_mesh * dy / 2.0 / np.pi | ||
return hklx_mesh, hkly_mesh | ||
|
||
|
||
class DNSScMap(ObjectDict): | ||
""" | ||
Class for storing data of a single DNS single crystal plot. | ||
""" | ||
|
||
def __init__(self, parameter, two_theta=None, omega=None, z_mesh=None, error_mesh=None): | ||
super().__init__() | ||
# non interpolated data: | ||
omega_mesh, two_theta_mesh, z_mesh = _get_mesh(omega, two_theta, z_mesh) | ||
omega_unique, two_theta_unique = _get_unique(omega_mesh, two_theta_mesh) | ||
qx_mesh, qy_mesh = _get_q_mesh(omega_mesh, two_theta_mesh, parameter["wavelength"]) | ||
hklx_mesh, hkly_mesh = _get_hkl_mesh(qx_mesh, qy_mesh, parameter["dx"], parameter["dy"]) | ||
# setting attributes dictionary keys | ||
self.omega_interpolated = None | ||
self.two_theta = two_theta_unique | ||
self.omega = omega_unique | ||
self.omega_offset = parameter["omega_offset"] | ||
self.hklx_mesh = hklx_mesh | ||
self.hkly_mesh = hkly_mesh | ||
self.z_mesh = z_mesh | ||
self.error_mesh = error_mesh | ||
self.dx = parameter["dx"] | ||
self.dy = parameter["dy"] | ||
self.hkl1 = parameter["hkl1"] | ||
self.hkl2 = parameter["hkl2"] | ||
self.wavelength = parameter["wavelength"] | ||
self.hkl_mesh = [self.hklx_mesh, self.hkly_mesh, self.z_mesh] | ||
|
||
def triangulate(self, mesh_name, switch=False): | ||
plot_x, plot_y, _z = getattr(self, mesh_name) | ||
self.triangulation = tri.Triangulation(plot_x.flatten(), plot_y.flatten()) | ||
return self.triangulation | ||
|
||
def interpolate_triangulation(self, interpolation=0): | ||
if self.triangulation is None: | ||
return None | ||
z = self.z_mesh | ||
triangulator = self.triangulation | ||
return [triangulator, z.flatten()] | ||
|
||
def get_dns_map_border(self, mesh_name): | ||
two_theta = self.two_theta | ||
omega = self.omega | ||
dns_path = np.zeros((2 * two_theta.size + 2 * omega.size, 2)) | ||
hkl_path = np.zeros((2 * two_theta.size + 2 * omega.size, 2)) | ||
dns_path[:, 0] = np.concatenate( | ||
(two_theta[0] * np.ones(omega.size), two_theta, two_theta[-1] * np.ones(omega.size), np.flip(two_theta)) | ||
) | ||
dns_path[:, 1] = np.concatenate((np.flip(omega), omega[0] * np.ones(two_theta.size), omega, omega[-1] * np.ones(two_theta.size))) | ||
dns_path[:, 0], dns_path[:, 1] = angle_to_q(dns_path[:, 0], dns_path[:, 1], self.wavelength) | ||
if "hkl" in mesh_name: | ||
hkl_path[:, 0] = dns_path[:, 0] * self.dx / 2.0 / np.pi | ||
hkl_path[:, 1] = dns_path[:, 1] * self.dy / 2.0 / np.pi | ||
return path.Path(hkl_path) | ||
return path.Path(dns_path) | ||
|
||
def mask_triangles(self, mesh_name): | ||
x, y, _z = getattr(self, mesh_name) | ||
x = x.flatten() | ||
y = y.flatten() | ||
dns_path = self.get_dns_map_border(mesh_name) | ||
triangles = self.triangulation.triangles | ||
x_y_triangles = np.zeros((len(x[triangles]), 2)) | ||
x_y_triangles[:, 0] = np.mean(x[triangles], axis=1) | ||
x_y_triangles[:, 1] = np.mean(y[triangles], axis=1) | ||
maxi = dns_path.contains_points(x_y_triangles) | ||
self.triangulation.set_mask(np.invert(maxi)) | ||
return self.triangulation |
6 changes: 6 additions & 0 deletions
6
...thon/mantidqtinterfaces/mantidqtinterfaces/dns_single_crystal_elastic/options/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Mantid Repository : https://github.com/mantidproject/mantid | ||
# | ||
# Copyright © 2023 ISIS Rutherford Appleton Laboratory UKRI, | ||
# NScD Oak Ridge National Laboratory, European Spallation Source | ||
# & Institut Laue - Langevin | ||
# SPDX - License - Identifier: GPL - 3.0 + |
87 changes: 87 additions & 0 deletions
87
...interfaces/dns_single_crystal_elastic/options/elastic_single_crystal_options_presenter.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# Mantid Repository : https://github.com/mantidproject/mantid | ||
# | ||
# Copyright © 2023 ISIS Rutherford Appleton Laboratory UKRI, | ||
# NScD Oak Ridge National Laboratory, European Spallation Source | ||
# & Institut Laue - Langevin | ||
# SPDX - License - Identifier: GPL - 3.0 + | ||
|
||
""" | ||
DNS single crystal elastic options tab presenter of DNS reduction GUI. | ||
""" | ||
|
||
from mantidqtinterfaces.dns_powder_tof.options.common_options_presenter import DNSCommonOptionsPresenter | ||
|
||
|
||
class DNSElasticSCOptionsPresenter(DNSCommonOptionsPresenter): | ||
def __init__(self, name=None, parent=None, view=None, model=None): | ||
super().__init__(parent=parent, name=name, view=view, model=model) | ||
# connect signals | ||
self._attach_signal_slots() | ||
|
||
def _set_auto_two_theta_binning(self): | ||
if self.param_dict["file_selector"]["full_data"]: | ||
sample_data = self.param_dict["file_selector"]["full_data"] | ||
two_theta_params_dict = get_automatic_two_theta_binning(sample_data) | ||
own_options = self.get_option_dict() | ||
for parameter in two_theta_params_dict.keys(): | ||
own_options[parameter] = two_theta_params_dict[parameter] | ||
self.set_view_from_param() | ||
|
||
def _set_auto_omega_binning(self): | ||
if self.param_dict["file_selector"]["full_data"]: | ||
sample_data = self.param_dict["file_selector"]["full_data"] | ||
omega_params_dict = get_automatic_omega_binning(sample_data) | ||
own_options = self.get_option_dict() | ||
for parameter in omega_params_dict.keys(): | ||
own_options[parameter] = omega_params_dict[parameter] | ||
self.set_view_from_param() | ||
|
||
def _get_automatic_binning_state(self): | ||
return self.view._map["automatic_binning"].isChecked() | ||
|
||
def tab_got_focus(self): | ||
auto_binning_is_on = self._get_automatic_binning_state() | ||
if auto_binning_is_on: | ||
self._set_auto_two_theta_binning() | ||
self._set_auto_omega_binning() | ||
|
||
def process_request(self): | ||
own_options = self.get_option_dict() | ||
if own_options["get_wavelength"]: | ||
self._determine_wavelength() | ||
|
||
def get_option_dict(self): | ||
if self.view is not None: | ||
self.own_dict.update(self.view.get_state()) | ||
return self.own_dict | ||
|
||
def _attach_signal_slots(self): | ||
self.view.sig_get_wavelength.connect(self._determine_wavelength) | ||
self.view.sig_auto_binning_clicked.connect(self._set_auto_two_theta_binning) | ||
self.view.sig_auto_binning_clicked.connect(self._set_auto_omega_binning) | ||
|
||
|
||
def get_automatic_two_theta_binning(sample_data): | ||
det_rot = [-x["det_rot"] for x in sample_data] | ||
two_theta_last_det = 115.0 | ||
two_theta_max = max(det_rot) + two_theta_last_det | ||
two_theta_min = min(det_rot) | ||
two_theta_step = 0.5 | ||
number_two_theta_bins = int(round((two_theta_max - two_theta_min) / two_theta_step) + 1) | ||
two_theta_binning_dict = { | ||
"two_theta_min": two_theta_min, | ||
"two_theta_max": two_theta_max, | ||
"two_theta_bin_size": two_theta_step, | ||
"nbins": number_two_theta_bins, | ||
} | ||
return two_theta_binning_dict | ||
|
||
|
||
def get_automatic_omega_binning(sample_data): | ||
omega = [x["sample_rot"] - x["det_rot"] for x in sample_data] | ||
omega_min = min(omega) | ||
omega_max = max(omega) | ||
omega_step = 1.0 | ||
number_omega_bins = int(round((omega_max - omega_min) / omega_step) + 1) | ||
omega_binning_dict = {"omega_min": omega_min, "omega_max": omega_max, "omega_bin_size": omega_step, "omega_nbins": number_omega_bins} | ||
return omega_binning_dict |
Oops, something went wrong.