amulet.api.partial_3d_array.bounded_partial_3d_array
module¶
- class amulet.api.partial_3d_array.BoundedPartial3DArray(dtype, default_value, section_shape, start, stop, step, parent_array)[source]¶
This class should behave the same as a numpy array in all three axis but the data internally is stored in sections to minimise memory usage. The array has a fixed size in all three axis much like a numpy array.
- classmethod from_partial_array(parent_array, start, stop, step)[source]¶
Create a
BoundedPartial3DArray
from anUnboundedPartial3DArray
and slices.- Parameters
- Returns
A new instance of
BoundedPartial3DArray
that behaves like a view into the parent array.
- __init__(dtype, default_value, section_shape, start, stop, step, parent_array)[source]¶
Construct a
BoundedPartial3DArray
. This should not be used directly. You should instead use the__getitem__()
method ofUnboundedPartial3DArray
- Parameters
dtype (
Union
[Type
[dtype
],Type
[bool
]]) – The dtype that all arrays will be stored in.default_value (
Union
[int
,bool
]) – The default value that all undefined arrays will be populated with if required.section_shape (
Tuple
[int
,int
,int
]) – The shape of each section array.start (
Tuple
[Optional
[int
],int
,Optional
[int
]]) – The starting point of the slice.stop (
Tuple
[Optional
[int
],int
,Optional
[int
]]) – The end point of the slice.step (
Tuple
[Optional
[int
],Optional
[int
],Optional
[int
]]) – The steps of the slice.parent_array (
UnboundedPartial3DArray
) – The originalUnboundedPartial3DArray
that the slice is viewing into.
- __array__(dtype=None)[source]¶
Get the data contained within as a numpy array.
>>> numpy.array(partial_array)
- Parameters
dtype – The dtype of the returned numpy array.
- Returns
A numpy array of the contained data.
- __eq__(value)[source]¶
Check equality of this object and another object.
Behaves mostly the same as a numpy array.
>>> bounded_partial_array1 == bounded_partial_array2
- Parameters
value – The object to compare to.
- Returns
- __contains__(item)[source]¶
Is a section array defined.
>>> 5 in partial_array True
- Parameters
item (
int
) – The section index to test.- Returns
True
if there is an array present for this section.False
otherwise
- property default_value: Union[int, bool][source]¶
The default value to populate undefined sections with. Read Only
- property section_shape: Tuple[int, int, int][source]¶
The x, y and z size of a section in the original array.
- property shape: Tuple[int, Union[int, float], int][source]¶
The size of the array in the x, y and z axis. Read Only
- property slices_tuple: Tuple[Tuple[int, int, int], Tuple[int, int, int], Tuple[int, int, int]][source]¶
The slices data in the x, y and z axis into the original array. Read Only
- property start: Tuple[int, int, int][source]¶
The minimum x, y and z of the slice within the original array. Read Only
- property start_x: int[source]¶
The minimum x value of the slice within the original array. Read Only
- property start_y: Optional[int][source]¶
The minimum y value of the slice within the original array. Read Only
- property start_z: int[source]¶
The minimum z value of the slice within the original array. Read Only
- property step: Tuple[int, int, int][source]¶
The step count of the slice in the x, y and z axis. Read Only
- property stop: Tuple[int, int, int][source]¶
The maximum x value of the slice within the original array. Read Only
- property stop_y: Optional[int][source]¶
The maximum y value of the slice within the original array. Read Only
- __getitem__(item)[source]¶
Get a value or sub-section of the unbounded array.
>>> # get the value at a given location >>> value = partial_array[3, 4, 5] # an integer >>> # get a cuboid volume in the array >>> value = partial_array[2:3, 4:5, 6:7] # BoundedPartial3DArray >>> # slice and int can be mixed >>> value = partial_array[2:3, 4, 6:7] # BoundedPartial3DArray
- Parameters
item – The slices to extract.
- Returns
The value or BoundedPartial3DArray viewing into this array.
- __setitem__(item, value)[source]¶
Set a sub-section of the array.
>>> # set the value at a given location >>> partial_array[3, 4, 5] = 1 >>> # set a cuboid volume in the array >>> partial_array[2:3, 4:5, 6:7] = 1 >>> # slice and int can be mixed >>> partial_array[2:3, 4, 6:7] = 1
- Parameters
slices – The slices or locations that define the volume to set.
value – The value to set at the given location. Can be an integer or array.