timor.Volume
Classes
A box volume is an expansion in the three-dimensional euclidean space forming a solid box. |
|
A cylindrical volume is an expansion in the three-dimensional euclidean space forming a solid cylinder. |
|
A spherical volume is an expansion in the three-dimensional euclidean space forming a fully/partially filled sphere. |
|
A Volume is a connected sub-set of a three-dimensional euclidean space. |
Module Contents
- class timor.Volume.BoxVolume(limits, offset=Transformation.neutral())

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
- _projection(point)
Keep cartesian coordinates
- Parameters:
point (numpy.ndarray)
- Return type:
- 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:
- 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:
- property lim_x: numpy.ndarray
Exposes the limits in x-direction
- Return type:
- property lim_y: numpy.ndarray
Exposes the limits in y-direction
- Return type:
- property lim_z: numpy.ndarray
Exposes the limits in z-direction
- Return type:
- property limit_rectangular_cuboid: numpy.ndarray
Return the edge vertices for box with the minimal and maximal value in each dimension.
- Return type:
- 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:
- class timor.Volume.CylinderVolume(limits, offset=Transformation.neutral())

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
- _projection(point)
Map cartesian to cylindrical coordinates
- Parameters:
point (numpy.ndarray)
- Return type:
- 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:
- 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:
- classmethod from_radius_height(r, z)
The limits for the full cylinder with radius = r and height = z
- property lim_phi: numpy.ndarray
The azimuthal limits
- Return type:
- property lim_r: numpy.ndarray
The radial limits
- Return type:
- property lim_z: numpy.ndarray
The height limits
- Return type:
- property limit_rectangular_cuboid: numpy.ndarray
Return the edge vertices for cylinder with the minimal and maximal value in each dimension
- Return type:
- 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:
- class timor.Volume.SphereVolume(limits, offset=Transformation.neutral())

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
- _projection(point)
Map cartesian to spherical coordinates
- Parameters:
point (numpy.ndarray)
- Return type:
- 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:
- 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:
- classmethod from_radius(r)
The limits for the full sphere with radius equal to r
- property lim_phi: numpy.ndarray
The polar limits
- Return type:
- property lim_r: numpy.ndarray
The radial limits
- Return type:
- property lim_theta: numpy.ndarray
The azimuthal limits
- Return type:
- 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:
- 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:
- class timor.Volume.Volume(limits, offset=Transformation.neutral())

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
- abstractmethod _projection(point)
Maps a point to the projection space of the limits
- Parameters:
point (numpy.ndarray)
- Return type:
- 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:
- 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:
- property is_convex: bool
- Abstractmethod:
- Return type:
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:
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:
- 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: