cf.Field.pad_missing

Field.pad_missing(axis, pad_width=None, to_size=None, inplace=False)[source]

Pad an axis with missing data.

The field’s data and all metadata constructs that span the axis are padded.

New in version 3.16.1.

Parameters
axis: str or int

Select the domain axis which is to be padded, defined by that which would be selected by passing the given axis description to a call of the field construct’s domain_axis method. For example, for a value of 'X', the domain axis construct returned by f.domain_axis('X') is selected.

pad_width: sequence of int, optional

Number of values to pad before and after the edges of the axis.

to_size: int, optional

Pad the axis after so that the new axis has the given size.

inplace: bool, optional

If True then do the operation in-place and return None.

Returns
Field or None

The padded field construct, or None if the operation was in-place.

Examples

>>> f = cf.example_field(6)
>>> print(f)
Field: precipitation_amount (ncvar%pr)
--------------------------------------
Data            : precipitation_amount(cf_role=timeseries_id(2), time(4))
Dimension coords: time(4) = [2000-01-16 12:00:00, ..., 2000-04-15 00:00:00] gregorian
Auxiliary coords: latitude(cf_role=timeseries_id(2)) = [25.0, 7.0] degrees_north
                : longitude(cf_role=timeseries_id(2)) = [10.0, 40.0] degrees_east
                : cf_role=timeseries_id(cf_role=timeseries_id(2)) = [x1, y2]
                : altitude(cf_role=timeseries_id(2), 3, 4) = [[[1.0, ..., --]]] m
Coord references: grid_mapping_name:latitude_longitude
>>> print(f.array)
[[1. 2. 3. 4.]
 [5. 6. 7. 8.]]
>>> g = f.pad_missing('T', (0, 5))
>>> print(g)
Field: precipitation_amount (ncvar%pr)
--------------------------------------
Data            : precipitation_amount(cf_role=timeseries_id(2), time(9))
Dimension coords: time(9) = [2000-01-16 12:00:00, ..., --] gregorian
Auxiliary coords: latitude(cf_role=timeseries_id(2)) = [25.0, 7.0] degrees_north
                : longitude(cf_role=timeseries_id(2)) = [10.0, 40.0] degrees_east
                : cf_role=timeseries_id(cf_role=timeseries_id(2)) = [x1, y2]
                : altitude(cf_role=timeseries_id(2), 3, 4) = [[[1.0, ..., --]]] m
Coord references: grid_mapping_name:latitude_longitude
>>> print(g.array)
[[1.0 2.0 3.0 4.0 -- -- -- -- --]
 [5.0 6.0 7.0 8.0 -- -- -- -- --]]
>>> h = g.pad_missing('cf_role=timeseries_id', (0, 1))
>>> print(h)
Field: precipitation_amount (ncvar%pr)
--------------------------------------
Data            : precipitation_amount(cf_role=timeseries_id(3), time(9))
Dimension coords: time(9) = [2000-01-16 12:00:00, ..., --] gregorian
Auxiliary coords: latitude(cf_role=timeseries_id(3)) = [25.0, 7.0, --] degrees_north
                : longitude(cf_role=timeseries_id(3)) = [10.0, 40.0, --] degrees_east
                : cf_role=timeseries_id(cf_role=timeseries_id(3)) = [x1, y2, --]
                : altitude(cf_role=timeseries_id(3), 3, 4) = [[[1.0, ..., --]]] m
Coord references: grid_mapping_name:latitude_longitude
>>> print(h.array)
[[1.0 2.0 3.0 4.0 -- -- -- -- --]
 [5.0 6.0 7.0 8.0 -- -- -- -- --]
 [ --  --  --  -- -- -- -- -- --]]
>>> print(f.pad_missing('time', to_size=6))
Field: precipitation_amount (ncvar%pr)
--------------------------------------
Data            : precipitation_amount(cf_role=timeseries_id(2), time(6))
Dimension coords: time(6) = [2000-01-16 12:00:00, ..., --] gregorian
Auxiliary coords: latitude(cf_role=timeseries_id(2)) = [25.0, 7.0] degrees_north
                : longitude(cf_role=timeseries_id(2)) = [10.0, 40.0] degrees_east
                : cf_role=timeseries_id(cf_role=timeseries_id(2)) = [x1, y2]
                : altitude(cf_role=timeseries_id(2), 3, 4) = [[[1.0, ..., --]]] m
Coord references: grid_mapping_name:latitude_longitude