Skip to content

Commit

Permalink
fixed inconsistency btw SPICE and Mantid conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
Bing Li committed Dec 20, 2024
1 parent ba8a8ba commit 281e2f9
Show file tree
Hide file tree
Showing 125 changed files with 110 additions and 290 deletions.
4 changes: 2 additions & 2 deletions scripts/rez_dispH.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import numpy as np
from mpl_toolkits.axisartist import Axes

from tavi.data.nxdict import NXdataset, NXentry
from tavi.data.nxentry import NexusEntry
from tavi.data.nexus_builder import NXdataset, NXentry
from tavi.data.nexus_entry import NexusEntry
from tavi.data.tavi import TAVI
from tavi.instrument.resolution.cooper_nathans import CN
from tavi.plotter import Plot2D
Expand Down
4 changes: 2 additions & 2 deletions scripts/scans_rez.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from tavi.data.nxdict import NXdataset, NXentry
from tavi.data.nxentry import NexusEntry
from tavi.data.nexus_builder import NXdataset, NXentry
from tavi.data.nexus_entry import NexusEntry
from tavi.data.tavi import TAVI
from tavi.instrument.resolution.cooper_nathans import CN
from tavi.sample.xtal import Xtal
Expand Down
2 changes: 1 addition & 1 deletion src/tavi/convert_spice_to_nexus.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pathlib
from typing import Optional

from tavi.data.nxentry import NexusEntry
from tavi.data.nexus_entry import NexusEntry


def convert_spice_to_nexus(
Expand Down
207 changes: 0 additions & 207 deletions src/tavi/data/fit_backup.py

This file was deleted.

File renamed without changes.
2 changes: 1 addition & 1 deletion src/tavi/data/nxentry.py → src/tavi/data/nexus_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import h5py
import numpy as np

from tavi.data.nxdict import spice_data_to_nxdict
from tavi.data.nexus_builder import spice_data_to_nxdict


def _find_val_path(val, grp, prefix=""):
Expand Down
18 changes: 7 additions & 11 deletions src/tavi/data/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import matplotlib.pyplot as plt
import numpy as np

from tavi.data.nxentry import NexusEntry
from tavi.data.nexus_entry import NexusEntry
from tavi.data.scan_data import ScanData1D
from tavi.plotter import Plot1D
from tavi.sample.xtal import Xtal
Expand Down Expand Up @@ -97,10 +97,7 @@ def from_spice(

@classmethod
def from_nexus(cls, path_to_nexus: str, scan_num: Optional[int] = None):
((name, nexus_dict),) = NexusEntry.from_nexus(
path_to_nexus,
scan_num,
).items()
((name, nexus_dict),) = NexusEntry.from_nexus(path_to_nexus, scan_num).items()
return cls(name, nexus_dict)

@property
Expand All @@ -122,14 +119,13 @@ def scan_info(self):
@property
def sample_ub_info(self):
sample_type = self._nexus_dict.get("sample/type")
ub_matrix = self._nexus_dict.get("sample/orientation_matrix")
ub_matrix = self._nexus_dict.get("sample/orientation_matrix").reshape(3, 3)
lattice_constants = self._nexus_dict.get("sample/unit_cell")
if sample_type == "crystal" and (ub_matrix is not None):
xtal = Xtal(lattice_constants)
(u, v) = xtal.ub_matrix_to_uv(spice_to_mantid(ub_matrix.reshape(3, 3)))
(u, v) = xtal.ub_matrix_to_uv(spice_to_mantid(ub_matrix))
else:
u = None
v = None
(u, v) = (None, None)

sample_ub_info = SampleUBInfo(
sample_name=self._nexus_dict.get("sample/name"),
Expand All @@ -154,7 +150,7 @@ def instrument_info(self):
analyzer=self._nexus_dict.get("analyser/type"),
sense=(
self._nexus_dict.get("monochromator/sense")
+ self._nexus_dict.get("sample/sense")
+ self._nexus_dict.get("goniometer/sense")
+ self._nexus_dict.get("analyser/sense")
),
collimation=self._nexus_dict.get("divergence_x"),
Expand Down Expand Up @@ -197,7 +193,7 @@ def get_data(
to normalize the y-axis and rebin x-axis.
Args:
axes (x_str, y_stre): x-axis and y-axis variables
axes (x_str, y_str): x-axis and y-axis variables
norm_to (norm_val (float), norm_channel(str)): value and channel for normalization
norm_channel should be "time", "monitor" or"mcu".
rebin_type (str | None): "tol" or "grid"
Expand Down
2 changes: 1 addition & 1 deletion src/tavi/data/scan_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


class ScanData1D(object):
"""1D scan data ready to be plot, with ooptions to renormalize or rebin"""
"""1D scan data ready to be plot, with options to renormalize or rebin"""

def __init__(
self,
Expand Down
2 changes: 1 addition & 1 deletion src/tavi/data/tavi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import h5py

from tavi.data.nxentry import NexusEntry
from tavi.data.nexus_entry import NexusEntry
from tavi.data.scan import Scan
from tavi.data.scan_group import ScanGroup

Expand Down
12 changes: 11 additions & 1 deletion src/tavi/instrument/components/goni.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(
component_name: str = "goniometer",
):
self.type: str = "Y-ZX" # Y-mZ-X for Huber stage at HB1A and HB3
self.sense: Literal[-1, +1] = -1
self.sense: Literal["-", "+"] = "-"
self.omega_limit: Optional[tuple]
self.sgl_limit: Optional[tuple] = (-10, 10)
self.sgu_limit: Optional[tuple] = (-10, 10)
Expand All @@ -29,6 +29,16 @@ def __init__(
super().__init__(param_dict)
self.component_name = component_name

@property
def _sense(self):
match self.sense:
case "+":
return +1
case "-":
return -1
case _:
raise ValueError(f"sense {self.sense} needs to be either '+' or '-'.")

@staticmethod
def rot_x(nu):
"""rotation matrix about y-axis by angle nu
Expand Down
12 changes: 11 additions & 1 deletion src/tavi/instrument/components/mono_ana.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(
self.d_spacing: float = mono_ana_xtal["PG002"]
self.mosaic_h: float = 45.0 # horizontal mosaic, min of arc
self.mosaic_v: float = 45.0 # vertical mosaic, if anisotropic
self.sense: Literal[-1, 1] = -1 # +1 for counter-clockwise, -1 for clockwise
self.sense: Literal["-", "+"] = "-" # + for counter-clockwise, - for clockwise

# divide by np.sqrt(12) if rectangular
# Diameter D/4 if spherical
Expand All @@ -61,6 +61,16 @@ def __init__(
super().__init__(param_dict, component_name)
self.d_spacing = mono_ana_xtal[self.type]

@property
def _sense(self):
match self.sense:
case "+":
return +1
case "-":
return -1
case _:
raise ValueError(f"sense {self.sense} needs to be either '+' or '-'.")

@property
def _mosaic_h(self):
return np.deg2rad(self.mosaic_h / 60)
Expand Down
6 changes: 3 additions & 3 deletions src/tavi/instrument/instrument_params/cg4c.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"type": "PG002",
"mosaic_h": 30,
"mosaic_v": 30,
"sense": -1,
"sense": "-",
"shape": "rectangular",
"width": 7,
"height": 15,
Expand All @@ -26,7 +26,7 @@
"optimally_curved_v": false
},
"goniometer": {
"sense": 1,
"sense": "+",
"type": "Y-ZX"
},
"monitor": {
Expand All @@ -37,7 +37,7 @@
"d_spacing": 3.35416,
"mosaic_h": 90,
"mosaic_v": 90,
"sense": -1,
"sense": "-",
"shape": "rectangular",
"width": 20.0,
"height": 18.0,
Expand Down
Loading

0 comments on commit 281e2f9

Please sign in to comment.