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

openmc-dev / openmc / 27291478556

10 Jun 2026 04:47PM UTC coverage: 80.477% (-0.9%) from 81.356%
27291478556

Pull #3951

github

web-flow
Merge a9c9d6b5d into 02eb999af
Pull Request #3951: wwinp files: Fix MemoryError in WeightWindowsList.export_to_hdf5 and speed up from_wwinp. Alternative Approach

16680 of 24156 branches covered (69.05%)

Branch coverage included in aggregate %.

70 of 119 new or added lines in 10 files covered. (58.82%)

1139 existing lines in 52 files now uncovered.

57358 of 67843 relevant lines covered (84.55%)

17252148.68 hits per line

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

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

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

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

14

15
class _Position(Structure):
2✔
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),
2✔
28
                ('y', c_double),
29
                ('z', c_double)]
30

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

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

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

54

55
def _extract_slice_data_args(plot):
2✔
56
    """Convert a legacy plot-like object into slice_data keyword arguments."""
57
    try:
2✔
58
        kwargs = {
2✔
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
        }
UNCOV
66
    except AttributeError as exc:
×
UNCOV
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
2✔
72

73

74
_dll.openmc_slice_data.argtypes = [
2✔
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
2✔
86
_dll.openmc_slice_data.errcheck = _error_handler
2✔
87

88

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

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

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

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

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

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

208
    _dll.openmc_slice_data(
2✔
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
2✔
221

222

223
def id_map(plot):
2✔
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(
2✔
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)
2✔
236
    geom_data, _ = slice_data(include_properties=False, **kwargs)
2✔
237
    return geom_data[:, :, :3]
2✔
238

239

240
def property_map(plot):
2✔
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(
2✔
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)
2✔
254
    _, prop_data = slice_data(include_properties=True, **kwargs)
2✔
255
    return prop_data
2✔
256

257

258
_dll.openmc_get_plot_index.argtypes = [c_int32, POINTER(c_int32)]
2✔
259
_dll.openmc_get_plot_index.restype = c_int
2✔
260
_dll.openmc_get_plot_index.errcheck = _error_handler
2✔
261

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

266
_dll.openmc_plot_set_id.argtypes = [c_int32, c_int32]
2✔
267
_dll.openmc_plot_set_id.restype = c_int
2✔
268
_dll.openmc_plot_set_id.errcheck = _error_handler
2✔
269

270
_dll.openmc_plots_size.restype = c_size_t
2✔
271

272
_dll.openmc_solidraytrace_plot_create.argtypes = [POINTER(c_int32)]
2✔
273
_dll.openmc_solidraytrace_plot_create.restype = c_int
2✔
274
_dll.openmc_solidraytrace_plot_create.errcheck = _error_handler
2✔
275

276
_dll.openmc_solidraytrace_plot_get_pixels.argtypes = [
2✔
277
    c_int32, POINTER(c_int32), POINTER(c_int32)]
278
_dll.openmc_solidraytrace_plot_get_pixels.restype = c_int
2✔
279
_dll.openmc_solidraytrace_plot_get_pixels.errcheck = _error_handler
2✔
280

281
_dll.openmc_solidraytrace_plot_set_pixels.argtypes = [c_int32, c_int32, c_int32]
2✔
282
_dll.openmc_solidraytrace_plot_set_pixels.restype = c_int
2✔
283
_dll.openmc_solidraytrace_plot_set_pixels.errcheck = _error_handler
2✔
284

285
_dll.openmc_solidraytrace_plot_get_color_by.argtypes = [c_int32, POINTER(c_int32)]
2✔
286
_dll.openmc_solidraytrace_plot_get_color_by.restype = c_int
2✔
287
_dll.openmc_solidraytrace_plot_get_color_by.errcheck = _error_handler
2✔
288

289
_dll.openmc_solidraytrace_plot_set_color_by.argtypes = [c_int32, c_int32]
2✔
290
_dll.openmc_solidraytrace_plot_set_color_by.restype = c_int
2✔
291
_dll.openmc_solidraytrace_plot_set_color_by.errcheck = _error_handler
2✔
292

293
_dll.openmc_solidraytrace_plot_set_default_colors.argtypes = [c_int32]
2✔
294
_dll.openmc_solidraytrace_plot_set_default_colors.restype = c_int
2✔
295
_dll.openmc_solidraytrace_plot_set_default_colors.errcheck = _error_handler
2✔
296

297
_dll.openmc_solidraytrace_plot_set_all_opaque.argtypes = [c_int32]
2✔
298
_dll.openmc_solidraytrace_plot_set_all_opaque.restype = c_int
2✔
299
_dll.openmc_solidraytrace_plot_set_all_opaque.errcheck = _error_handler
2✔
300

301
_dll.openmc_solidraytrace_plot_set_opaque.argtypes = [c_int32, c_int32, c_bool]
2✔
302
_dll.openmc_solidraytrace_plot_set_opaque.restype = c_int
2✔
303
_dll.openmc_solidraytrace_plot_set_opaque.errcheck = _error_handler
2✔
304

305
_dll.openmc_solidraytrace_plot_set_color.argtypes = [c_int32, c_int32, c_uint8, c_uint8, c_uint8]
2✔
306
_dll.openmc_solidraytrace_plot_set_color.restype = c_int
2✔
307
_dll.openmc_solidraytrace_plot_set_color.errcheck = _error_handler
2✔
308

309
_dll.openmc_solidraytrace_plot_get_camera_position.argtypes = [
2✔
310
    c_int32, POINTER(c_double), POINTER(c_double), POINTER(c_double)]
311
_dll.openmc_solidraytrace_plot_get_camera_position.restype = c_int
2✔
312
_dll.openmc_solidraytrace_plot_get_camera_position.errcheck = _error_handler
2✔
313

314
_dll.openmc_solidraytrace_plot_set_camera_position.argtypes = [c_int32, c_double, c_double, c_double]
2✔
315
_dll.openmc_solidraytrace_plot_set_camera_position.restype = c_int
2✔
316
_dll.openmc_solidraytrace_plot_set_camera_position.errcheck = _error_handler
2✔
317

318
_dll.openmc_solidraytrace_plot_get_look_at.argtypes = [
2✔
319
    c_int32, POINTER(c_double), POINTER(c_double), POINTER(c_double)]
320
_dll.openmc_solidraytrace_plot_get_look_at.restype = c_int
2✔
321
_dll.openmc_solidraytrace_plot_get_look_at.errcheck = _error_handler
2✔
322

323
_dll.openmc_solidraytrace_plot_set_look_at.argtypes = [c_int32, c_double, c_double, c_double]
2✔
324
_dll.openmc_solidraytrace_plot_set_look_at.restype = c_int
2✔
325
_dll.openmc_solidraytrace_plot_set_look_at.errcheck = _error_handler
2✔
326

327
_dll.openmc_solidraytrace_plot_get_up.argtypes = [
2✔
328
    c_int32, POINTER(c_double), POINTER(c_double), POINTER(c_double)]
329
_dll.openmc_solidraytrace_plot_get_up.restype = c_int
2✔
330
_dll.openmc_solidraytrace_plot_get_up.errcheck = _error_handler
2✔
331

332
_dll.openmc_solidraytrace_plot_set_up.argtypes = [c_int32, c_double, c_double, c_double]
2✔
333
_dll.openmc_solidraytrace_plot_set_up.restype = c_int
2✔
334
_dll.openmc_solidraytrace_plot_set_up.errcheck = _error_handler
2✔
335

336
_dll.openmc_solidraytrace_plot_get_light_position.argtypes = [
2✔
337
    c_int32, POINTER(c_double), POINTER(c_double), POINTER(c_double)]
338
_dll.openmc_solidraytrace_plot_get_light_position.restype = c_int
2✔
339
_dll.openmc_solidraytrace_plot_get_light_position.errcheck = _error_handler
2✔
340

341
_dll.openmc_solidraytrace_plot_set_light_position.argtypes = [c_int32, c_double, c_double, c_double]
2✔
342
_dll.openmc_solidraytrace_plot_set_light_position.restype = c_int
2✔
343
_dll.openmc_solidraytrace_plot_set_light_position.errcheck = _error_handler
2✔
344

345
_dll.openmc_solidraytrace_plot_get_fov.argtypes = [c_int32, POINTER(c_double)]
2✔
346
_dll.openmc_solidraytrace_plot_get_fov.restype = c_int
2✔
347
_dll.openmc_solidraytrace_plot_get_fov.errcheck = _error_handler
2✔
348

349
_dll.openmc_solidraytrace_plot_set_fov.argtypes = [c_int32, c_double]
2✔
350
_dll.openmc_solidraytrace_plot_set_fov.restype = c_int
2✔
351
_dll.openmc_solidraytrace_plot_set_fov.errcheck = _error_handler
2✔
352

353
_dll.openmc_solidraytrace_plot_update_view.argtypes = [c_int32]
2✔
354
_dll.openmc_solidraytrace_plot_update_view.restype = c_int
2✔
355
_dll.openmc_solidraytrace_plot_update_view.errcheck = _error_handler
2✔
356

357
_dll.openmc_solidraytrace_plot_create_image.argtypes = [c_int32, POINTER(c_uint8), c_int32, c_int32]
2✔
358
_dll.openmc_solidraytrace_plot_create_image.restype = c_int
2✔
359
_dll.openmc_solidraytrace_plot_create_image.errcheck = _error_handler
2✔
360

361
_dll.openmc_solidraytrace_plot_get_color.argtypes = [c_int32, c_int32,
2✔
362
                                             POINTER(c_uint8), POINTER(c_uint8), POINTER(c_uint8)]
363
_dll.openmc_solidraytrace_plot_get_color.restype = c_int
2✔
364
_dll.openmc_solidraytrace_plot_get_color.errcheck = _error_handler
2✔
365

366
_dll.openmc_solidraytrace_plot_get_diffuse_fraction.argtypes = [
2✔
367
    c_int32, POINTER(c_double)]
368
_dll.openmc_solidraytrace_plot_get_diffuse_fraction.restype = c_int
2✔
369
_dll.openmc_solidraytrace_plot_get_diffuse_fraction.errcheck = _error_handler
2✔
370

371
_dll.openmc_solidraytrace_plot_set_diffuse_fraction.argtypes = [c_int32, c_double]
2✔
372
_dll.openmc_solidraytrace_plot_set_diffuse_fraction.restype = c_int
2✔
373
_dll.openmc_solidraytrace_plot_set_diffuse_fraction.errcheck = _error_handler
2✔
374

375

376
class SolidRayTracePlot(_FortranObjectWithID):
2✔
377
    """Solid ray-traced plot stored internally.
378

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

383
    Parameters
384
    ----------
385
    uid : int or None
386
        Unique ID of the plot
387
    new : bool
388
        When `index` is None, this argument controls whether a new object is
389
        created or a view of an existing object is returned.
390
    index : int or None
391
        Index in the internal plots array.
392

393
    Attributes
394
    ----------
395
    id : int
396
        Unique ID of the plot.
397
    pixels : tuple of int
398
        Plot image dimensions as ``(width, height)``.
399
    color_by : int
400
        Coloring mode. Use :attr:`COLOR_BY_MATERIAL` or
401
        :attr:`COLOR_BY_CELL`.
402
    camera_position : tuple of float
403
        Camera position as ``(x, y, z)``.
404
    look_at : tuple of float
405
        Point the camera is aimed at as ``(x, y, z)``.
406
    up : tuple of float
407
        Up direction as ``(x, y, z)``.
408
    light_position : tuple of float
409
        Position of the light source as ``(x, y, z)``.
410
    fov : float
411
        Horizontal field-of-view angle in degrees.
412
    diffuse_fraction : float
413
        Fraction of reflected light treated as diffuse (0 to 1).
414
    """
415

416
    COLOR_BY_MATERIAL = 0
2✔
417
    COLOR_BY_CELL = 1
2✔
418
    __instances = WeakValueDictionary()
2✔
419

420
    def __new__(cls, uid=None, new=True, index=None):
2✔
421
        mapping = plots
2✔
422
        if index is None:
2✔
423
            if new:
2✔
424
                if uid is not None and uid in mapping:
2✔
UNCOV
425
                    raise AllocationError(
×
426
                        f'A plot with ID={uid} has already been allocated.'
427
                    )
428
                index = c_int32()
2✔
429
                _dll.openmc_solidraytrace_plot_create(index)
2✔
430
                index = index.value
2✔
431
            else:
UNCOV
432
                index = mapping[uid]._index
×
433

434
        if index not in cls.__instances:
2✔
435
            instance = super().__new__(cls)
2✔
436
            instance._index = index
2✔
437
            if uid is not None:
2✔
UNCOV
438
                instance.id = uid
×
439
            cls.__instances[index] = instance
2✔
440

441
        return cls.__instances[index]
2✔
442

443
    def __init__(self, uid=None, new=True, index=None):
2✔
444
        super().__init__(uid, new, index)
2✔
445

446
    @property
2✔
447
    def id(self):
2✔
448
        plot_id = c_int32()
2✔
449
        _dll.openmc_plot_get_id(self._index, plot_id)
2✔
450
        return plot_id.value
2✔
451

452
    @id.setter
2✔
453
    def id(self, plot_id):
2✔
UNCOV
454
        _dll.openmc_plot_set_id(self._index, plot_id)
×
455

456
    @staticmethod
2✔
457
    def _get_xyz(getter, index):
2✔
458
        x = c_double()
2✔
459
        y = c_double()
2✔
460
        z = c_double()
2✔
461
        getter(index, x, y, z)
2✔
462
        return (x.value, y.value, z.value)
2✔
463

464
    @staticmethod
2✔
465
    def _set_xyz(setter, index, xyz):
2✔
466
        x, y, z = xyz
2✔
467
        setter(index, float(x), float(y), float(z))
2✔
468

469
    @property
2✔
470
    def pixels(self):
2✔
471
        width = c_int32()
2✔
472
        height = c_int32()
2✔
473
        _dll.openmc_solidraytrace_plot_get_pixels(self._index, width, height)
2✔
474
        return (width.value, height.value)
2✔
475

476
    @pixels.setter
2✔
477
    def pixels(self, pixels):
2✔
478
        width, height = pixels
2✔
479
        _dll.openmc_solidraytrace_plot_set_pixels(
2✔
480
            self._index, int(width), int(height))
481

482
    @property
2✔
483
    def color_by(self):
2✔
484
        color_by = c_int32()
2✔
485
        _dll.openmc_solidraytrace_plot_get_color_by(self._index, color_by)
2✔
486
        return color_by.value
2✔
487

488
    @color_by.setter
2✔
489
    def color_by(self, color_by):
2✔
490
        _dll.openmc_solidraytrace_plot_set_color_by(self._index, int(color_by))
2✔
491

492
    def set_default_colors(self):
2✔
493
        _dll.openmc_solidraytrace_plot_set_default_colors(self._index)
2✔
494

495
    def set_all_opaque(self):
2✔
UNCOV
496
        _dll.openmc_solidraytrace_plot_set_all_opaque(self._index)
×
497

498
    def set_visibility(self, domain_id, visible):
2✔
499
        _dll.openmc_solidraytrace_plot_set_opaque(
2✔
500
            self._index, int(domain_id), bool(visible)
501
        )
502

503
    def set_color(self, domain_id, color):
2✔
504
        r, g, b = [int(c) for c in color]
2✔
505
        _dll.openmc_solidraytrace_plot_set_color(
2✔
506
            self._index, int(domain_id), r, g, b)
507

508
    @property
2✔
509
    def camera_position(self):
2✔
510
        return self._get_xyz(_dll.openmc_solidraytrace_plot_get_camera_position,
2✔
511
                             self._index)
512

513
    @camera_position.setter
2✔
514
    def camera_position(self, position):
2✔
515
        self._set_xyz(_dll.openmc_solidraytrace_plot_set_camera_position,
2✔
516
                      self._index, position)
517

518
    @property
2✔
519
    def look_at(self):
2✔
520
        return self._get_xyz(_dll.openmc_solidraytrace_plot_get_look_at,
2✔
521
                             self._index)
522

523
    @look_at.setter
2✔
524
    def look_at(self, position):
2✔
525
        self._set_xyz(_dll.openmc_solidraytrace_plot_set_look_at,
2✔
526
                      self._index, position)
527

528
    @property
2✔
529
    def up(self):
2✔
530
        return self._get_xyz(_dll.openmc_solidraytrace_plot_get_up, self._index)
2✔
531

532
    @up.setter
2✔
533
    def up(self, direction):
2✔
534
        self._set_xyz(_dll.openmc_solidraytrace_plot_set_up, self._index,
2✔
535
                      direction)
536

537
    @property
2✔
538
    def light_position(self):
2✔
539
        return self._get_xyz(_dll.openmc_solidraytrace_plot_get_light_position,
2✔
540
                             self._index)
541

542
    @light_position.setter
2✔
543
    def light_position(self, position):
2✔
544
        self._set_xyz(_dll.openmc_solidraytrace_plot_set_light_position,
2✔
545
                      self._index, position)
546

547
    @property
2✔
548
    def fov(self):
2✔
549
        fov = c_double()
2✔
550
        _dll.openmc_solidraytrace_plot_get_fov(self._index, fov)
2✔
551
        return fov.value
2✔
552

553
    @fov.setter
2✔
554
    def fov(self, fov):
2✔
555
        _dll.openmc_solidraytrace_plot_set_fov(self._index, float(fov))
2✔
556

557
    def update_view(self):
2✔
558
        _dll.openmc_solidraytrace_plot_update_view(self._index)
2✔
559

560
    def create_image(self):
2✔
561
        width, height = self.pixels
2✔
562
        image = np.zeros((height, width, 3), dtype=np.uint8)
2✔
563
        _dll.openmc_solidraytrace_plot_create_image(
2✔
564
            self._index,
565
            image.ctypes.data_as(POINTER(c_uint8)),
566
            width,
567
            height
568
        )
569
        return image
2✔
570

571
    def get_color(self, domain_id):
2✔
572
        r = c_uint8()
2✔
573
        g = c_uint8()
2✔
574
        b = c_uint8()
2✔
575
        _dll.openmc_solidraytrace_plot_get_color(
2✔
576
            self._index, int(domain_id), r, g, b)
577
        return int(r.value), int(g.value), int(b.value)
2✔
578

579
    @property
2✔
580
    def diffuse_fraction(self):
2✔
581
        value = c_double()
2✔
582
        _dll.openmc_solidraytrace_plot_get_diffuse_fraction(self._index, value)
2✔
583
        return value.value
2✔
584

585
    @diffuse_fraction.setter
2✔
586
    def diffuse_fraction(self, value):
2✔
587
        _dll.openmc_solidraytrace_plot_set_diffuse_fraction(
2✔
588
            self._index, float(value))
589

590
    # Backward-compatible setter aliases
591
    def set_pixels(self, width, height):
2✔
UNCOV
592
        self.pixels = (width, height)
×
593

594
    def set_color_by(self, color_by):
2✔
UNCOV
595
        self.color_by = color_by
×
596

597
    def set_camera_position(self, x, y, z):
2✔
UNCOV
598
        self.camera_position = (x, y, z)
×
599

600
    def set_look_at(self, x, y, z):
2✔
UNCOV
601
        self.look_at = (x, y, z)
×
602

603
    def set_up(self, x, y, z):
2✔
UNCOV
604
        self.up = (x, y, z)
×
605

606
    def set_light_position(self, x, y, z):
2✔
UNCOV
607
        self.light_position = (x, y, z)
×
608

609
    def set_fov(self, fov):
2✔
UNCOV
610
        self.fov = fov
×
611

612
    def set_diffuse_fraction(self, value):
2✔
UNCOV
613
        self.diffuse_fraction = value
×
614

615

616
class _PlotMapping(Mapping):
2✔
617
    def __getitem__(self, key):
2✔
618
        index = c_int32()
2✔
619
        try:
2✔
620
            _dll.openmc_get_plot_index(key, index)
2✔
621
        except (AllocationError, InvalidIDError) as e:
×
UNCOV
622
            raise KeyError(str(e))
×
623
        return SolidRayTracePlot(index=index.value)
2✔
624

625
    def __iter__(self):
2✔
UNCOV
626
        for i in range(len(self)):
×
UNCOV
627
            yield SolidRayTracePlot(index=i).id
×
628

629
    def __len__(self):
2✔
630
        return _dll.openmc_plots_size()
2✔
631

632
    def __repr__(self):
2✔
UNCOV
633
        return repr(dict(self))
×
634

635

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

© 2026 Coveralls, Inc