Skip to content
Merged
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Project Changelog
Release 1.6.0 (TBD)
-------------------

API changes:
* Rename `TargettedPixelGroup` to `TargetedPixelGroup` for correct spelling. Still keep `TargettedPixelGroup` as an alias for backwards compatibility. (#487)

New:
* Add Function6D framework. (#478)
* Add e_field attribute to Plasma object for electric field vector. (#465)
Expand Down Expand Up @@ -134,7 +137,7 @@ API changes:

New:
* Merged cherab-openadas package into the core cherab package to simplify installation.
* Beam object uses a cone primitive instead of a cylinder for the bounding volume of divergent beams.
* Beam object uses a cone primitive instead of a cylinder for the bounding volume of divergent beams.
* Added Clamp functions.
* Added ThermalCXRate.
* Added optimised ray transfer grid calculation tools.
Expand Down Expand Up @@ -162,7 +165,7 @@ New:

Bug fixes:
* Improved handling on non c-order arrays in various methods.
* Numerous minor bug fixes (see commit history)
* Numerous minor bug fixes (see commit history)


Release 1.0.1 (1 Oct 2018)
Expand Down
2 changes: 1 addition & 1 deletion cherab/tools/observers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
from .calcam import load_calcam_calibration
from .intersections import find_wall_intersection
from .spectroscopy import SpectroscopicSightLine, SpectroscopicFibreOptic
from .group import PixelGroup, TargettedPixelGroup, SightLineGroup, FibreOpticGroup, SpectroscopicFibreOpticGroup, SpectroscopicSightLineGroup
from .group import PixelGroup, TargetedPixelGroup, TargettedPixelGroup, SightLineGroup, FibreOpticGroup, SpectroscopicFibreOpticGroup, SpectroscopicSightLineGroup
5 changes: 3 additions & 2 deletions cherab/tools/observers/group/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
# under the Licence.

from .fibreoptic import FibreOpticGroup
from .sightline import SightLineGroup
from .targettedpixel import TargettedPixelGroup
from .pixel import PixelGroup
from .sightline import SightLineGroup
from .spectroscopic import SpectroscopicFibreOpticGroup, SpectroscopicSightLineGroup
from .targetedpixel import TargetedPixelGroup
from .targettedpixel import TargettedPixelGroup
123 changes: 123 additions & 0 deletions cherab/tools/observers/group/targetedpixel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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
98 changes: 19 additions & 79 deletions cherab/tools/observers/group/targettedpixel.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@
# See the Licence for the specific language governing permissions and limitations
# under the Licence.

from numpy import ndarray
from raysect.optical.observer import TargettedPixel
import warnings

from .base import Observer0DGroup
from .targetedpixel import TargetedPixelGroup as _TargetedPixelGroup


class TargettedPixelGroup(Observer0DGroup):
class TargettedPixelGroup(_TargetedPixelGroup):
"""
A group of targetted pixel under a single scene-graph node.
A group of targeted pixel under a single scene-graph node.

A scene-graph object regrouping a series of 'TargettedPixel'
.. deprecated::
TargettedPixelGroup is deprecated and will be removed in a future version.
Use TargetedPixelGroup instead.

A scene-graph object regrouping a series of 'TargetedPixel'
observers as a scene-graph parent. Allows combined observation and display
control simultaneously.

Expand All @@ -35,82 +38,19 @@ class TargettedPixelGroup(Observer0DGroup):
:ivar list targets: Targets for preferential sampling
:ivar list targetted_path_prob: Probability of ray being casted at the target
"""
_OBSERVER_TYPE = TargettedPixel

@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
def __init__(self, *args, **kwargs):
warnings.warn(
"TargettedPixelGroup is deprecated and will be removed in a future version. Use TargetedPixelGroup instead.",
DeprecationWarning,
stacklevel=2,
)
super().__init__(*args, **kwargs)

@property
def targetted_path_prob(self):
return [pixel.targetted_path_prob for pixel in self._observers]
return self.targeted_path_prob

@targetted_path_prob.setter
def targetted_path_prob(self, value):
if isinstance(value, (list, tuple)):
if len(value) == len(self._observers):
for pixel, v in zip(self._observers, value):
pixel.targetted_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.targetted_path_prob = value
self.targeted_path_prob = value
Loading
Loading