cf.PartitionArray

class cf.PartitionArray(array, **kwargs)

Bases: cf.utils.CfList

An N-dimensional partition array.

Initialization

Parameters :
array : list

A (possibly nested) list of Partition objects.

# _FillValue : optional # The fill value of the data array. By default the numpy fill # value appropriate to the data-type will be used.

direction : bool or dict, optional
The direction of each dimension of the data array. It is a boolean if the data array is a scalar array, otherwise it is a dictionary keyed by the dimensions’ identities found in order.

# ndim : int, optional # Number of dimensions in the data array.

order : list, optional
The identities of the dimensions of the data array. If the data array is a scalar array then it is an empty list.
pdims : list, optional
The identities of the partition dimensions of the partition array. Each element is also found in order. If partition array is a scalar array then it is an empty list.

# shape : list, optional # The data array’s dimension sizes. # # size : int, optional # Number of elements in the data array. # # Units : Units, optional # The units of the data.

Examples

>>> pa = PartitionArray(
        [Partition(location  = [(0,n) for n in shape],
                   shape     = shape[:],
                   order     = order[:],
                   direction = copy(direction),
                   Units     = units.copy(),
                   part      = [],
                   data      = data)
         ],
        order      = order,
#        hardmask   = False,
#        shape      = shape,
#        size       = data.size,
#        Units      = units.copy(),
#        ndim       = ndim,
        direction  = direction,
        pdims      = [],
        _FillValue = _FillValue)
add_partitions(extra_boundaries, pdim, existing_boundaries=None)
change_dimension_names(dim_name_map)

dim_name_map should be a dictionary which maps each dimension names in self.order to its new dimension name. E.g. {‘dim0’:’dim1’, ‘dim1’:’dim0’}

copy(_copy_attr=True)

Return a deep copy.

Do not set the _copy_attr parameter. It is for internal use only.

Equivalent to copy.deepcopy(pa).

Returns :
out :

The deep copy.

Examples

>>> pa.copy()
count(value)

Return the number of occurrences of a given value.

Uses numerically tolerant equality where appropriate.

Parameters :
value :

The value to count.

Returns :
out : int

The number of occurrences of value.

Examples

>>> s
[1, 2, 3, 2, 4, 2]
>>> s.count(1)
1
>>> s.count(2)
3
equals(other, rtol=None, atol=None, traceback=False)

True if two instances are equal, False otherwise.

Two instances are equal if their attributes are equal and their elements are equal pair-wise.

Parameters :
other :

The object to compare for equality.

atol : float, optional

The absolute tolerance for all numerical comparisons, By default the value returned by the ATOL function is used.

rtol : float, optional

The relative tolerance for all numerical comparisons, By default the value returned by the RTOL function is used.

traceback : bool, optional

If True then print a traceback highlighting where the two instances differ.

Returns :
out : bool

Whether or not the two instances are equal.

expand_pdims(pdim)

Insert a new size 1 partition dimension in place.

The new parition dimension is inserted at position 0.

Parameters :
axis : str

The name of the new partition dimension.

Returns :

None

Examples

>>> pa.pdims
['dim0', 'dim1']
>>> pa.expand_pdims('dim2')
>>> pa.pdims
['dim2', 'dim0', 'dim1']
flat()

Return a flat iterator over the Partition objects in the partition array.

Returns :
out : generator

An iterator over the elements of the partition array.

Examples

>>> type(pa.flat())
<generator object flat at 0x145a0f0>
>>> for partition in pa.flat():
...     print partition.Units
index(value, start=0, stop=None)

Return the first index of a given value.

Uses numerically tolerant equality where appropriate.

Parameters :
value :

The value to look for in the list.

start : int, optional

Start looking from this index. By default, look from the beginning of the list.

stop : int, optional

Stop looking before this index. By default, look up to the end of the list.

Returns :

out : int

Raises :
ValueError :

If the given value is not in the list.

Examples

>>> s
[1, 2, 3, 2, 4, 2]
>>> s.index(1)
1
>>> s.index(2, 2)
3
>>> s.index(2, start=2, stop=5)
3
>>> s.index(6)
ValueError: CfList doesn't contain: 6
info(attr)
insert(index, item)

Insert an object before the given index in place.

Parameters :

index : int

item :

Returns :

None

Examples

>>> s
[1, 2, 3]
>>> s.insert(1, 'A')
>>> s
[1, 'A', 2, 3]
>>> s.insert(100, 'B')
[1, 'A', 2, 3, 'B']
>>> s.insert(100, 'B')
[1, 'A', 2, 3, 'B']
>>> s.insert(-2, 'C')
[1, 'A', 2, 'C', 3, 'B']
>>> s.insert(-100, 'D')
['D', 1, 'A', 2, 'C', 3, 'B']
partition_boundaries()
ravel()

Return a flattened partition array as a built-in list.

Returns :
out : list of Partitions

A list containing the flattened partition array.

Examples

>>> x = partitions.ravel()
>>> type(x)
list
rollaxis(axis, start=0)

Roll the specified partition dimension backwards,in place until it lies in a given position.

This does not change the master array.

Parameters :
axis : int

The axis to roll backwards. The positions of the other axes do not change relative to one another.

start : int, optional

The axis is rolled until it lies before this position. The default, 0, results in a “complete” roll.

Returns :

None

Examples

>>> pa.rollaxis(2)
>>> pa.rollaxis(2, start=1)
set_location_map()

Recalculate the location attribute of each Partition object in the partition array in place.

Examples

>>> pa.set_location_map()
squeeze()

Remove all size 1 partition dimensions in place.

Returns :None

Examples

>>> pa.pdims
['dim0', 'dim1', 'dim2']
>>> pa._list
[[[<cf.partition.Partition object at 0x145daa0>,
   <cf.partition.Partition object at 0x145db90>]],
 [[<cf.partition.Partition object at 0x145dc08>,
   <cf.partition.Partition object at 0x145dd70>]]]
>>> pa.squeeze()
>>> pa.pdims
['dim0', 'dim2']
>>> pa._list
[[<cf.partition.Partition object at 0x145daa0>,
  <cf.partition.Partition object at 0x145db90>],
 [<cf.partition.Partition object at 0x145dc08>,
  <cf.partition.Partition object at 0x145dd70>]]
transpose(axes)

Permute the partition dimensions of the partition array in place.

This does not change the master array.

Parameters :
axes : sequence of ints

Permute the axes according to the values given.

Returns :

None

Examples

>>> pa.transpose((2,0,1))
isscalar

True if the master array is a 0-d scalar array.

Examples

>>> pa.order
[]
>>> pa.isscalar
True
>>> len(pa.order) >= 1
True
>>> pa.isscalar
False
pndim

The number of partition dimensions in the partition array.

Examples

>>> pa.pndim
2
pshape

Examples

psize

The number of partitions in the partition array.

Examples

>>> pa.psize
7

This Page