cf.Data.halo¶

Data.
halo
(size, axes=None, tripolar=None, fold_index=1, inplace=False, verbose=None)[source]¶ Expand the data by adding a halo.
The halo may be applied over a subset of the data dimensions and each dimension may have a different halo size (including zero). The halo region is populated with a copy of the proximate values from the original data.
Cyclic axes
A cyclic axis that is expanded with a halo of at least size 1 is no longer considered to be cyclic.
Tripolar domains
Data for global tripolar domains are a special case in that a halo added to the northern end of the “Y” axis must be filled with values that are flipped in “X” direction. Such domains need to be explicitly indicated with the tripolar parameter.
New in version 3.5.0.
 Parameters
 size:
int
ordict
Specify the size of the halo for each axis.
If size is a nonnegative
int
then this is the halo size that is applied to all of the axes defined by the axes parameter.Alternatively, halo sizes may be assigned to axes individually by providing a
dict
for which a key specifies an axis (defined by its integer position in the data) with a corresponding value of the halo size for that axis. Axes not specified by the dictionary are not expanded, and the axes parameter must not also be set. Parameter example:
Specify a halo size of 1 for all otherwise selected axes:
size=1
 Parameter example:
Specify a halo size of zero
size=0
. This results in no change to the data shape. Parameter example:
For data with three dimensions, specify a halo size of 3 for the first dimension and 1 for the second dimension:
size={0: 3, 1: 1}
. This is equivalent tosize={0: 3, 1: 1, 2: 0}
 Parameter example:
Specify a halo size of 2 for the first and last dimensions
size=2, axes=[0, 1]`
or equivalentlysize={0: 2, 1: 2}
.
 axes: (sequence of)
int
Select the domain axes to be expanded, defined by their integer positions in the data. By default, or if axes is
None
, all axes are selected. No axes are expanded if axes is an empty sequence. tripolar:
dict
, optional A dictionary defining the “X” and “Y” axes of a global tripolar domain. This is necessary because in the global tripolar case the “X” and “Y” axes need special treatment, as described above. It must have keys
'X'
and'Y'
, whose values identify the corresponding domain axis construct by their integer positions in the data.The “X” and “Y” axes must be a subset of those identified by the size or axes parameter.
See the fold_index parameter.
 Parameter example:
Define the “X” and Y” axes by positions 2 and 1 respectively of the data:
tripolar={'X': 2, 'Y': 1}
 fold_index:
int
, optional Identify which index of the “Y” axis corresponds to the fold in “X” axis of a tripolar grid. The only valid values are
1
for the last index, and0
for the first index. By default it is assumed to be the last index. Ignored if tripolar isNone
. inplace:
bool
, optional If True then do the operation inplace and return
None
. verbose:
int
orNone
, optional If an integer from
0
to3
, corresponding to increasing verbosity (else1
as a special case of maximal and extreme verbosity), set for the duration of the method call (only) as the minimum severity level cutoff of displayed log messages, regardless of the global configuredcf.LOG_LEVEL
.Else, if
None
(the default value), log messages will be filtered out, or otherwise, according to the value of thecf.LOG_LEVEL
setting.Overall, the higher a nonnegative integer that is set (up to a maximum of
3
) the more description that is printed to convey information about the operation.
 size:
 Returns
Examples:
>>> d = cf.Data(numpy.arange(12).reshape(3, 4), 'm') >>> d[1, 1] = cf.masked >>> d[1, 1] = cf.masked >>> print(d.array) [[ 0 1 2 3] [ 4  6 7] [ 8 9 10 ]]
>>> e = d.halo(1) >>> print(e.array) [[ 0 0 1 2 3 3] [ 0 0 1 2 3 3] [ 4 4  6 7 7] [ 8 8 9 10  ] [ 8 8 9 10  ]] >>> d.equals(e[1:1, 1:1]) True
>>> e = d.halo(2) >>> print(e.array) [[ 0 1 0 1 2 3 2 3] [ 4  4  6 7 6 7] [ 0 1 0 1 2 3 2 3] [ 4  4  6 7 6 7] [ 8 9 8 9 10  10 ] [ 4  4  6 7 6 7] [ 8 9 8 9 10  10 ]] >>> d.equals(e[2:2, 2:2]) True
>>> e = d.halo(0) >>> d.equals(e) True
>>> e = d.halo(1, axes=0) >>> print(e.array) [[ 0 1 2 3] [ 0 1 2 3] [ 4  6 7] [ 8 9 10 ] [ 8 9 10 ]] >>> d.equals(e[1:1, :]) True >>> f = d.halo({0: 1}) >>> f.equals(e) True
>>> e = d.halo(1, tripolar={'X': 1, 'Y': 0}) >>> print(e.array) [[ 0 0 1 2 3 3] [ 0 0 1 2 3 3] [ 4 4  6 7 7] [ 8 8 9 10  ] [  10 9 8 8]]
>>> e = d.halo(1, tripolar={'X': 1, 'Y': 0}, fold_index=0) >>> print(e.array) [[ 3 3 2 1 0 0] [ 0 0 1 2 3 3] [ 4 4  6 7 7] [ 8 8 9 10  ] [ 8 8 9 10  ]]