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

openmc-dev / openmc / 21875369661

10 Feb 2026 05:26PM UTC coverage: 81.755% (-0.2%) from 81.905%
21875369661

Pull #3789

github

web-flow
Merge daf88bc9b into 3f20a5e22
Pull Request #3789: SolidRayTracePlot CAPI

17501 of 24590 branches covered (71.17%)

Branch coverage included in aggregate %.

469 of 624 new or added lines in 2 files covered. (75.16%)

1 existing line in 1 file now uncovered.

56684 of 66151 relevant lines covered (85.69%)

46447878.5 hits per line

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

88.37
/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

13

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

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

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

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

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

53

54
class _PlotBase(Structure):
11✔
55
    """A structure defining a 2-D geometry slice with underlying c-types
56

57
    C-Type Attributes
58
    -----------------
59
    origin_ : openmc.lib.plot._Position
60
        A position defining the origin of the plot.
61
    width_ : openmc.lib.plot._Position
62
        The width of the plot along the x, y, and z axes, respectively
63
    basis_ : c_int
64
        The axes basis of the plot view.
65
    pixels_ : c_size_t[3]
66
        The resolution of the plot in the horizontal and vertical dimensions
67
    color_overlaps_ : c_bool
68
        Whether to assign unique IDs (-3) to overlapping regions.
69
    level_ : c_int
70
        The universe level for the plot view
71

72
    Attributes
73
    ----------
74
    origin : tuple or list of ndarray
75
        Origin (center) of the plot
76
    width : float
77
        The horizontal dimension of the plot in geometry units (cm)
78
    height : float
79
        The vertical dimension of the plot in geometry units (cm)
80
    basis : string
81
        One of {'xy', 'xz', 'yz'} indicating the horizontal and vertical
82
        axes of the plot.
83
    h_res : int
84
        The horizontal resolution of the plot in pixels
85
    v_res : int
86
        The vertical resolution of the plot in pixels
87
    level : int
88
        The universe level for the plot (default: -1 -> all universes shown)
89
    """
90
    _fields_ = [('origin_', _Position),
11✔
91
                ('width_', _Position),
92
                ('basis_', c_int),
93
                ('pixels_', 3*c_size_t),
94
                ('color_overlaps_', c_bool),
95
                ('level_', c_int)]
96

97
    def __init__(self):
11✔
98
        self.level_ = -1
11✔
99
        self.basis_ = 1
11✔
100
        self.color_overlaps_ = False
11✔
101

102
    @property
11✔
103
    def origin(self):
11✔
104
        return self.origin_
×
105

106
    @origin.setter
11✔
107
    def origin(self, origin):
11✔
108
        self.origin_.x = origin[0]
11✔
109
        self.origin_.y = origin[1]
11✔
110
        self.origin_.z = origin[2]
11✔
111

112
    @property
11✔
113
    def width(self):
11✔
114
        return self.width_.x
×
115

116
    @width.setter
11✔
117
    def width(self, width):
11✔
118
        self.width_.x = width
11✔
119

120
    @property
11✔
121
    def height(self):
11✔
122
        return self.width_.y
×
123

124
    @height.setter
11✔
125
    def height(self, height):
11✔
126
        self.width_.y = height
11✔
127

128
    @property
11✔
129
    def basis(self):
11✔
130
        if self.basis_ == 1:
×
131
            return 'xy'
×
132
        elif self.basis_ == 2:
×
133
            return 'xz'
×
134
        elif self.basis_ == 3:
×
135
            return 'yz'
×
136

137
        raise ValueError(f"Plot basis {self.basis_} is invalid")
×
138

139
    @basis.setter
11✔
140
    def basis(self, basis):
11✔
141
        if isinstance(basis, str):
11✔
142
            valid_bases = ('xy', 'xz', 'yz')
11✔
143
            basis = basis.lower()
11✔
144
            if basis not in valid_bases:
11✔
145
                raise ValueError(f"{basis} is not a valid plot basis.")
×
146

147
            if basis == 'xy':
11✔
148
                self.basis_ = 1
11✔
149
            elif basis == 'xz':
11✔
150
                self.basis_ = 2
11✔
151
            elif basis == 'yz':
11✔
152
                self.basis_ = 3
11✔
153
            return
11✔
154

155
        if isinstance(basis, int):
×
156
            valid_bases = (1, 2, 3)
×
157
            if basis not in valid_bases:
×
158
                raise ValueError(f"{basis} is not a valid plot basis.")
×
159
            self.basis_ = basis
×
160
            return
×
161

162
        raise ValueError(f"{basis} of type {type(basis)} is an invalid plot basis")
×
163

164
    @property
11✔
165
    def h_res(self):
11✔
166
        return self.pixels_[0]
11✔
167

168
    @h_res.setter
11✔
169
    def h_res(self, h_res):
11✔
170
        self.pixels_[0] = h_res
11✔
171

172
    @property
11✔
173
    def v_res(self):
11✔
174
        return self.pixels_[1]
11✔
175

176
    @v_res.setter
11✔
177
    def v_res(self, v_res):
11✔
178
        self.pixels_[1] = v_res
11✔
179

180
    @property
11✔
181
    def level(self):
11✔
182
        return int(self.level_)
×
183

184
    @level.setter
11✔
185
    def level(self, level):
11✔
186
        self.level_ = level
11✔
187

188
    @property
11✔
189
    def color_overlaps(self):
11✔
190
        return self.color_overlaps_
×
191

192
    @color_overlaps.setter
11✔
193
    def color_overlaps(self, color_overlaps):
11✔
194
        self.color_overlaps_ = color_overlaps
11✔
195

196
    def __repr__(self):
11✔
197
        out_str = ["-----",
×
198
                   "Plot:",
199
                   "-----",
200
                   f"Origin: {self.origin}",
201
                   f"Width: {self.width}",
202
                   f"Height: {self.height}",
203
                   f"Basis: {self.basis}",
204
                   f"HRes: {self.h_res}",
205
                   f"VRes: {self.v_res}",
206
                   f"Color Overlaps: {self.color_overlaps}",
207
                   f"Level: {self.level}"]
208
        return '\n'.join(out_str)
×
209

210

211
_dll.openmc_id_map.argtypes = [POINTER(_PlotBase), POINTER(c_int32)]
11✔
212
_dll.openmc_id_map.restype = c_int
11✔
213
_dll.openmc_id_map.errcheck = _error_handler
11✔
214

215

216
def id_map(plot):
11✔
217
    """
218
    Generate a 2-D map of cell and material IDs. Used for in-memory image
219
    generation.
220

221
    Parameters
222
    ----------
223
    plot : openmc.lib.plot._PlotBase
224
        Object describing the slice of the model to be generated
225

226
    Returns
227
    -------
228
    id_map : numpy.ndarray
229
        A NumPy array with shape (vertical pixels, horizontal pixels, 3) of
230
        OpenMC property ids with dtype int32. The last dimension of the array
231
        contains, in order, cell IDs, cell instances, and material IDs.
232

233
    """
234
    img_data = np.zeros((plot.v_res, plot.h_res, 3),
11✔
235
                        dtype=np.dtype('int32'))
236
    _dll.openmc_id_map(plot, img_data.ctypes.data_as(POINTER(c_int32)))
11✔
237
    return img_data
11✔
238

239

240
_dll.openmc_property_map.argtypes = [POINTER(_PlotBase), POINTER(c_double)]
11✔
241
_dll.openmc_property_map.restype = c_int
11✔
242
_dll.openmc_property_map.errcheck = _error_handler
11✔
243

244

245
def property_map(plot):
11✔
246
    """
247
    Generate a 2-D map of cell temperatures and material densities. Used for
248
    in-memory image generation.
249

250
    Parameters
251
    ----------
252
    plot : openmc.lib.plot._PlotBase
253
        Object describing the slice of the model to be generated
254

255
    Returns
256
    -------
257
    property_map : numpy.ndarray
258
        A NumPy array with shape (vertical pixels, horizontal pixels, 2) of
259
        OpenMC property ids with dtype float
260

261
    """
262
    prop_data = np.zeros((plot.v_res, plot.h_res, 2))
11✔
263
    _dll.openmc_property_map(plot, prop_data.ctypes.data_as(POINTER(c_double)))
11✔
264
    return prop_data
11✔
265

266
_dll.openmc_get_plot_index.argtypes = [c_int32, POINTER(c_int32)]
11✔
267
_dll.openmc_get_plot_index.restype = c_int
11✔
268
_dll.openmc_get_plot_index.errcheck = _error_handler
11✔
269

270
_dll.openmc_plot_get_id.argtypes = [c_int32, POINTER(c_int32)]
11✔
271
_dll.openmc_plot_get_id.restype = c_int
11✔
272
_dll.openmc_plot_get_id.errcheck = _error_handler
11✔
273

274
_dll.openmc_plot_set_id.argtypes = [c_int32, c_int32]
11✔
275
_dll.openmc_plot_set_id.restype = c_int
11✔
276
_dll.openmc_plot_set_id.errcheck = _error_handler
11✔
277

278
_dll.openmc_plots_size.restype = c_size_t
11✔
279

280
_dll.openmc_solidraytrace_plot_create.argtypes = [POINTER(c_int32)]
11✔
281
_dll.openmc_solidraytrace_plot_create.restype = c_int
11✔
282
_dll.openmc_solidraytrace_plot_create.errcheck = _error_handler
11✔
283

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

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

293
_dll.openmc_solidraytrace_plot_get_color_by.argtypes = [c_int32, POINTER(c_int32)]
11✔
294
_dll.openmc_solidraytrace_plot_get_color_by.restype = c_int
11✔
295
_dll.openmc_solidraytrace_plot_get_color_by.errcheck = _error_handler
11✔
296

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

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

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

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

313
_dll.openmc_solidraytrace_plot_set_color.argtypes = [c_int32, c_int32, c_uint8, c_uint8, c_uint8]
11✔
314
_dll.openmc_solidraytrace_plot_set_color.restype = c_int
11✔
315
_dll.openmc_solidraytrace_plot_set_color.errcheck = _error_handler
11✔
316

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

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

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

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

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

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

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

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

353
_dll.openmc_solidraytrace_plot_get_fov.argtypes = [c_int32, POINTER(c_double)]
11✔
354
_dll.openmc_solidraytrace_plot_get_fov.restype = c_int
11✔
355
_dll.openmc_solidraytrace_plot_get_fov.errcheck = _error_handler
11✔
356

357
_dll.openmc_solidraytrace_plot_set_fov.argtypes = [c_int32, c_double]
11✔
358
_dll.openmc_solidraytrace_plot_set_fov.restype = c_int
11✔
359
_dll.openmc_solidraytrace_plot_set_fov.errcheck = _error_handler
11✔
360

361
_dll.openmc_solidraytrace_plot_update_view.argtypes = [c_int32]
11✔
362
_dll.openmc_solidraytrace_plot_update_view.restype = c_int
11✔
363
_dll.openmc_solidraytrace_plot_update_view.errcheck = _error_handler
11✔
364

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

369
_dll.openmc_solidraytrace_plot_get_color.argtypes = [c_int32, c_int32,
11✔
370
                                             POINTER(c_uint8), POINTER(c_uint8), POINTER(c_uint8)]
371
_dll.openmc_solidraytrace_plot_get_color.restype = c_int
11✔
372
_dll.openmc_solidraytrace_plot_get_color.errcheck = _error_handler
11✔
373

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

379
_dll.openmc_solidraytrace_plot_set_diffuse_fraction.argtypes = [c_int32, c_double]
11✔
380
_dll.openmc_solidraytrace_plot_set_diffuse_fraction.restype = c_int
11✔
381
_dll.openmc_solidraytrace_plot_set_diffuse_fraction.errcheck = _error_handler
11✔
382

383

384
class SolidRayTracePlot(_FortranObjectWithID):
11✔
385
    """Solid ray-traced plot stored internally.
386

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

391
    Parameters
392
    ----------
393
    uid : int or None
394
        Unique ID of the plot
395
    new : bool
396
        When `index` is None, this argument controls whether a new object is
397
        created or a view of an existing object is returned.
398
    index : int or None
399
        Index in the internal plots array.
400

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

424
    COLOR_BY_MATERIAL = 0
11✔
425
    COLOR_BY_CELL = 1
11✔
426
    __instances = WeakValueDictionary()
11✔
427

428
    def __new__(cls, uid=None, new=True, index=None):
11✔
429
        mapping = plots
11✔
430
        if index is None:
11✔
431
            if new:
11✔
432
                if uid is not None and uid in mapping:
11✔
NEW
433
                    raise AllocationError(
×
434
                        f'A plot with ID={uid} has already been allocated.'
435
                    )
436
                index = c_int32()
11✔
437
                _dll.openmc_solidraytrace_plot_create(index)
11✔
438
                index = index.value
11✔
439
            else:
NEW
440
                index = mapping[uid]._index
×
441

442
        if index not in cls.__instances:
11✔
443
            instance = super().__new__(cls)
11✔
444
            instance._index = index
11✔
445
            if uid is not None:
11✔
NEW
446
                instance.id = uid
×
447
            cls.__instances[index] = instance
11✔
448

449
        return cls.__instances[index]
11✔
450

451
    def __init__(self, uid=None, new=True, index=None):
11✔
452
        super().__init__(uid, new, index)
11✔
453

454
    @property
11✔
455
    def id(self):
11✔
456
        plot_id = c_int32()
11✔
457
        _dll.openmc_plot_get_id(self._index, plot_id)
11✔
458
        return plot_id.value
11✔
459

460
    @id.setter
11✔
461
    def id(self, plot_id):
11✔
NEW
462
        _dll.openmc_plot_set_id(self._index, plot_id)
×
463

464
    @staticmethod
11✔
465
    def _get_xyz(getter, index):
11✔
466
        x = c_double()
11✔
467
        y = c_double()
11✔
468
        z = c_double()
11✔
469
        getter(index, x, y, z)
11✔
470
        return (x.value, y.value, z.value)
11✔
471

472
    @staticmethod
11✔
473
    def _set_xyz(setter, index, xyz):
11✔
474
        x, y, z = xyz
11✔
475
        setter(index, float(x), float(y), float(z))
11✔
476

477
    @property
11✔
478
    def pixels(self):
11✔
479
        width = c_int32()
11✔
480
        height = c_int32()
11✔
481
        _dll.openmc_solidraytrace_plot_get_pixels(self._index, width, height)
11✔
482
        return (width.value, height.value)
11✔
483

484
    @pixels.setter
11✔
485
    def pixels(self, pixels):
11✔
486
        width, height = pixels
11✔
487
        _dll.openmc_solidraytrace_plot_set_pixels(
11✔
488
            self._index, int(width), int(height))
489

490
    @property
11✔
491
    def color_by(self):
11✔
492
        color_by = c_int32()
11✔
493
        _dll.openmc_solidraytrace_plot_get_color_by(self._index, color_by)
11✔
494
        return color_by.value
11✔
495

496
    @color_by.setter
11✔
497
    def color_by(self, color_by):
11✔
498
        _dll.openmc_solidraytrace_plot_set_color_by(self._index, int(color_by))
11✔
499

500
    def set_default_colors(self):
11✔
501
        _dll.openmc_solidraytrace_plot_set_default_colors(self._index)
11✔
502

503
    def set_all_opaque(self):
11✔
NEW
504
        _dll.openmc_solidraytrace_plot_set_all_opaque(self._index)
×
505

506
    def set_visibility(self, domain_id, visible):
11✔
507
        _dll.openmc_solidraytrace_plot_set_opaque(
11✔
508
            self._index, int(domain_id), bool(visible)
509
        )
510

511
    def set_color(self, domain_id, color):
11✔
512
        r, g, b = [int(c) for c in color]
11✔
513
        _dll.openmc_solidraytrace_plot_set_color(
11✔
514
            self._index, int(domain_id), r, g, b)
515

516
    @property
11✔
517
    def camera_position(self):
11✔
518
        return self._get_xyz(_dll.openmc_solidraytrace_plot_get_camera_position,
11✔
519
                             self._index)
520

521
    @camera_position.setter
11✔
522
    def camera_position(self, position):
11✔
523
        self._set_xyz(_dll.openmc_solidraytrace_plot_set_camera_position,
11✔
524
                      self._index, position)
525

526
    @property
11✔
527
    def look_at(self):
11✔
528
        return self._get_xyz(_dll.openmc_solidraytrace_plot_get_look_at,
11✔
529
                             self._index)
530

531
    @look_at.setter
11✔
532
    def look_at(self, position):
11✔
533
        self._set_xyz(_dll.openmc_solidraytrace_plot_set_look_at,
11✔
534
                      self._index, position)
535

536
    @property
11✔
537
    def up(self):
11✔
538
        return self._get_xyz(_dll.openmc_solidraytrace_plot_get_up, self._index)
11✔
539

540
    @up.setter
11✔
541
    def up(self, direction):
11✔
542
        self._set_xyz(_dll.openmc_solidraytrace_plot_set_up, self._index,
11✔
543
                      direction)
544

545
    @property
11✔
546
    def light_position(self):
11✔
547
        return self._get_xyz(_dll.openmc_solidraytrace_plot_get_light_position,
11✔
548
                             self._index)
549

550
    @light_position.setter
11✔
551
    def light_position(self, position):
11✔
552
        self._set_xyz(_dll.openmc_solidraytrace_plot_set_light_position,
11✔
553
                      self._index, position)
554

555
    @property
11✔
556
    def fov(self):
11✔
557
        fov = c_double()
11✔
558
        _dll.openmc_solidraytrace_plot_get_fov(self._index, fov)
11✔
559
        return fov.value
11✔
560

561
    @fov.setter
11✔
562
    def fov(self, fov):
11✔
563
        _dll.openmc_solidraytrace_plot_set_fov(self._index, float(fov))
11✔
564

565
    def update_view(self):
11✔
566
        _dll.openmc_solidraytrace_plot_update_view(self._index)
11✔
567

568
    def create_image(self):
11✔
569
        width, height = self.pixels
11✔
570
        image = np.zeros((height, width, 3), dtype=np.uint8)
11✔
571
        _dll.openmc_solidraytrace_plot_create_image(
11✔
572
            self._index,
573
            image.ctypes.data_as(POINTER(c_uint8)),
574
            width,
575
            height
576
        )
577
        return image
11✔
578

579
    def get_color(self, domain_id):
11✔
580
        r = c_uint8()
11✔
581
        g = c_uint8()
11✔
582
        b = c_uint8()
11✔
583
        _dll.openmc_solidraytrace_plot_get_color(
11✔
584
            self._index, int(domain_id), r, g, b)
585
        return int(r.value), int(g.value), int(b.value)
11✔
586

587
    @property
11✔
588
    def diffuse_fraction(self):
11✔
589
        value = c_double()
11✔
590
        _dll.openmc_solidraytrace_plot_get_diffuse_fraction(self._index, value)
11✔
591
        return value.value
11✔
592

593
    @diffuse_fraction.setter
11✔
594
    def diffuse_fraction(self, value):
11✔
595
        _dll.openmc_solidraytrace_plot_set_diffuse_fraction(
11✔
596
            self._index, float(value))
597

598
    # Backward-compatible setter aliases
599
    def set_pixels(self, width, height):
11✔
NEW
600
        self.pixels = (width, height)
×
601

602
    def set_color_by(self, color_by):
11✔
NEW
603
        self.color_by = color_by
×
604

605
    def set_camera_position(self, x, y, z):
11✔
NEW
606
        self.camera_position = (x, y, z)
×
607

608
    def set_look_at(self, x, y, z):
11✔
NEW
609
        self.look_at = (x, y, z)
×
610

611
    def set_up(self, x, y, z):
11✔
NEW
612
        self.up = (x, y, z)
×
613

614
    def set_light_position(self, x, y, z):
11✔
NEW
615
        self.light_position = (x, y, z)
×
616

617
    def set_fov(self, fov):
11✔
NEW
618
        self.fov = fov
×
619

620
    def set_diffuse_fraction(self, value):
11✔
NEW
621
        self.diffuse_fraction = value
×
622

623

624
class _PlotMapping(Mapping):
11✔
625
    def __getitem__(self, key):
11✔
626
        index = c_int32()
11✔
627
        try:
11✔
628
            _dll.openmc_get_plot_index(key, index)
11✔
NEW
629
        except (AllocationError, InvalidIDError) as e:
×
NEW
630
            raise KeyError(str(e))
×
631
        return SolidRayTracePlot(index=index.value)
11✔
632

633
    def __iter__(self):
11✔
NEW
634
        for i in range(len(self)):
×
NEW
635
            yield SolidRayTracePlot(index=i).id
×
636

637
    def __len__(self):
11✔
638
        return _dll.openmc_plots_size()
11✔
639

640
    def __repr__(self):
11✔
NEW
641
        return repr(dict(self))
×
642

643

644
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