• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

openmc-dev / openmc / 28975504630

08 Jul 2026 09:02PM UTC coverage: 81.341% (+0.07%) from 81.267%
28975504630

Pull #3971

github

web-flow
Merge af2ecaf51 into 8b15ee391
Pull Request #3971: Delta tracking

18549 of 26870 branches covered (69.03%)

Branch coverage included in aggregate %.

614 of 661 new or added lines in 20 files covered. (92.89%)

545 existing lines in 20 files now uncovered.

59935 of 69618 relevant lines covered (86.09%)

49705850.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.86
/openmc/lib/plot.py
1
from collections.abc import Mapping
11✔
2
from ctypes import (c_bool, c_int, c_size_t, c_int32,
11✔
3
                    c_double, c_uint8, Structure, POINTER)
4
from weakref import WeakValueDictionary
11✔
5

6
from ..exceptions import AllocationError, InvalidIDError
11✔
7
from . import _dll
11✔
8
from .core import _FortranObjectWithID
11✔
9
from .error import _error_handler
11✔
10

11
import numpy as np
11✔
12
import warnings
11✔
13

14

15
class _Position(Structure):
11✔
16
    """Definition of an xyz location in space with underlying c-types
17

18
    C-type Attributes
19
    -----------------
20
    x : c_double
21
        Position's x value (default: 0.0)
22
    y : c_double
23
        Position's y value (default: 0.0)
24
    z : c_double
25
        Position's z value (default: 0.0)
26
    """
27
    _fields_ = [('x', c_double),
11✔
28
                ('y', c_double),
29
                ('z', c_double)]
30

31
    def __getitem__(self, idx):
11✔
32
        if idx == 0:
11✔
33
            return self.x
11✔
34
        elif idx == 1:
11✔
35
            return self.y
11✔
36
        elif idx == 2:
11✔
37
            return self.z
11✔
38
        else:
39
            raise IndexError(f"{idx} index is invalid for _Position")
11✔
40

41
    def __setitem__(self, idx, val):
11✔
42
        if idx == 0:
11✔
43
            self.x = val
11✔
44
        elif idx == 1:
11✔
45
            self.y = val
11✔
46
        elif idx == 2:
11✔
47
            self.z = val
11✔
48
        else:
49
            raise IndexError(f"{idx} index is invalid for _Position")
×
50

51
    def __repr__(self):
11✔
52
        return f"({self.x}, {self.y}, {self.z})"
×
53

54

55
def _extract_slice_data_args(plot):
11✔
56
    """Convert a legacy plot-like object into slice_data keyword arguments."""
57
    try:
11✔
58
        kwargs = {
11✔
59
            'origin': tuple(plot.origin),
60
            'width': (plot.width, plot.height),
61
            'basis': plot.basis,
62
            'pixels': (plot.h_res, plot.v_res),
63
            'show_overlaps': getattr(plot, 'color_overlaps', False),
64
            'level': getattr(plot, 'level', -1),
65
        }
66
    except AttributeError as exc:
×
67
        raise TypeError(
×
68
            "plot must be a legacy plot-like object with origin, width, "
69
            "height, basis, h_res, and v_res attributes."
70
        ) from exc
71
    return kwargs
11✔
72

73

74
_dll.openmc_slice_data.argtypes = [
11✔
75
    POINTER(c_double * 3),   # origin
76
    POINTER(c_double * 3),   # u_span
77
    POINTER(c_double * 3),   # v_span
78
    POINTER(c_size_t * 2),   # pixels
79
    c_bool,                  # show_overlaps
80
    c_int,                   # level
81
    c_int32,                 # filter_index
82
    POINTER(c_int32),        # geom_data
83
    POINTER(c_double),       # property_data (can be None)
84
]
85
_dll.openmc_slice_data.restype = c_int
11✔
86
_dll.openmc_slice_data.errcheck = _error_handler
11✔
87

88

89
def slice_data(origin, width=None, basis='xy', u_span=None, v_span=None,
11✔
90
                pixels=None, show_overlaps=False, level=-1, filter=None,
91
                include_properties=True):
92
    """Generate a 2D raster of geometry and property data for plotting.
93

94
    Parameters
95
    ----------
96
    origin : sequence of float
97
        Center position of the plot [x, y, z]
98
    width : sequence of float
99
        Width of the plot [horizontal, vertical]. Mutually exclusive with
100
        u_span/v_span.
101
    basis : {'xy', 'xz', 'yz'} or int
102
        Plot basis. Ignored if u_span/v_span are provided.
103
    u_span : sequence of float, optional
104
        Full-width span vector for the horizontal axis (3 values). Mutually
105
        exclusive with width.
106
    v_span : sequence of float, optional
107
        Full-height span vector for the vertical axis (3 values). Mutually
108
        exclusive with width.
109
    pixels : sequence of int
110
        Number of pixels [horizontal, vertical]
111
    show_overlaps : bool, optional
112
        Whether to detect overlapping cells
113
    level : int, optional
114
        Universe level (-1 for deepest)
115
    filter : openmc.lib.Filter, optional
116
        Filter for bin index lookup
117
    include_properties : bool, optional
118
        Whether to compute temperature/density
119

120
    Returns
121
    -------
122
    geom_data : numpy.ndarray
123
        Array of shape (v_res, h_res, 3) or (v_res, h_res, 4) with int32 dtype.
124
        Contains [cell_id, cell_instance, material_id] when no filter is provided,
125
        or [cell_id, cell_instance, material_id, filter_bin] when a filter is provided.
126
    property_data : numpy.ndarray or None
127
        Array of shape (v_res, h_res, 2) with float64 dtype containing
128
        [temperature, density], or None if include_properties=False
129
    """
130
    if pixels is None:
11✔
131
        raise ValueError("pixels must be specified.")
×
132
    if len(pixels) != 2:
11✔
133
        raise ValueError("pixels must be a length-2 sequence.")
×
134

135
    if width is not None and (u_span is not None or v_span is not None):
11✔
136
        raise ValueError("width is mutually exclusive with u_span/v_span.")
×
137

138
    if u_span is not None or v_span is not None:
11✔
139
        if u_span is None or v_span is None:
11✔
140
            raise ValueError("Both u_span and v_span must be provided.")
×
141
        u_span = np.asarray(u_span, dtype=float)
11✔
142
        v_span = np.asarray(v_span, dtype=float)
11✔
143
        if u_span.shape != (3,) or v_span.shape != (3,):
11✔
144
            raise ValueError("u_span and v_span must be length-3 sequences.")
×
145
        u_norm = np.linalg.norm(u_span)
11✔
146
        v_norm = np.linalg.norm(v_span)
11✔
147
        if u_norm == 0.0 or v_norm == 0.0:
11✔
148
            raise ValueError("u_span and v_span must be non-zero vectors.")
×
149
        dot = float(np.dot(u_span, v_span))
11✔
150
        ortho_tol = 1.0e-10 * u_norm * v_norm
11✔
151
        if abs(dot) > ortho_tol:
11✔
152
            raise ValueError("u_span and v_span must be orthogonal.")
×
153
    else:
154
        if width is None:
11✔
155
            raise ValueError("width must be provided when u_span/v_span are not set.")
×
156
        if len(width) != 2:
11✔
157
            raise ValueError("width must be a length-2 sequence.")
×
158
        basis_map = {'xy': 1, 'xz': 2, 'yz': 3}
11✔
159
        if isinstance(basis, str):
11✔
160
            basis = basis.lower()
11✔
161
            if basis not in basis_map:
11✔
162
                raise ValueError(f"{basis} is not a valid plot basis.")
×
163
            basis = basis_map[basis]
11✔
164
        elif isinstance(basis, int):
×
165
            if basis not in basis_map.values():
×
166
                raise ValueError(f"{basis} is not a valid plot basis.")
×
167
        else:
168
            raise ValueError(f"{basis} is not a valid plot basis.")
×
169

170
        if basis == 1:
11✔
171
            u_span = np.array([width[0], 0.0, 0.0], dtype=float)
11✔
172
            v_span = np.array([0.0, width[1], 0.0], dtype=float)
11✔
173
        elif basis == 2:
11✔
174
            u_span = np.array([width[0], 0.0, 0.0], dtype=float)
11✔
175
            v_span = np.array([0.0, 0.0, width[1]], dtype=float)
11✔
176
        else:
177
            u_span = np.array([0.0, width[0], 0.0], dtype=float)
11✔
178
            v_span = np.array([0.0, 0.0, width[1]], dtype=float)
11✔
179

180
    origin = np.asarray(origin, dtype=float)
11✔
181
    if origin.shape != (3,):
11✔
182
        raise ValueError("origin must be a length-3 sequence.")
×
183

184
    # Prepare ctypes arrays
185
    origin_arr = (c_double * 3)(*origin)
11✔
186
    u_span_arr = (c_double * 3)(*u_span)
11✔
187
    v_span_arr = (c_double * 3)(*v_span)
11✔
188
    pixels_arr = (c_size_t * 2)(*pixels)
11✔
189

190
    # Get internal filter index from filter ID if filter is provided
191
    if filter is not None:
11✔
192
        filter_index = c_int32()
11✔
193
        _dll.openmc_get_filter_index(filter.id, filter_index)
11✔
194
        filter_index = filter_index.value
11✔
195
    else:
196
        filter_index = -1
11✔
197

198
    # Allocate output arrays with dynamic size based on filter
199
    n_geom_fields = 4 if filter is not None else 3
11✔
200
    geom_data = np.zeros((pixels[1], pixels[0], n_geom_fields), dtype=np.int32)
11✔
201
    if include_properties:
11✔
202
        property_data = np.zeros((pixels[1], pixels[0], 2), dtype=np.float64)
11✔
203
        prop_ptr = property_data.ctypes.data_as(POINTER(c_double))
11✔
204
    else:
205
        property_data = None
11✔
206
        prop_ptr = None
11✔
207

208
    _dll.openmc_slice_data(
11✔
209
        origin_arr,
210
        u_span_arr,
211
        v_span_arr,
212
        pixels_arr,
213
        show_overlaps,
214
        level,
215
        filter_index,
216
        geom_data.ctypes.data_as(POINTER(c_int32)),
217
        prop_ptr
218
    )
219

220
    return geom_data, property_data
11✔
221

222

223
def id_map(plot):
11✔
224
    """Deprecated compatibility wrapper for geometry ID maps.
225

226
    This function is kept for compatibility and will be removed in a future
227
    release. Use `slice_data(..., include_properties=False)` instead.
228
    """
229
    warnings.warn(
11✔
230
        "openmc.lib.id_map is deprecated and will be removed in a future "
231
        "release; use openmc.lib.slice_data(..., include_properties=False).",
232
        FutureWarning,
233
    )
234

235
    kwargs = _extract_slice_data_args(plot)
11✔
236
    geom_data, _ = slice_data(include_properties=False, **kwargs)
11✔
237
    return geom_data[:, :, :3]
11✔
238

239

240
def property_map(plot):
11✔
241
    """Deprecated compatibility wrapper for temperature/density maps.
242

243
    This function is kept for compatibility and will be removed in a future
244
    release. Use `slice_data(..., include_properties=True)` instead.
245
    """
246
    warnings.warn(
11✔
247
        "openmc.lib.property_map is deprecated and will be removed in a "
248
        "future release; use openmc.lib.slice_data(..., "
249
        "include_properties=True).",
250
        FutureWarning,
251
    )
252

253
    kwargs = _extract_slice_data_args(plot)
11✔
254
    _, prop_data = slice_data(include_properties=True, **kwargs)
11✔
255
    return prop_data
11✔
256

257

258
_dll.openmc_slice_data_overlap_count.argtypes = [POINTER(c_size_t)]
11✔
259
_dll.openmc_slice_data_overlap_count.restype = c_int
11✔
260
_dll.openmc_slice_data_overlap_count.errcheck = _error_handler
11✔
261

262
_dll.openmc_slice_data_overlap_info.argtypes = [c_size_t, POINTER(c_int32)]
11✔
263
_dll.openmc_slice_data_overlap_info.restype = c_int
11✔
264
_dll.openmc_slice_data_overlap_info.errcheck = _error_handler
11✔
265

266

267
# Python wrappings for overlap functions
268
def slice_data_overlap_count():
11✔
269
    count = c_size_t()
11✔
270
    _dll.openmc_slice_data_overlap_count(count)
11✔
271
    return count.value
11✔
272

273

274
def slice_data_overlap_info():
11✔
275
    n = slice_data_overlap_count()
11✔
276
    overlap_info = np.empty(n * 3, dtype=np.int32)
11✔
277

278
    if n > 0:
11✔
279
        _dll.openmc_slice_data_overlap_info(
11✔
280
            n,
281
            overlap_info.ctypes.data_as(POINTER(c_int32)),
282
        )
283
    return overlap_info, n
11✔
284

285

286
_dll.openmc_get_plot_index.argtypes = [c_int32, POINTER(c_int32)]
11✔
287
_dll.openmc_get_plot_index.restype = c_int
11✔
288
_dll.openmc_get_plot_index.errcheck = _error_handler
11✔
289

290
_dll.openmc_plot_get_id.argtypes = [c_int32, POINTER(c_int32)]
11✔
291
_dll.openmc_plot_get_id.restype = c_int
11✔
292
_dll.openmc_plot_get_id.errcheck = _error_handler
11✔
293

294
_dll.openmc_plot_set_id.argtypes = [c_int32, c_int32]
11✔
295
_dll.openmc_plot_set_id.restype = c_int
11✔
296
_dll.openmc_plot_set_id.errcheck = _error_handler
11✔
297

298
_dll.openmc_plots_size.restype = c_size_t
11✔
299

300
_dll.openmc_solidraytrace_plot_create.argtypes = [POINTER(c_int32)]
11✔
301
_dll.openmc_solidraytrace_plot_create.restype = c_int
11✔
302
_dll.openmc_solidraytrace_plot_create.errcheck = _error_handler
11✔
303

304
_dll.openmc_solidraytrace_plot_get_pixels.argtypes = [
11✔
305
    c_int32, POINTER(c_int32), POINTER(c_int32)]
306
_dll.openmc_solidraytrace_plot_get_pixels.restype = c_int
11✔
307
_dll.openmc_solidraytrace_plot_get_pixels.errcheck = _error_handler
11✔
308

309
_dll.openmc_solidraytrace_plot_set_pixels.argtypes = [c_int32, c_int32, c_int32]
11✔
310
_dll.openmc_solidraytrace_plot_set_pixels.restype = c_int
11✔
311
_dll.openmc_solidraytrace_plot_set_pixels.errcheck = _error_handler
11✔
312

313
_dll.openmc_solidraytrace_plot_get_color_by.argtypes = [c_int32, POINTER(c_int32)]
11✔
314
_dll.openmc_solidraytrace_plot_get_color_by.restype = c_int
11✔
315
_dll.openmc_solidraytrace_plot_get_color_by.errcheck = _error_handler
11✔
316

317
_dll.openmc_solidraytrace_plot_set_color_by.argtypes = [c_int32, c_int32]
11✔
318
_dll.openmc_solidraytrace_plot_set_color_by.restype = c_int
11✔
319
_dll.openmc_solidraytrace_plot_set_color_by.errcheck = _error_handler
11✔
320

321
_dll.openmc_solidraytrace_plot_set_default_colors.argtypes = [c_int32]
11✔
322
_dll.openmc_solidraytrace_plot_set_default_colors.restype = c_int
11✔
323
_dll.openmc_solidraytrace_plot_set_default_colors.errcheck = _error_handler
11✔
324

325
_dll.openmc_solidraytrace_plot_set_all_opaque.argtypes = [c_int32]
11✔
326
_dll.openmc_solidraytrace_plot_set_all_opaque.restype = c_int
11✔
327
_dll.openmc_solidraytrace_plot_set_all_opaque.errcheck = _error_handler
11✔
328

329
_dll.openmc_solidraytrace_plot_set_opaque.argtypes = [c_int32, c_int32, c_bool]
11✔
330
_dll.openmc_solidraytrace_plot_set_opaque.restype = c_int
11✔
331
_dll.openmc_solidraytrace_plot_set_opaque.errcheck = _error_handler
11✔
332

333
_dll.openmc_solidraytrace_plot_set_color.argtypes = [c_int32, c_int32, c_uint8, c_uint8, c_uint8]
11✔
334
_dll.openmc_solidraytrace_plot_set_color.restype = c_int
11✔
335
_dll.openmc_solidraytrace_plot_set_color.errcheck = _error_handler
11✔
336

337
_dll.openmc_solidraytrace_plot_get_camera_position.argtypes = [
11✔
338
    c_int32, POINTER(c_double), POINTER(c_double), POINTER(c_double)]
339
_dll.openmc_solidraytrace_plot_get_camera_position.restype = c_int
11✔
340
_dll.openmc_solidraytrace_plot_get_camera_position.errcheck = _error_handler
11✔
341

342
_dll.openmc_solidraytrace_plot_set_camera_position.argtypes = [c_int32, c_double, c_double, c_double]
11✔
343
_dll.openmc_solidraytrace_plot_set_camera_position.restype = c_int
11✔
344
_dll.openmc_solidraytrace_plot_set_camera_position.errcheck = _error_handler
11✔
345

346
_dll.openmc_solidraytrace_plot_get_look_at.argtypes = [
11✔
347
    c_int32, POINTER(c_double), POINTER(c_double), POINTER(c_double)]
348
_dll.openmc_solidraytrace_plot_get_look_at.restype = c_int
11✔
349
_dll.openmc_solidraytrace_plot_get_look_at.errcheck = _error_handler
11✔
350

351
_dll.openmc_solidraytrace_plot_set_look_at.argtypes = [c_int32, c_double, c_double, c_double]
11✔
352
_dll.openmc_solidraytrace_plot_set_look_at.restype = c_int
11✔
353
_dll.openmc_solidraytrace_plot_set_look_at.errcheck = _error_handler
11✔
354

355
_dll.openmc_solidraytrace_plot_get_up.argtypes = [
11✔
356
    c_int32, POINTER(c_double), POINTER(c_double), POINTER(c_double)]
357
_dll.openmc_solidraytrace_plot_get_up.restype = c_int
11✔
358
_dll.openmc_solidraytrace_plot_get_up.errcheck = _error_handler
11✔
359

360
_dll.openmc_solidraytrace_plot_set_up.argtypes = [c_int32, c_double, c_double, c_double]
11✔
361
_dll.openmc_solidraytrace_plot_set_up.restype = c_int
11✔
362
_dll.openmc_solidraytrace_plot_set_up.errcheck = _error_handler
11✔
363

364
_dll.openmc_solidraytrace_plot_get_light_position.argtypes = [
11✔
365
    c_int32, POINTER(c_double), POINTER(c_double), POINTER(c_double)]
366
_dll.openmc_solidraytrace_plot_get_light_position.restype = c_int
11✔
367
_dll.openmc_solidraytrace_plot_get_light_position.errcheck = _error_handler
11✔
368

369
_dll.openmc_solidraytrace_plot_set_light_position.argtypes = [c_int32, c_double, c_double, c_double]
11✔
370
_dll.openmc_solidraytrace_plot_set_light_position.restype = c_int
11✔
371
_dll.openmc_solidraytrace_plot_set_light_position.errcheck = _error_handler
11✔
372

373
_dll.openmc_solidraytrace_plot_get_fov.argtypes = [c_int32, POINTER(c_double)]
11✔
374
_dll.openmc_solidraytrace_plot_get_fov.restype = c_int
11✔
375
_dll.openmc_solidraytrace_plot_get_fov.errcheck = _error_handler
11✔
376

377
_dll.openmc_solidraytrace_plot_set_fov.argtypes = [c_int32, c_double]
11✔
378
_dll.openmc_solidraytrace_plot_set_fov.restype = c_int
11✔
379
_dll.openmc_solidraytrace_plot_set_fov.errcheck = _error_handler
11✔
380

381
_dll.openmc_solidraytrace_plot_update_view.argtypes = [c_int32]
11✔
382
_dll.openmc_solidraytrace_plot_update_view.restype = c_int
11✔
383
_dll.openmc_solidraytrace_plot_update_view.errcheck = _error_handler
11✔
384

385
_dll.openmc_solidraytrace_plot_create_image.argtypes = [c_int32, POINTER(c_uint8), c_int32, c_int32]
11✔
386
_dll.openmc_solidraytrace_plot_create_image.restype = c_int
11✔
387
_dll.openmc_solidraytrace_plot_create_image.errcheck = _error_handler
11✔
388

389
_dll.openmc_solidraytrace_plot_get_color.argtypes = [c_int32, c_int32,
11✔
390
                                             POINTER(c_uint8), POINTER(c_uint8), POINTER(c_uint8)]
391
_dll.openmc_solidraytrace_plot_get_color.restype = c_int
11✔
392
_dll.openmc_solidraytrace_plot_get_color.errcheck = _error_handler
11✔
393

394
_dll.openmc_solidraytrace_plot_get_diffuse_fraction.argtypes = [
11✔
395
    c_int32, POINTER(c_double)]
396
_dll.openmc_solidraytrace_plot_get_diffuse_fraction.restype = c_int
11✔
397
_dll.openmc_solidraytrace_plot_get_diffuse_fraction.errcheck = _error_handler
11✔
398

399
_dll.openmc_solidraytrace_plot_set_diffuse_fraction.argtypes = [c_int32, c_double]
11✔
400
_dll.openmc_solidraytrace_plot_set_diffuse_fraction.restype = c_int
11✔
401
_dll.openmc_solidraytrace_plot_set_diffuse_fraction.errcheck = _error_handler
11✔
402

403

404
class SolidRayTracePlot(_FortranObjectWithID):
11✔
405
    """Solid ray-traced plot stored internally.
406

407
    This class exposes a solid ray-traced plot that is stored internally in
408
    the OpenMC library. To obtain a view of an existing plot with a given ID,
409
    use the :data:`openmc.lib.plots` mapping.
410

411
    Parameters
412
    ----------
413
    uid : int or None
414
        Unique ID of the plot
415
    new : bool
416
        When `index` is None, this argument controls whether a new object is
417
        created or a view of an existing object is returned.
418
    index : int or None
419
        Index in the internal plots array.
420

421
    Attributes
422
    ----------
423
    id : int
424
        Unique ID of the plot.
425
    pixels : tuple of int
426
        Plot image dimensions as ``(width, height)``.
427
    color_by : int
428
        Coloring mode. Use :attr:`COLOR_BY_MATERIAL` or
429
        :attr:`COLOR_BY_CELL`.
430
    camera_position : tuple of float
431
        Camera position as ``(x, y, z)``.
432
    look_at : tuple of float
433
        Point the camera is aimed at as ``(x, y, z)``.
434
    up : tuple of float
435
        Up direction as ``(x, y, z)``.
436
    light_position : tuple of float
437
        Position of the light source as ``(x, y, z)``.
438
    fov : float
439
        Horizontal field-of-view angle in degrees.
440
    diffuse_fraction : float
441
        Fraction of reflected light treated as diffuse (0 to 1).
442
    """
443

444
    COLOR_BY_MATERIAL = 0
11✔
445
    COLOR_BY_CELL = 1
11✔
446
    __instances = WeakValueDictionary()
11✔
447

448
    def __new__(cls, uid=None, new=True, index=None):
11✔
449
        mapping = plots
11✔
450
        if index is None:
11✔
451
            if new:
11✔
452
                if uid is not None and uid in mapping:
11✔
UNCOV
453
                    raise AllocationError(
×
454
                        f'A plot with ID={uid} has already been allocated.'
455
                    )
456
                index = c_int32()
11✔
457
                _dll.openmc_solidraytrace_plot_create(index)
11✔
458
                index = index.value
11✔
459
            else:
UNCOV
460
                index = mapping[uid]._index
×
461

462
        if index not in cls.__instances:
11✔
463
            instance = super().__new__(cls)
11✔
464
            instance._index = index
11✔
465
            if uid is not None:
11✔
UNCOV
466
                instance.id = uid
×
467
            cls.__instances[index] = instance
11✔
468

469
        return cls.__instances[index]
11✔
470

471
    def __init__(self, uid=None, new=True, index=None):
11✔
472
        super().__init__(uid, new, index)
11✔
473

474
    @property
11✔
475
    def id(self):
11✔
476
        plot_id = c_int32()
11✔
477
        _dll.openmc_plot_get_id(self._index, plot_id)
11✔
478
        return plot_id.value
11✔
479

480
    @id.setter
11✔
481
    def id(self, plot_id):
11✔
UNCOV
482
        _dll.openmc_plot_set_id(self._index, plot_id)
×
483

484
    @staticmethod
11✔
485
    def _get_xyz(getter, index):
11✔
486
        x = c_double()
11✔
487
        y = c_double()
11✔
488
        z = c_double()
11✔
489
        getter(index, x, y, z)
11✔
490
        return (x.value, y.value, z.value)
11✔
491

492
    @staticmethod
11✔
493
    def _set_xyz(setter, index, xyz):
11✔
494
        x, y, z = xyz
11✔
495
        setter(index, float(x), float(y), float(z))
11✔
496

497
    @property
11✔
498
    def pixels(self):
11✔
499
        width = c_int32()
11✔
500
        height = c_int32()
11✔
501
        _dll.openmc_solidraytrace_plot_get_pixels(self._index, width, height)
11✔
502
        return (width.value, height.value)
11✔
503

504
    @pixels.setter
11✔
505
    def pixels(self, pixels):
11✔
506
        width, height = pixels
11✔
507
        _dll.openmc_solidraytrace_plot_set_pixels(
11✔
508
            self._index, int(width), int(height))
509

510
    @property
11✔
511
    def color_by(self):
11✔
512
        color_by = c_int32()
11✔
513
        _dll.openmc_solidraytrace_plot_get_color_by(self._index, color_by)
11✔
514
        return color_by.value
11✔
515

516
    @color_by.setter
11✔
517
    def color_by(self, color_by):
11✔
518
        _dll.openmc_solidraytrace_plot_set_color_by(self._index, int(color_by))
11✔
519

520
    def set_default_colors(self):
11✔
521
        _dll.openmc_solidraytrace_plot_set_default_colors(self._index)
11✔
522

523
    def set_all_opaque(self):
11✔
UNCOV
524
        _dll.openmc_solidraytrace_plot_set_all_opaque(self._index)
×
525

526
    def set_visibility(self, domain_id, visible):
11✔
527
        _dll.openmc_solidraytrace_plot_set_opaque(
11✔
528
            self._index, int(domain_id), bool(visible)
529
        )
530

531
    def set_color(self, domain_id, color):
11✔
532
        r, g, b = [int(c) for c in color]
11✔
533
        _dll.openmc_solidraytrace_plot_set_color(
11✔
534
            self._index, int(domain_id), r, g, b)
535

536
    @property
11✔
537
    def camera_position(self):
11✔
538
        return self._get_xyz(_dll.openmc_solidraytrace_plot_get_camera_position,
11✔
539
                             self._index)
540

541
    @camera_position.setter
11✔
542
    def camera_position(self, position):
11✔
543
        self._set_xyz(_dll.openmc_solidraytrace_plot_set_camera_position,
11✔
544
                      self._index, position)
545

546
    @property
11✔
547
    def look_at(self):
11✔
548
        return self._get_xyz(_dll.openmc_solidraytrace_plot_get_look_at,
11✔
549
                             self._index)
550

551
    @look_at.setter
11✔
552
    def look_at(self, position):
11✔
553
        self._set_xyz(_dll.openmc_solidraytrace_plot_set_look_at,
11✔
554
                      self._index, position)
555

556
    @property
11✔
557
    def up(self):
11✔
558
        return self._get_xyz(_dll.openmc_solidraytrace_plot_get_up, self._index)
11✔
559

560
    @up.setter
11✔
561
    def up(self, direction):
11✔
562
        self._set_xyz(_dll.openmc_solidraytrace_plot_set_up, self._index,
11✔
563
                      direction)
564

565
    @property
11✔
566
    def light_position(self):
11✔
567
        return self._get_xyz(_dll.openmc_solidraytrace_plot_get_light_position,
11✔
568
                             self._index)
569

570
    @light_position.setter
11✔
571
    def light_position(self, position):
11✔
572
        self._set_xyz(_dll.openmc_solidraytrace_plot_set_light_position,
11✔
573
                      self._index, position)
574

575
    @property
11✔
576
    def fov(self):
11✔
577
        fov = c_double()
11✔
578
        _dll.openmc_solidraytrace_plot_get_fov(self._index, fov)
11✔
579
        return fov.value
11✔
580

581
    @fov.setter
11✔
582
    def fov(self, fov):
11✔
583
        _dll.openmc_solidraytrace_plot_set_fov(self._index, float(fov))
11✔
584

585
    def update_view(self):
11✔
586
        _dll.openmc_solidraytrace_plot_update_view(self._index)
11✔
587

588
    def create_image(self):
11✔
589
        width, height = self.pixels
11✔
590
        image = np.zeros((height, width, 3), dtype=np.uint8)
11✔
591
        _dll.openmc_solidraytrace_plot_create_image(
11✔
592
            self._index,
593
            image.ctypes.data_as(POINTER(c_uint8)),
594
            width,
595
            height
596
        )
597
        return image
11✔
598

599
    def get_color(self, domain_id):
11✔
600
        r = c_uint8()
11✔
601
        g = c_uint8()
11✔
602
        b = c_uint8()
11✔
603
        _dll.openmc_solidraytrace_plot_get_color(
11✔
604
            self._index, int(domain_id), r, g, b)
605
        return int(r.value), int(g.value), int(b.value)
11✔
606

607
    @property
11✔
608
    def diffuse_fraction(self):
11✔
609
        value = c_double()
11✔
610
        _dll.openmc_solidraytrace_plot_get_diffuse_fraction(self._index, value)
11✔
611
        return value.value
11✔
612

613
    @diffuse_fraction.setter
11✔
614
    def diffuse_fraction(self, value):
11✔
615
        _dll.openmc_solidraytrace_plot_set_diffuse_fraction(
11✔
616
            self._index, float(value))
617

618
    # Backward-compatible setter aliases
619
    def set_pixels(self, width, height):
11✔
UNCOV
620
        self.pixels = (width, height)
×
621

622
    def set_color_by(self, color_by):
11✔
UNCOV
623
        self.color_by = color_by
×
624

625
    def set_camera_position(self, x, y, z):
11✔
626
        self.camera_position = (x, y, z)
×
627

628
    def set_look_at(self, x, y, z):
11✔
UNCOV
629
        self.look_at = (x, y, z)
×
630

631
    def set_up(self, x, y, z):
11✔
UNCOV
632
        self.up = (x, y, z)
×
633

634
    def set_light_position(self, x, y, z):
11✔
UNCOV
635
        self.light_position = (x, y, z)
×
636

637
    def set_fov(self, fov):
11✔
UNCOV
638
        self.fov = fov
×
639

640
    def set_diffuse_fraction(self, value):
11✔
UNCOV
641
        self.diffuse_fraction = value
×
642

643

644
class _PlotMapping(Mapping):
11✔
645
    def __getitem__(self, key):
11✔
646
        index = c_int32()
11✔
647
        try:
11✔
648
            _dll.openmc_get_plot_index(key, index)
11✔
UNCOV
649
        except (AllocationError, InvalidIDError) as e:
×
UNCOV
650
            raise KeyError(str(e))
×
651
        return SolidRayTracePlot(index=index.value)
11✔
652

653
    def __iter__(self):
11✔
UNCOV
654
        for i in range(len(self)):
×
UNCOV
655
            yield SolidRayTracePlot(index=i).id
×
656

657
    def __len__(self):
11✔
658
        return _dll.openmc_plots_size()
11✔
659

660
    def __repr__(self):
11✔
UNCOV
661
        return repr(dict(self))
×
662

663

664
plots = _PlotMapping()
11✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc