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],
... part = [],
... Units = cf.Units('K'))
>>> 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],
... part = [slice(None, None, -1), [0,1,3,4], slice(None)],
... Units = cf.Units('K'))
>>> p = Partition(data = numpy.array(4),
... direction = True,
... location = [(4, 5)],
... order = ['dim1'],
... shape = [1],
... part = [],
... Units = cf.Units('K'))
Partition attributes
data | |
direction | |
in_memory | True if and only if the partition’s data is in memory as opposed to on disk. |
indices | The indices of the master array which correspond to this partition’s data. |
isscalar | True if and only if the partition’s data is a scalar array. |
location | |
on_disk | Return True if the partition’s data is on disk as opposed to in memory. |
order | |
part | |
shape |
Partition methods
close | Close the partition. |
conform | 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. |
copy | Return a deep copy. |
iterarray_indices | Return an iterator over indices of the conformed array. |
itermaster_indices | Return an iterator over indices of the master array which are spanned by the conformed array. |
new_part | Return the part attribute updated for new indices. |
to_disk | Store the partition’s data in a temporary file on disk in place. |
update_from | Completely update the partition with another partition’s attributes in place. |
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 an iterator over indices of the conformed array.
The array is not conformed.
Returns : |
|
---|
Examples
>>> p.shape
[2, 1, 3]
>>> for index in p.iterarray_indices():
... print index
...
(0, 0, 0)
(0, 0, 1)
(0, 0, 2)
(1, 0, 0)
(1, 0, 1)
(1, 0, 2)
Return an iterator over indices of the master array which are spanned by the conformed array.
The array is not conformed.
Returns : |
|
---|
Examples
>>> p.location
[(3, 5), (0, 1), (0, 3)]
>>> for index in p.itermaster_indices():
... print index
...
(3, 0, 0)
(3, 0, 1)
(3, 0, 2)
(4, 0, 0)
(4, 0, 1)
(4, 0, 2)
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.isscalar
True
>>> p.data.ndim
1
>>> p.isscalar
False
Return True if the partition’s data is on disk as opposed to in memory.
Examples
>>> p.on_disk
True