Skip to content

Commit fbd3abf

Browse files
committed
Refactors axes label handling by using Enum
1 parent 957c892 commit fbd3abf

File tree

3 files changed

+56
-23
lines changed

3 files changed

+56
-23
lines changed

src/easydiffraction/core/constants.py

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/easydiffraction/plotting/plotters/plotter_base.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,23 @@
66

77
import numpy as np
88

9+
from easydiffraction.experiments.components.experiment_type import BeamModeEnum
10+
from easydiffraction.experiments.components.experiment_type import ScatteringTypeEnum
911
from easydiffraction.utils.utils import is_notebook
1012

1113
DEFAULT_ENGINE = 'plotly' if is_notebook() else 'asciichartpy'
1214
DEFAULT_HEIGHT = 9
1315
DEFAULT_MIN = -np.inf
1416
DEFAULT_MAX = np.inf
1517

18+
DEFAULT_AXES_LABELS = {
19+
(ScatteringTypeEnum.BRAGG, BeamModeEnum.CONSTANT_WAVELENGTH): ['2θ (degree)', 'Intensity (arb. units)'],
20+
(ScatteringTypeEnum.BRAGG, BeamModeEnum.TIME_OF_FLIGHT): ['TOF (µs)', 'Intensity (arb. units)'],
21+
(ScatteringTypeEnum.BRAGG, 'd-spacing'): ['d (Å)', 'Intensity (arb. units)'],
22+
(ScatteringTypeEnum.TOTAL, BeamModeEnum.CONSTANT_WAVELENGTH): ['r (Å)', 'G(r) (Å)'],
23+
(ScatteringTypeEnum.TOTAL, BeamModeEnum.TIME_OF_FLIGHT): ['r (Å)', 'G(r) (Å)'],
24+
}
25+
1626
SERIES_CONFIG = dict(
1727
calc=dict(
1828
mode='lines',

src/easydiffraction/plotting/plotting.py

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# SPDX-FileCopyrightText: 2021-2025 EasyDiffraction Python Library contributors <https://github.com/easyscience/diffraction-lib>
22
# SPDX-License-Identifier: BSD-3-Clause
33

4-
from easydiffraction.core.constants import DEFAULT_AXES_LABELS
54
from easydiffraction.plotting.plotters.plotter_ascii import AsciiPlotter
5+
from easydiffraction.plotting.plotters.plotter_base import DEFAULT_AXES_LABELS
66
from easydiffraction.plotting.plotters.plotter_base import DEFAULT_ENGINE
77
from easydiffraction.plotting.plotters.plotter_base import DEFAULT_HEIGHT
88
from easydiffraction.plotting.plotters.plotter_base import DEFAULT_MAX
@@ -120,7 +120,15 @@ def show_supported_engines(self):
120120
columns_data=columns_data,
121121
)
122122

123-
def plot_meas(self, pattern, expt_name, expt_type, x_min=None, x_max=None, d_spacing=False):
123+
def plot_meas(
124+
self,
125+
pattern,
126+
expt_name,
127+
expt_type,
128+
x_min=None,
129+
x_max=None,
130+
d_spacing=False,
131+
):
124132
if pattern.x is None:
125133
error(f'No data available for experiment {expt_name}')
126134
return
@@ -149,9 +157,19 @@ def plot_meas(self, pattern, expt_name, expt_type, x_min=None, x_max=None, d_spa
149157
y_labels = ['meas']
150158

151159
if d_spacing:
152-
axes_labels = DEFAULT_AXES_LABELS[expt_type.scattering_type.value]['d-spacing']
160+
axes_labels = DEFAULT_AXES_LABELS[
161+
(
162+
expt_type.scattering_type.value,
163+
'd-spacing',
164+
)
165+
]
153166
else:
154-
axes_labels = DEFAULT_AXES_LABELS[expt_type.scattering_type.value][expt_type.beam_mode.value]
167+
axes_labels = DEFAULT_AXES_LABELS[
168+
(
169+
expt_type.scattering_type.value,
170+
expt_type.beam_mode.value,
171+
)
172+
]
155173

156174
self._plotter.plot(
157175
x=x,
@@ -199,9 +217,19 @@ def plot_calc(
199217
y_labels = ['calc']
200218

201219
if d_spacing:
202-
axes_labels = DEFAULT_AXES_LABELS[expt_type.scattering_type.value]['d-spacing']
220+
axes_labels = DEFAULT_AXES_LABELS[
221+
(
222+
expt_type.scattering_type.value,
223+
'd-spacing',
224+
)
225+
]
203226
else:
204-
axes_labels = DEFAULT_AXES_LABELS[expt_type.scattering_type.value][expt_type.beam_mode.value]
227+
axes_labels = DEFAULT_AXES_LABELS[
228+
(
229+
expt_type.scattering_type.value,
230+
expt_type.beam_mode.value,
231+
)
232+
]
205233

206234
self._plotter.plot(
207235
x=x,
@@ -259,9 +287,19 @@ def plot_meas_vs_calc(
259287
y_labels = ['meas', 'calc']
260288

261289
if d_spacing:
262-
axes_labels = DEFAULT_AXES_LABELS[expt_type.scattering_type.value]['d-spacing']
290+
axes_labels = DEFAULT_AXES_LABELS[
291+
(
292+
expt_type.scattering_type.value,
293+
'd-spacing',
294+
)
295+
]
263296
else:
264-
axes_labels = DEFAULT_AXES_LABELS[expt_type.scattering_type.value][expt_type.beam_mode.value]
297+
axes_labels = DEFAULT_AXES_LABELS[
298+
(
299+
expt_type.scattering_type.value,
300+
expt_type.beam_mode.value,
301+
)
302+
]
265303

266304
if show_residual:
267305
y_resid = y_meas - y_calc

0 commit comments

Comments
 (0)