Bases: object
A partition.
Initialization
Parameters : |
|
---|
Examples
>>> p = Partition(data = numpy.arange(20).reshape(2,5,1),
direction = {'dim0', True, 'dim1': False, 'dim2': True},
location = [(0, 6), (1, 3), (4, 5)],
order = ['dim1', 'dim0', 'dim2'],
shape = [5, 2, 1],
Units = cf.Units('K'),
part = [],
>>> p = Partition(data = numpy.arange(20).reshape(2,5,1),
direction = {'dim0', True, 'dim1': False, 'dim2': True},
location = [(0, 6), (1, 3), (4, 5)],
order = ['dim1', 'dim0', 'dim2'],
shape = [5, 2, 1],
Units = cf.Units('K'),
part = [slice(None, None, -1), [0,1,3,4], slice(None)],
>>> p = Partition(data = numpy.array(4),
direction = True,
location = [(4, 5)],
order = ['dim1'],
shape = [1],
Units = cf.Units('K'),
part = [],
Close the partition.
Closing the partition is important for memory management. The partition should always be closed after it is conformed to prevent memory leaks.
Closing the partition does one of three things, depending on the values of the partition’s _original and _save attributes and on the save parameter: * Nothing. * Stores the data in a temporary file. * Reverts the partition to a previous state.
Parameters : |
|
---|---|
Returns : | None |
Examples
>>> p.close()
After a partition has been conformed, the partition must be closed (with the close method) before another partition is conformed, otherwise a memory leak could occur. For example:
>>> order = partition_array.order
>>> direction = partition_array.direction
>>> units = partition_array.units
>>> save = partition_array.save_to_disk()
>>> revert_to_file = True
>>> for partition in partition_array.flat():
...
... # Conform the partition
... partition.conform(order, direction, units, save, revert_to_file)
...
... # [ Some code to operate on the conformed partition ]
...
... # Close the partition
... partition.close()
...
... # Now move on to conform the next partition
...
>>>
Parameters : | order : list direction : dict units : Units
|
---|---|
Returns : |
|
Return a deep copy.
Equivalent to copy.deepcopy(p).
Returns : |
|
---|
Examples
>>> q = p.copy()
Return the part attribute updated for new indices.
Does not change the partition in place.
Parameters : | indices : list dim2position : dict data_direction : dict |
---|---|
Returns : | out : list |
Examples
>>> p.part = p.new_part(indices, dim2position, data_direction)
Store the partition’s data in a temporary file on disk in place.
Assumes that the partition’s data is currently in memory, but this is not checked.
Returns : | None |
---|
Examples
>>> p.to_disk()
Completely update the partition with another partition’s attributes in place.
The updated partition is always independent of the other partition.
Parameters : | other : Partition |
---|---|
Returns : | None |
Examples
>>> p.update_from(q)
True if and only if the partition’s data is in memory as opposed to on disk.
Examples
>>> p.in_memory
False
The indices of the master array which correspond to this partition’s data.
Returns : |
|
---|
Examples
>>> p.data.shape
(5, 7)
>>> p.indices
(slice(0, 5), slice(2, 9))
>>> p.data.shape
()
>>> p.indices
()
True if and only if the partition’s data is a scalar array.
Examples
>>> p.data.ndim
0
>>> p.is_scalar
True
>>> p.data.ndim
1
>>> p.is_scalar
False
Return True if the partition’s data is on disk as opposed to in memory.
Examples
>>> p.on_disk
True