Skip to content

Commit c64f4fa

Browse files
committed
Add CW/TOF SC ASCII import with wavelength
1 parent 62fe41e commit c64f4fa

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

src/easydiffraction/experiments/experiment/bragg_pd.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ class BraggPdExperiment(
2323
InstrumentMixin,
2424
PdExperimentBase,
2525
):
26-
"""Powder diffraction experiment.
27-
28-
Wraps background model, peak profile and linked phases for Bragg PD.
26+
"""Standard (Bragg) Powder Diffraction experiment class with
27+
specific attributes.
2928
"""
3029

3130
def __init__(

src/easydiffraction/experiments/experiment/bragg_sc.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ class BraggScExperiment(
2020
InstrumentMixin,
2121
ScExperimentBase,
2222
):
23-
"""Single crystal experiment class with specific attributes."""
23+
"""Standard (Bragg) Single Crystal experiment class with specific
24+
attributes.
25+
"""
2426

2527
def __init__(
2628
self,
@@ -34,11 +36,12 @@ def __init__(
3436
self._extinction = Extinction()
3537

3638
def _load_ascii_data_to_experiment(self, data_path: str) -> None:
37-
"""Load (index_h, index_k, index_l, y, sy) data from an ASCII
38-
file into the data category.
39+
"""Load measured data from an ASCII file into the data category.
3940
40-
The file format is space/column separated with 5 columns:
41-
``h k l Fobs sFobs``.
41+
The file format is space/column separated with either 5 or 6
42+
columns depending on the beam mode:
43+
- 5 for constant wavelength mode: ``h k l Iobs sIobs``.
44+
- 6 for time-of-flight mode: ``h k l Iobs sIobs wavelength``.
4245
"""
4346
import numpy as np
4447

@@ -47,27 +50,30 @@ def _load_ascii_data_to_experiment(self, data_path: str) -> None:
4750
except Exception as e:
4851
raise IOError(f'Failed to read data from {data_path}: {e}') from e
4952

50-
if data.shape[1] < 5:
51-
raise ValueError('Data file must have five columns: h, k, l, Fobs, sFobs.')
53+
if self.type.beam_mode.value == BeamModeEnum.CONSTANT_WAVELENGTH and data.shape[1] < 5:
54+
raise ValueError('Data file must have at least 5 columns: h, k, l, Iobs, sIobs.')
55+
elif self.type.beam_mode.value == BeamModeEnum.TIME_OF_FLIGHT and data.shape[1] < 6:
56+
raise ValueError(
57+
'Data file must have at least 6 columns: h, k, l, Iobs, sIobs, wavelength.'
58+
)
5259

53-
# Extract h, k, l
60+
# Extract Miller indices h, k, l
5461
indices_h: np.ndarray = data[:, 0].astype(int)
5562
indices_k: np.ndarray = data[:, 1].astype(int)
5663
indices_l: np.ndarray = data[:, 2].astype(int)
5764

58-
# Extract Fobs, sFobs data
59-
y: np.ndarray = data[:, 3]
60-
sy: np.ndarray = data[:, 4]
65+
# Extract intensities and their standard uncertainties
66+
integrated_intensities: np.ndarray = data[:, 3]
67+
integrated_intensities_su: np.ndarray = data[:, 4]
6168

6269
# Set the experiment data
6370
self.data._set_hkl(indices_h, indices_k, indices_l)
64-
self.data._set_meas(y)
65-
self.data._set_meas_su(sy)
71+
self.data._set_meas(integrated_intensities)
72+
self.data._set_meas_su(integrated_intensities_su)
6673

67-
if self.type.beam_mode.value == BeamModeEnum.TIME_OF_FLIGHT:
68-
# Extract wavelength data if present
74+
# If wavelength data is present (column 6), extract and set it
75+
if data.shape[1] >= 6:
6976
wavelength: np.ndarray = data[:, 5]
70-
# Set the experiment data
7177
self.data._set_wavelength(wavelength)
7278

7379
console.paragraph('Data loaded successfully')

0 commit comments

Comments
 (0)