forked from cherab/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtargetedpixel.py
More file actions
123 lines (106 loc) · 4.58 KB
/
targetedpixel.py
File metadata and controls
123 lines (106 loc) · 4.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# Copyright 2016-2021 Euratom
# Copyright 2016-2021 United Kingdom Atomic Energy Authority
# Copyright 2016-2021 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas
#
# Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the
# European Commission - subsequent versions of the EUPL (the "Licence");
# You may not use this work except in compliance with the Licence.
# You may obtain a copy of the Licence at:
#
# https://joinup.ec.europa.eu/software/page/eupl5
#
# Unless required by applicable law or agreed to in writing, software distributed
# under the Licence is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied.
#
# See the Licence for the specific language governing permissions and limitations
# under the Licence.
from numpy import ndarray
from raysect.optical.observer import TargetedPixel
from .base import Observer0DGroup
class TargetedPixelGroup(Observer0DGroup):
"""
A group of targeted pixels under a single scene-graph node.
A scene-graph object regrouping a series of 'TargetedPixel'
observers as a scene-graph parent. Allows combined observation and display
control simultaneously.
:ivar list x_width: Width of pixel along local x axis
:ivar list y_width: Width of pixel along local y axis
:ivar list targets: Targets for preferential sampling
:ivar list targeted_path_prob: Probability of ray being casted at the target
"""
_OBSERVER_TYPE = TargetedPixel
@property
def x_width(self):
return [pixel.x_width for pixel in self._observers]
@x_width.setter
def x_width(self, value):
if isinstance(value, (list, tuple, ndarray)):
if len(value) == len(self._observers):
for pixel, v in zip(self._observers, value):
pixel.x_width = v
else:
raise ValueError(
"The length of 'x_width' ({}) mismatches the number of pixels ({}).".format(len(value), len(self._observers))
)
else:
for pixel in self._observers:
pixel.x_width = value
@property
def y_width(self):
return [pixel.y_width for pixel in self._observers]
@y_width.setter
def y_width(self, value):
if isinstance(value, (list, tuple, ndarray)):
if len(value) == len(self._observers):
for pixel, v in zip(self._observers, value):
pixel.y_width = v
else:
raise ValueError(
"The length of 'y_width' ({}) mismatches the number of pixels ({}).".format(len(value), len(self._observers))
)
else:
for pixel in self._observers:
pixel.y_width = value
@property
def targets(self):
"""
List of target lists used by pixels for preferential sampling
:param list value: List of primitives to be set to each pixel or
list of lists containing targets specific for each pixel
in this case the number of lists must match number of pixels
:rtype: list
"""
return [pixel.targets for pixel in self._observers]
@targets.setter
def targets(self, value):
if all(isinstance(v, (list, tuple)) for v in value):
if len(value) == len(self._observers):
for pixel, v in zip(self._observers, value):
pixel.targets = v
else:
raise ValueError(
"The number of provided target lists' ({}) mismatches the number of pixels ({}).".format(
len(value), len(self._observers)
)
)
else:
# assuming a list of primitives, the pixel's setter will throw an error if not
for pixel in self._observers:
pixel.targets = value
@property
def targeted_path_prob(self):
return [pixel.targeted_path_prob for pixel in self._observers]
@targeted_path_prob.setter
def targeted_path_prob(self, value):
if isinstance(value, (list, tuple)):
if len(value) == len(self._observers):
for pixel, v in zip(self._observers, value):
pixel.targeted_path_prob = v
else:
raise ValueError(
"The length of 'value' ({}) mismatches the number of pixels ({}).".format(len(value), len(self._observers))
)
else:
for pixel in self._observers:
pixel.targeted_path_prob = value