Skip to content

Commit

Permalink
rename labels
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl committed Aug 21, 2024
1 parent 4320645 commit 8bb8821
Show file tree
Hide file tree
Showing 35 changed files with 298 additions and 298 deletions.
6 changes: 3 additions & 3 deletions Wrappers/Python/cil/framework/acquisition_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# CIL Developers, listed at: https://github.com/TomographicImaging/CIL/blob/master/NOTICE.txt
import numpy

from .labels import AcquisitionDimensionLabels, Backends
from .labels import AcquisitionDimension, Backend
from .data_container import DataContainer
from .partitioner import Partitioner

Expand Down Expand Up @@ -114,7 +114,7 @@ def reorder(self, order):
order: list or str
Ordered list of labels from self.dimension_labels, or string 'astra' or 'tigre'.
'''
if order in Backends:
order = AcquisitionDimensionLabels.get_order_for_engine(order, self.geometry)
if order in Backend:
order = AcquisitionDimension.get_order_for_engine(order, self.geometry)

super().reorder(order)
42 changes: 21 additions & 21 deletions Wrappers/Python/cil/framework/acquisition_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import numpy

from .labels import AcquisitionDimensionLabels, UnitsAngles, AcquisitionType, FillTypes
from .labels import AcquisitionDimension, AngleUnit, AcquisitionType, FillType
from .acquisition_data import AcquisitionData
from .image_geometry import ImageGeometry

Expand Down Expand Up @@ -1457,7 +1457,7 @@ def angle_unit(self):

@angle_unit.setter
def angle_unit(self,val):
self._angle_unit = UnitsAngles(val)
self._angle_unit = AngleUnit(val)

def __str__(self):
repres = "Acquisition description:\n"
Expand Down Expand Up @@ -1612,32 +1612,32 @@ class AcquisitionGeometry(object):
@property
def ANGLE(self):
warnings.warn("use AcquisitionDimensionLabels.Angle instead", DeprecationWarning, stacklevel=2)
return AcquisitionDimensionLabels.ANGLE
return AcquisitionDimension.ANGLE

@property
def CHANNEL(self):
warnings.warn("use AcquisitionDimensionLabels.Channel instead", DeprecationWarning, stacklevel=2)
return AcquisitionDimensionLabels.CHANNEL
return AcquisitionDimension.CHANNEL

@property
def DEGREE(self):
warnings.warn("use UnitsAngles.DEGREE", DeprecationWarning, stacklevel=2)
return UnitsAngles.DEGREE
return AngleUnit.DEGREE

@property
def HORIZONTAL(self):
warnings.warn("use AcquisitionDimensionLabels.HORIZONTAL instead", DeprecationWarning, stacklevel=2)
return AcquisitionDimensionLabels.HORIZONTAL
return AcquisitionDimension.HORIZONTAL

@property
def RADIAN(self):
warnings.warn("use UnitsAngles.RADIAN instead", DeprecationWarning, stacklevel=2)
return UnitsAngles.RADIAN
return AngleUnit.RADIAN

@property
def VERTICAL(self):
warnings.warn("use AcquisitionDimensionLabels.VERTICAL instead", DeprecationWarning, stacklevel=2)
return AcquisitionDimensionLabels.VERTICAL
return AcquisitionDimension.VERTICAL

@property
def geom_type(self):
Expand Down Expand Up @@ -1709,15 +1709,15 @@ def dimension(self):
@property
def shape(self):

shape_dict = {AcquisitionDimensionLabels.CHANNEL: self.config.channels.num_channels,
AcquisitionDimensionLabels.ANGLE: self.config.angles.num_positions,
AcquisitionDimensionLabels.VERTICAL: self.config.panel.num_pixels[1],
AcquisitionDimensionLabels.HORIZONTAL: self.config.panel.num_pixels[0]}
shape_dict = {AcquisitionDimension.CHANNEL: self.config.channels.num_channels,
AcquisitionDimension.ANGLE: self.config.angles.num_positions,
AcquisitionDimension.VERTICAL: self.config.panel.num_pixels[1],
AcquisitionDimension.HORIZONTAL: self.config.panel.num_pixels[0]}
return tuple(shape_dict[label] for label in self.dimension_labels)

@property
def dimension_labels(self):
labels_default = AcquisitionDimensionLabels.get_order_for_engine("cil")
labels_default = AcquisitionDimension.get_order_for_engine("cil")

shape_default = [self.config.channels.num_channels,
self.config.angles.num_positions,
Expand Down Expand Up @@ -1745,7 +1745,7 @@ def dimension_labels(self):
@dimension_labels.setter
def dimension_labels(self, val):
if val is not None:
self._dimension_labels = tuple(map(AcquisitionDimensionLabels, val))
self._dimension_labels = tuple(map(AcquisitionDimension, val))

@property
def ndim(self):
Expand Down Expand Up @@ -1816,10 +1816,10 @@ def get_centre_of_rotation(self, distance_units='default', angle_units='radian')
else:
raise ValueError("`distance_units` is not recognised. Must be 'default' or 'pixels'. Got {}".format(distance_units))

angle_units = UnitsAngles(angle_units)
angle_units = AngleUnit(angle_units)

angle = angle_rad
if angle_units == UnitsAngles.DEGREE:
if angle_units == AngleUnit.DEGREE:
angle = numpy.degrees(angle_rad)

return {'offset': (offset, offset_units), 'angle': (angle, angle_units.value)}
Expand Down Expand Up @@ -1860,10 +1860,10 @@ def set_centre_of_rotation(self, offset=0.0, distance_units='default', angle=0.0
raise NotImplementedError()


angle_units = UnitsAngles(angle_units)
angle_units = AngleUnit(angle_units)

angle_rad = angle
if angle_units == UnitsAngles.DEGREE:
if angle_units == AngleUnit.DEGREE:
angle_rad = numpy.radians(angle)

if distance_units =='default':
Expand Down Expand Up @@ -2181,8 +2181,8 @@ def allocate(self, value=0, **kwargs):
if isinstance(value, Number):
# it's created empty, so we make it 0
out.array.fill(value)
elif value in FillTypes:
if value == FillTypes.RANDOM:
elif value in FillType:
if value == FillType.RANDOM:
seed = kwargs.get('seed', None)
if seed is not None:
numpy.random.seed(seed)
Expand All @@ -2191,7 +2191,7 @@ def allocate(self, value=0, **kwargs):
out.fill(r)
else:
out.fill(numpy.random.random_sample(self.shape))
elif value == FillTypes.RANDOM_INT:
elif value == FillType.RANDOM_INT:
seed = kwargs.get('seed', None)
if seed is not None:
numpy.random.seed(seed)
Expand Down
6 changes: 3 additions & 3 deletions Wrappers/Python/cil/framework/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@
import numpy

from ..utilities.multiprocessing import NUM_THREADS
from .labels import FillTypes
from .labels import FillType


class BlockGeometry(object):
@property
def RANDOM(self):
warnings.warn("use FillTypes.RANDOM instead", DeprecationWarning, stacklevel=2)
return FillTypes.RANDOM
return FillType.RANDOM

@property
def RANDOM_INT(self):
warnings.warn("use FillTypes.RANDOM_INT instead", DeprecationWarning, stacklevel=2)
return FillTypes.RANDOM_INT
return FillType.RANDOM_INT

@property
def dtype(self):
Expand Down
6 changes: 3 additions & 3 deletions Wrappers/Python/cil/framework/image_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import numpy

from .data_container import DataContainer
from .labels import ImageDimensionLabels, Backends
from .labels import ImageDimension, Backend

class ImageData(DataContainer):
'''DataContainer for holding 2D or 3D DataContainer'''
Expand Down Expand Up @@ -200,7 +200,7 @@ def reorder(self, order):
order: list or str
Ordered list of labels from self.dimension_labels, or string 'astra' or 'tigre'.
'''
if order in Backends:
order = ImageDimensionLabels.get_order_for_engine(order, self.geometry)
if order in Backend:
order = ImageDimension.get_order_for_engine(order, self.geometry)

super().reorder(order)
40 changes: 20 additions & 20 deletions Wrappers/Python/cil/framework/image_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,45 +22,45 @@
import numpy

from .image_data import ImageData
from .labels import ImageDimensionLabels, FillTypes
from .labels import ImageDimension, FillType


class ImageGeometry:
@property
def CHANNEL(self):
warnings.warn("use ImageDimensionLabels.CHANNEL instead", DeprecationWarning, stacklevel=2)
return ImageDimensionLabels.CHANNEL
return ImageDimension.CHANNEL

@property
def HORIZONTAL_X(self):
warnings.warn("use ImageDimensionLabels.HORIZONTAL_X instead", DeprecationWarning, stacklevel=2)
return ImageDimensionLabels.HORIZONTAL_X
return ImageDimension.HORIZONTAL_X

@property
def HORIZONTAL_Y(self):
warnings.warn("use ImageDimensionLabels.HORIZONTAL_Y instead", DeprecationWarning, stacklevel=2)
return ImageDimensionLabels.HORIZONTAL_Y
return ImageDimension.HORIZONTAL_Y

@property
def RANDOM(self):
warnings.warn("use FillTypes.RANDOM instead", DeprecationWarning, stacklevel=2)
return FillTypes.RANDOM
return FillType.RANDOM
@property
def RANDOM_INT(self):
warnings.warn("use FillTypes.RANDOM_INT instead", DeprecationWarning, stacklevel=2)
return FillTypes.RANDOM_INT
return FillType.RANDOM_INT

@property
def VERTICAL(self):
warnings.warn("use ImageDimensionLabels.VERTICAL instead", DeprecationWarning, stacklevel=2)
return ImageDimensionLabels.VERTICAL
return ImageDimension.VERTICAL

@property
def shape(self):
shape_dict = {ImageDimensionLabels.CHANNEL: self.channels,
ImageDimensionLabels.VERTICAL: self.voxel_num_z,
ImageDimensionLabels.HORIZONTAL_Y: self.voxel_num_y,
ImageDimensionLabels.HORIZONTAL_X: self.voxel_num_x}
shape_dict = {ImageDimension.CHANNEL: self.channels,
ImageDimension.VERTICAL: self.voxel_num_z,
ImageDimension.HORIZONTAL_Y: self.voxel_num_y,
ImageDimension.HORIZONTAL_X: self.voxel_num_x}
return tuple(shape_dict[label] for label in self.dimension_labels)

@shape.setter
Expand All @@ -69,10 +69,10 @@ def shape(self, val):

@property
def spacing(self):
spacing_dict = {ImageDimensionLabels.CHANNEL: self.channel_spacing,
ImageDimensionLabels.VERTICAL: self.voxel_size_z,
ImageDimensionLabels.HORIZONTAL_Y: self.voxel_size_y,
ImageDimensionLabels.HORIZONTAL_X: self.voxel_size_x}
spacing_dict = {ImageDimension.CHANNEL: self.channel_spacing,
ImageDimension.VERTICAL: self.voxel_size_z,
ImageDimension.HORIZONTAL_Y: self.voxel_size_y,
ImageDimension.HORIZONTAL_X: self.voxel_size_x}
return tuple(spacing_dict[label] for label in self.dimension_labels)

@property
Expand All @@ -86,7 +86,7 @@ def ndim(self):
@property
def dimension_labels(self):

labels_default = ImageDimensionLabels.get_order_for_engine("cil")
labels_default = ImageDimension.get_order_for_engine("cil")

shape_default = [ self.channels,
self.voxel_num_z,
Expand All @@ -113,7 +113,7 @@ def dimension_labels(self, val):

def set_labels(self, labels):
if labels is not None:
self._dimension_labels = tuple(map(ImageDimensionLabels, labels))
self._dimension_labels = tuple(map(ImageDimension, labels))

def __eq__(self, other):
if not isinstance(other, self.__class__):
Expand Down Expand Up @@ -274,8 +274,8 @@ def allocate(self, value=0, **kwargs):
if isinstance(value, Number):
# it's created empty, so we make it 0
out.array.fill(value)
elif value in FillTypes:
if value == FillTypes.RANDOM:
elif value in FillType:
if value == FillType.RANDOM:
seed = kwargs.get('seed', None)
if seed is not None:
numpy.random.seed(seed)
Expand All @@ -285,7 +285,7 @@ def allocate(self, value=0, **kwargs):
else:
out.fill(numpy.random.random_sample(self.shape))

elif value == FillTypes.RANDOM_INT:
elif value == FillType.RANDOM_INT:
seed = kwargs.get('seed', None)
if seed is not None:
numpy.random.seed(seed)
Expand Down
34 changes: 17 additions & 17 deletions Wrappers/Python/cil/framework/labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def _generate_next_value_(name: str, start, count, last_values) -> str:
return name.lower()


class Backends(StrEnum):
class Backend(StrEnum):
"""
Available backends for CIL.
Expand Down Expand Up @@ -117,14 +117,14 @@ def check_order_for_engine(cls, engine: str, geometry) -> bool:
f" Try using `data.reorder('{engine}')` to permute for {engine}")


class ImageDimensionLabels(_DimensionBase, StrEnum):
class ImageDimension(_DimensionBase, StrEnum):
"""
Available dimension labels for image data.
Examples
--------
```
data.reorder([ImageDimensionLabels.HORIZONTAL_X, ImageDimensionLabels.VERTICAL])
data.reorder([ImageDimension.HORIZONTAL_X, ImageDimension.VERTICAL])
data.reorder(["horizontal_x", "vertical"])
```
"""
Expand All @@ -135,24 +135,24 @@ class ImageDimensionLabels(_DimensionBase, StrEnum):

@classmethod
def _default_order(cls, engine: str) -> tuple:
engine = Backends(engine)
engine = Backend(engine)
orders = {
Backends.ASTRA: (cls.CHANNEL, cls.VERTICAL, cls.HORIZONTAL_Y, cls.HORIZONTAL_X),
Backends.TIGRE: (cls.CHANNEL, cls.VERTICAL, cls.HORIZONTAL_Y, cls.HORIZONTAL_X),
Backends.CIL: (cls.CHANNEL, cls.VERTICAL, cls.HORIZONTAL_Y, cls.HORIZONTAL_X)}
Backend.ASTRA: (cls.CHANNEL, cls.VERTICAL, cls.HORIZONTAL_Y, cls.HORIZONTAL_X),
Backend.TIGRE: (cls.CHANNEL, cls.VERTICAL, cls.HORIZONTAL_Y, cls.HORIZONTAL_X),
Backend.CIL: (cls.CHANNEL, cls.VERTICAL, cls.HORIZONTAL_Y, cls.HORIZONTAL_X)}
return orders[engine]


class AcquisitionDimensionLabels(_DimensionBase, StrEnum):
class AcquisitionDimension(_DimensionBase, StrEnum):
"""
Available dimension labels for acquisition data.
Examples
--------
```
data.reorder([AcquisitionDimensionLabels.CHANNEL,
AcquisitionDimensionLabels.ANGLE,
AcquisitionDimensionLabels.HORIZONTAL])
data.reorder([AcquisitionDimension.CHANNEL,
AcquisitionDimension.ANGLE,
AcquisitionDimension.HORIZONTAL])
data.reorder(["channel", "angle", "horizontal"])
```
"""
Expand All @@ -163,15 +163,15 @@ class AcquisitionDimensionLabels(_DimensionBase, StrEnum):

@classmethod
def _default_order(cls, engine: str) -> tuple:
engine = Backends(engine)
engine = Backend(engine)
orders = {
Backends.ASTRA: (cls.CHANNEL, cls.VERTICAL, cls.ANGLE, cls.HORIZONTAL),
Backends.TIGRE: (cls.CHANNEL, cls.ANGLE, cls.VERTICAL, cls.HORIZONTAL),
Backends.CIL: (cls.CHANNEL, cls.ANGLE, cls.VERTICAL, cls.HORIZONTAL)}
Backend.ASTRA: (cls.CHANNEL, cls.VERTICAL, cls.ANGLE, cls.HORIZONTAL),
Backend.TIGRE: (cls.CHANNEL, cls.ANGLE, cls.VERTICAL, cls.HORIZONTAL),
Backend.CIL: (cls.CHANNEL, cls.ANGLE, cls.VERTICAL, cls.HORIZONTAL)}
return orders[engine]


class FillTypes(StrEnum):
class FillType(StrEnum):
"""
Available fill types for image data.
Expand All @@ -191,7 +191,7 @@ class FillTypes(StrEnum):
RANDOM_INT = auto()


class UnitsAngles(StrEnum):
class AngleUnit(StrEnum):
"""
Available units for angles.
Expand Down
Loading

0 comments on commit 8bb8821

Please sign in to comment.