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

openmc-dev / openmc / 26918794427

03 Jun 2026 11:09PM UTC coverage: 81.262% (-0.1%) from 81.382%
26918794427

Pull #3806

github

web-flow
Merge 93fff74ab into 111eb7706
Pull Request #3806: Introduce new C API function for slice plots

18131 of 26324 branches covered (68.88%)

Branch coverage included in aggregate %.

197 of 248 new or added lines in 4 files covered. (79.44%)

1156 existing lines in 34 files now uncovered.

59239 of 68887 relevant lines covered (85.99%)

48406720.12 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
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_plot_args(plot):
11✔
56
    """Convert a legacy plot-like object into slice_plot 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
            'color_overlaps': getattr(plot, 'color_overlaps', False),
64
            'level': getattr(plot, 'level', -1),
65
        }
NEW
66
    except AttributeError as exc:
×
NEW
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_plot.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,                  # color_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_plot.restype = c_int
11✔
86
_dll.openmc_slice_plot.errcheck = _error_handler
11✔
87

88

89
def slice_plot(origin, width=None, basis='xy', u_span=None, v_span=None,
11✔
90
                pixels=None, color_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
    color_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✔
NEW
131
        raise ValueError("pixels must be specified.")
×
132
    if len(pixels) != 2:
11✔
NEW
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✔
NEW
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✔
NEW
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✔
NEW
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✔
NEW
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✔
NEW
152
            raise ValueError("u_span and v_span must be orthogonal.")
×
153
    else:
154
        if width is None:
11✔
NEW
155
            raise ValueError("width must be provided when u_span/v_span are not set.")
×
156
        if len(width) != 2:
11✔
NEW
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✔
NEW
164
        elif isinstance(basis, int):
×
NEW
165
            if basis not in basis_map.values():
×
166
                raise ValueError(f"{basis} is not a valid plot basis.")
×
167
        else:
NEW
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✔
NEW
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_plot(
11✔
209
        origin_arr,
210
        u_span_arr,
211
        v_span_arr,
212
        pixels_arr,
213
        color_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_plot(..., 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_plot(..., include_properties=False).",
232
        FutureWarning,
233
    )
234

235
    kwargs = _extract_slice_plot_args(plot)
11✔
236
    geom_data, _ = slice_plot(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_plot(..., 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_plot(..., "
249
        "include_properties=True).",
250
        FutureWarning,
251
    )
252

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

257

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

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

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

270
_dll.openmc_plots_size.restype = c_size_t
11✔
271

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

375

376
class SolidRayTracePlot(_FortranObjectWithID):
11✔
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
11✔
417
    COLOR_BY_CELL = 1
11✔
418
    __instances = WeakValueDictionary()
11✔
419

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

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

441
        return cls.__instances[index]
11✔
442

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

615

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

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

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

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

635

636
plots = _PlotMapping()
11✔
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