timor.Volume

Classes

BoxVolume

A box volume is an expansion in the three-dimensional euclidean space forming a solid box.

CylinderVolume

A cylindrical volume is an expansion in the three-dimensional euclidean space forming a solid cylinder.

SphereVolume

A spherical volume is an expansion in the three-dimensional euclidean space forming a fully/partially filled sphere.

Volume

A Volume is a connected sub-set of a three-dimensional euclidean space.

Module Contents

class timor.Volume.BoxVolume(limits, offset=Transformation.neutral())
Inheritance diagram of timor.Volume.BoxVolume

A box volume is an expansion in the three-dimensional euclidean space forming a solid box.

The basic building block of a box volume.

Parameters:
  • limits (numpy.ndarray) – Defined by :math:(x, y, z) with shape (3,2)

  • offset (timor.utilities.transformation.TransformationLike) – Transformation offset of the volume, inherited from super class

__slots__ = ()
_limits: numpy.ndarray
_offset: timor.utilities.transformation.Transformation
_projection(point)

Keep cartesian coordinates

Parameters:

point (numpy.ndarray)

Return type:

numpy.ndarray

_rounding_error: float = 1e-12
contains(r_point)

Check whether a given point (3,) locates within the volume

Parameters:

r_point (Union[Sequence[float], timor.utilities.transformation.Transformation])

Return type:

bool

discretize(grid_size)

Discretize points in grid form inside this volume.

It should be noticed that a hyperrectangle must surround a sphere or cylinder, which also means there could be many points existing in the complementary space between the volume and hyperrectangle. So a contains check is a must for the volume subclass. Those not contained in the volume will be given “nan” value.

Parameters:

grid_size (Sequence[int]) – the number of grid along each side of the hyperbox, should be an integer array.

Returns:

A (grid_size x grid_size x grid_size x 3) array as a point representing the center of the subgrid. Notice: There could also be “nan” for sphere and cylinder for those fail to pass the contains check.

Return type:

numpy.ndarray

is_convex()

A fully filled box is always convex.

Return type:

bool

property lim_x: numpy.ndarray

Exposes the limits in x-direction

Return type:

numpy.ndarray

property lim_y: numpy.ndarray

Exposes the limits in y-direction

Return type:

numpy.ndarray

property lim_z: numpy.ndarray

Exposes the limits in z-direction

Return type:

numpy.ndarray

property limit_rectangular_cuboid: numpy.ndarray

Return the edge vertices for box with the minimal and maximal value in each dimension.

Return type:

numpy.ndarray

sample_uniform(rng=None)

Sample points within the partial box which are defined by [x, y, z] uniformly.

Parameters:

rng (Optional[numpy.random.Generator]) – Random number generator

Returns:

A point which is sampled uniformly inside the volume

Return type:

numpy.ndarray

property vol: float

The actual volume of the partial sampling space

Return type:

float

class timor.Volume.CylinderVolume(limits, offset=Transformation.neutral())
Inheritance diagram of timor.Volume.CylinderVolume

A cylindrical volume is an expansion in the three-dimensional euclidean space forming a solid cylinder.

The basic building block of a cylindrical volume.

Parameters:
  • limits (numpy.ndarray) – Defined by :math:(r, phi, z) with shape (3,2), where, \(\phi\) is in the range of \((-\pi, \pi).\)

  • offset (timor.utilities.transformation.TransformationLike) – Transformation offset of the volume, inherited from super class

__slots__ = ()
_limits: numpy.ndarray
_offset: timor.utilities.transformation.Transformation
_projection(point)

Map cartesian to cylindrical coordinates

Parameters:

point (numpy.ndarray)

Return type:

numpy.ndarray

_rounding_error: float = 1e-12
contains(r_point)

Check whether a given point (3,) locates within the volume

Parameters:

r_point (Union[Sequence[float], timor.utilities.transformation.Transformation])

Return type:

bool

discretize(grid_size)

Discretize points in grid form inside this volume.

It should be noticed that a hyperrectangle must surround a sphere or cylinder, which also means there could be many points existing in the complementary space between the volume and hyperrectangle. So a contains check is a must for the volume subclass. Those not contained in the volume will be given “nan” value.

Parameters:

grid_size (Sequence[int]) – the number of grid along each side of the hyperbox, should be an integer array.

Returns:

A (grid_size x grid_size x grid_size x 3) array as a point representing the center of the subgrid. Notice: There could also be “nan” for sphere and cylinder for those fail to pass the contains check.

Return type:

numpy.ndarray

classmethod from_radius_height(r, z)

The limits for the full cylinder with radius = r and height = z

is_convex()

Check whether the cylinder volume is convex.

Return type:

bool

property lim_phi: numpy.ndarray

The azimuthal limits

Return type:

numpy.ndarray

property lim_r: numpy.ndarray

The radial limits

Return type:

numpy.ndarray

property lim_z: numpy.ndarray

The height limits

Return type:

numpy.ndarray

property limit_rectangular_cuboid: numpy.ndarray

Return the edge vertices for cylinder with the minimal and maximal value in each dimension

Return type:

numpy.ndarray

sample_uniform(rng=None)

Sample points within the partial cylinder which are defined by [r, theta, height] uniformly.

Parameters:

rng (Optional[numpy.random.Generator]) – Random number generator

Returns:

A point which is sampled uniformly inside the volume

Return type:

numpy.ndarray

property vol: float

The actual volume of the partial sampling space

Return type:

float

class timor.Volume.SphereVolume(limits, offset=Transformation.neutral())
Inheritance diagram of timor.Volume.SphereVolume

A spherical volume is an expansion in the three-dimensional euclidean space forming a fully/partially filled sphere.

The basic building block of a spherical volume.

Parameters:
  • limits (numpy.ndarray) – Defined by :math:(r, theta, phi)` with shape (3,2) according to ISO 80000-2:2019 representation where, \(\theta\) is in the range of \((0, \pi).\) \(\phi\) is in \((-\pi, \pi).\)

  • offset (timor.utilities.transformation.TransformationLike) – Transformation offset of the volume, inherited from super class

__slots__ = ()
_limits: numpy.ndarray
_offset: timor.utilities.transformation.Transformation
_projection(point)

Map cartesian to spherical coordinates

Parameters:

point (numpy.ndarray)

Return type:

numpy.ndarray

_rounding_error: float = 1e-12
contains(r_point)

Check whether a given point (3,) locates within the volume

Parameters:

r_point (Union[Sequence[float], timor.utilities.transformation.Transformation])

Return type:

bool

discretize(grid_size)

Discretize points in grid form inside this volume.

It should be noticed that a hyperrectangle must surround a sphere or cylinder, which also means there could be many points existing in the complementary space between the volume and hyperrectangle. So a contains check is a must for the volume subclass. Those not contained in the volume will be given “nan” value.

Parameters:

grid_size (Sequence[int]) – the number of grid along each side of the hyperbox, should be an integer array.

Returns:

A (grid_size x grid_size x grid_size x 3) array as a point representing the center of the subgrid. Notice: There could also be “nan” for sphere and cylinder for those fail to pass the contains check.

Return type:

numpy.ndarray

classmethod from_radius(r)

The limits for the full sphere with radius equal to r

is_convex()

Check whether the sphere volume is convex.

Return type:

bool

property lim_phi: numpy.ndarray

The polar limits

Return type:

numpy.ndarray

property lim_r: numpy.ndarray

The radial limits

Return type:

numpy.ndarray

property lim_theta: numpy.ndarray

The azimuthal limits

Return type:

numpy.ndarray

property limit_rectangular_cuboid: numpy.ndarray

Return the edge vertices for sphere with the minimal and maximal value in each dimension.

It should be noticed that this could be quite a bit tighter if the allowed angles are restricted.

Return type:

numpy.ndarray

sample_uniform(rng=None)

Sample points within the partial sphere which are defined by [r, theta, phi] uniformly.

Parameters:

rng (Optional[numpy.random.Generator]) – Random number generator

Source:

stats.stackexchange.com/questions/8021

Returns:

A point which is sampled uniformly inside the volume

Return type:

numpy.ndarray

property vol: float

The actual volume of the partial sampling space

Return type:

float

class timor.Volume.Volume(limits, offset=Transformation.neutral())
Inheritance diagram of timor.Volume.Volume

A Volume is a connected sub-set of a three-dimensional euclidean space.

Initialize a volume with a transformation offset for every sample.

Parameters:
  • limits (numpy.ndarray) – Limits for defining the shape of the volume -> (3,2)

  • offset (timor.utilities.transformation.TransformationLike) – Transformation offset of the volume with shape -> (4,4)

__slots__ = ()
_limits: numpy.ndarray
_offset: timor.utilities.transformation.Transformation
abstractmethod _projection(point)

Maps a point to the projection space of the limits

Parameters:

point (numpy.ndarray)

Return type:

numpy.ndarray

_rounding_error: float = 1e-12
contains(r_point)

Check whether a given point (3,) locates within the volume

Parameters:

r_point (Union[Sequence[float], timor.utilities.transformation.Transformation])

Return type:

bool

discretize(grid_size)

Discretize points in grid form inside this volume.

It should be noticed that a hyperrectangle must surround a sphere or cylinder, which also means there could be many points existing in the complementary space between the volume and hyperrectangle. So a contains check is a must for the volume subclass. Those not contained in the volume will be given “nan” value.

Parameters:

grid_size (Sequence[int]) – the number of grid along each side of the hyperbox, should be an integer array.

Returns:

A (grid_size x grid_size x grid_size x 3) array as a point representing the center of the subgrid. Notice: There could also be “nan” for sphere and cylinder for those fail to pass the contains check.

Return type:

numpy.ndarray

property is_convex: bool
Abstractmethod:

Return type:

bool

Determines whether the volume is convex.

This should be implemented by subclasses based on their specific geometric properties.

property limit_rectangular_cuboid: numpy.ndarray
Abstractmethod:

Return type:

numpy.ndarray

Get the edge vertex with the extreme value in each dimension for a hyperrectangle over-approximating the volume.

Returns:

2x3 array with the first element for minimal vertex and the second for maximal vertex

Return type:

numpy.ndarray

abstractmethod sample_uniform(rng=None)

Uniformly sample a point inside the volume.

Parameters:

rng (Optional[numpy.random.Generator]) – Random number generator

Returns:

A point as a (3,) np array

Return type:

numpy.ndarray

property vol: float
Abstractmethod:

Return type:

float

Calculate the actual volume of the sampling space