cf.Field


class cf.Field(properties=None, source=None, copy=True, _use_data=True)[source]

Bases: cf.mixin.propertiesdata.PropertiesData, cfdm.field.Field

A field construct of the CF data model.

The field construct is central to the CF data model, and includes all the other constructs. A field corresponds to a CF-netCDF data variable with all of its metadata. All CF-netCDF elements are mapped to a field construct or some element of the CF field construct. The field construct contains all the data and metadata which can be extracted from the file using the CF conventions.

The field construct consists of a data array and the definition of its domain (that describes the locations of each cell of the data array), field ancillary constructs containing metadata defined over the same domain, and cell method constructs to describe how the cell values represent the variation of the physical quantity within the cells of the domain. The domain is defined collectively by the following constructs of the CF data model: domain axis, dimension coordinate, auxiliary coordinate, cell measure, coordinate reference and domain ancillary constructs.

The field construct also has optional properties to describe aspects of the data that are independent of the domain. These correspond to some netCDF attributes of variables (e.g. units, long_name and standard_name), and some netCDF global file attributes (e.g. history and institution).

NetCDF interface

The netCDF variable name of the construct may be accessed with the nc_set_variable, nc_get_variable, nc_del_variable and nc_has_variable methods.

The selection of properties to be written as netCDF global attributes may be accessed with the nc_global_attributes, nc_clear_global_attributes and nc_set_global_attribute methods.

The netCDF variable group structure may be accessed with the nc_set_variable, nc_get_variable, nc_variable_groups, nc_clear_variable_groups and nc_set_variable_groups methods.

The netCDF group attributes may be accessed with the nc_group_attributes, nc_clear_group_attributes, nc_set_group_attribute and nc_set_group_attributes methods.

The netCDF geometry variable group structure may be accessed with the nc_set_geometry_variable, nc_get_geometry_variable, nc_geometry_variable_groups, nc_clear_variable_groups and nc_set_geometry_variable_groups methods.

Some components exist within multiple constructs, but when written to a netCDF dataset the netCDF names associated with such components will be arbitrarily taken from one of them. The netCDF variable, dimension and sample dimension names and group structures for such components may be set or removed consistently across all such components with the nc_del_component_variable, nc_set_component_variable, nc_set_component_variable_groups, nc_clear_component_variable_groups, nc_del_component_dimension, nc_set_component_dimension, nc_set_component_dimension_groups, nc_clear_component_dimension_groups, nc_del_component_sample_dimension, nc_set_component_sample_dimension, nc_set_component_sample_dimension_groups, nc_clear_component_sample_dimension_groups methods.

CF-compliance issues for field constructs read from a netCDF dataset may be accessed with the dataset_compliance method.

Initialization

Parameters
properties: dict, optional

Set descriptive properties. The dictionary keys are property names, with corresponding values. Ignored if the source parameter is set.

Parameter example:

properties={'standard_name': 'air_temperature'}

Properties may also be set after initialisation with the set_properties and set_property methods.

source: optional

Initialize the properties, data and metadata constructs from those of source.

copy: bool, optional

If False then do not deep copy input parameters prior to initialization. By default arguments are deep copied.

Inspection

Methods

dump

A full description of the field construct.

identity

Return the canonical identity.

identities

Return all possible identities.

inspect

Inspect the object for debugging.

Attributes

construct_type

Return a description of the construct type.

id

An identity for the Field object.

Selection

Methods

match_by_identity

Whether or not the construct identity satisfies conditions.

match_by_naxes

Whether or not the data has a given dimensionality.

match_by_ncvar

Whether or not the netCDF variable name satisfies conditions.

match_by_property

Whether or not properties satisfy conditions.

match_by_rank

Whether or not the number of domain axis constructs satisfies conditions.

match_by_units

Whether or not the construct has given units.

match_by_construct

Whether or not there are particular metadata constructs.

Properties

Methods

del_property

Remove a property.

get_property

Get a CF property.

has_property

Whether a property has been set.

set_property

Set a property.

properties

Return all properties.

clear_properties

Remove all properties.

set_properties

Set properties.

Attributes

add_offset

The add_offset CF property.

calendar

The calendar CF property.

cell_methods

Return cell method constructs.

comment

The comment CF property.

Conventions

The Conventions CF property.

DSG

True if the field contains a collection of discrete sampling geometries.

_FillValue

The _FillValue CF property.

featureType

The featureType CF property.

flag_masks

The flag_masks CF property.

flag_meanings

The flag_meanings CF property.

flag_values

The flag_values CF property.

history

The history CF property.

institution

The institution CF property.

leap_month

The leap_month CF property.

leap_year

The leap_year CF property.

long_name

The long_name CF property.

missing_value

The missing_value CF property.

month_lengths

The month_lengths CF property.

references

The references CF property.

scale_factor

The scale_factor CF property.

source

The source CF property.

standard_error_multiplier

The standard_error_multiplier CF property.

standard_name

The standard_name CF property.

title

The title CF property.

units

The units CF property.

valid_max

The valid_max CF property.

valid_min

The valid_min CF property.

valid_range

The valid_range CF property.

Units

override_units

Override the units.

override_calendar

Override the calendar of date-time units.

Units

The cf.Units object containing the units of the data array.

Data

Methods

del_data

Remove the data.

get_data

Return the data.

has_data

Whether a data has been set.

set_data

Set the field construct data.

del_data_axes

Remove the keys of the domain axis constructs spanned by the data of the field or of a metadata construct.

get_data_axes

Return the keys of the domain axis constructs spanned by the data of a metadata construct.

has_data_axes

Whether the domain axis constructs spanned by the data of the field or of a metadata construct have been set.

set_data_axes

Set the domain axis constructs spanned by the data of the field or of a metadata construct.

Attributes

array

A numpy array deep copy of the data array.

data

The Data object containing the data array.

datetime_array

An independent numpy array of date-time objects.

datum

Return an element of the data array as a standard Python scalar.

dtype

The numpy data type of the data array.

ndim

The number of dimensions in the data array.

shape

A tuple of the data array’s dimension sizes.

size

The number of elements in the data array.

varray

A numpy array view of the data array.

Rearranging elements

anchor

Roll a cyclic axis so that the given value lies in the first coordinate cell.

flatten

Flatten axes of the field.

flip

Flip (reverse the direction of) axes of the field.

insert_dimension

Insert a size 1 axis into the data array.

roll

Roll the field along a cyclic axis.

squeeze

Remove size 1 axes from the data.

swapaxes

Interchange two axes of the data.

transpose

Permute the axes of the data array.

unsqueeze

Insert size 1 axes into the data array.

Expanding the data

halo

Expand the field construct by adding a halo to its data.

Data array mask

apply_masking

Apply masking as defined by the CF conventions.

count

Count the non-masked elements of the data.

count_masked

Count the masked elements of the data.

fill_value

Return the data array missing data value.

binary_mask

A binary (0 and 1) missing data mask of the data array.

hardmask

Whether the mask is hard (True) or soft (False).

mask

The mask of the data array.

mask_invalid

Mask the array where invalid values occur.

Changing data values

__setitem__

Called to implement assignment to x[indices]=value

subspace

Create a subspace of the field construct.

indices

Create indices that define a subspace of the field construct.

where

Assign to data elements depending on a condition.

apply_masking

Apply masking as defined by the CF conventions.

mask_invalid

Mask the array where invalid values occur.

Miscellaneous data operations

Methods

cyclic

Set the cyclicity of an axis.

period

Return or set the period of the data.

get_filenames

Return the name of the file or files containing the data.

close

Close all files referenced by the field construct.

chunk

Partition the data array.

Metadata constructs

Methods

construct

Select a metadata construct by its identity.

construct_key

Select the key of a metadata construct by its identity.

del_construct

Remove a metadata construct.

get_construct

Return a metadata construct.

has_construct

Whether a metadata construct exists.

set_construct

Set a metadata construct.

replace_construct

Replace a metadata construct.

del_data_axes

Remove the keys of the domain axis constructs spanned by the data of the field or of a metadata construct.

get_data_axes

Return the keys of the domain axis constructs spanned by the data of a metadata construct.

has_data_axes

Whether the domain axis constructs spanned by the data of the field or of a metadata construct have been set.

set_data_axes

Set the domain axis constructs spanned by the data of the field or of a metadata construct.

auxiliary_coordinate

Return an auxiliary coordinate construct, or its key.

cell_measure

Select a cell measure construct by its identity.

cell_method

Select a cell method construct by its identity.

coordinate

Return a dimension coordinate construct, or its key.

coordinate_reference

Return a coordinate reference construct, or its key.

coordinate_reference_domain_axes

Return the domain axes that apply to a coordinate reference construct.

get_coordinate_reference

TODO

set_coordinate_reference

Set a coordinate reference construct.

del_coordinate_reference

Remove a coordinate reference construct and all of its domain ancillary constructs.

dimension_coordinate

Return a dimension coordinate construct, or its key.

domain_ancillary

Return a domain ancillary construct, or its key.

domain_axis

Return a domain axis construct, or its key.

domain_axis_key

Return the key of the domain axis construct that is spanned by 1-d coordinate constructs.

domain_axis_position

Return the position in the data of a domain axis construct.

domain_mask

Return a boolean field that is True where criteria are met.

del_domain_axis

Remove a domain axis construct.

field_ancillary

Return a field ancillary construct, or its key.

map_axes

Map the axis identifiers of the field to their equivalent axis identifiers of another.

climatological_time_axes

Return all axes which are climatological time axes.

Attributes

constructs

Return the metadata constructs.

auxiliary_coordinates

Return auxiliary coordinate constructs.

cell_measures

Return cell measure constructs.

cell_methods

Return cell method constructs.

coordinates

Return dimension and auxiliary coordinate constructs.

coordinate_references

Return coordinate reference constructs.

dimension_coordinates

Return dimension coordinate constructs.

domain_ancillaries

Return domain ancillary constructs.

domain_axes

Return domain axis constructs.

axes

Return domain axis constructs.

field_ancillaries

Return field ancillary constructs.

reference_datetime

The reference date-time of units of elapsed time.

Domain

Methods

get_domain

Return the domain.

Attributes

domain

Return the domain.

Miscellaneous

Methods

copy

Return a deep copy of the field construct.

compute_vertical_coordinates

Compute non-parametric vertical coordinates.

dataset_compliance

A report of problems encountered whilst reading the field construct from a dataset.

equals

Whether two instances are the same.

compress

Compress the field construct.

convert

Convert a metadata construct into a new field construct.

creation_commands

Return the commands that would create the field construct.

radius

Return the radius used for calculating cell areas in spherical polar coordinates.

uncompress

Uncompress the field construct.

concatenate

Join a sequence of fields together.

section

Return a FieldList of m dimensional sections of a Field of n dimensions, where M <= N.

Attributes

Flags

A Flags object containing self-describing CF flag values.

has_bounds

Whether or not there are cell bounds.

has_geometry

Whether or not any coordinate constructs have cell geometries.

rank

The number of axes in the domain.

T

True if and only if the data are coordinates for a CF ‘T’ axis.

X

Always False.

Y

Always False.

Z

Always False.

NetCDF

Methods

nc_del_variable

Remove the netCDF variable name.

nc_get_variable

Return the netCDF variable name.

nc_has_variable

Whether the netCDF variable name has been set.

nc_set_variable

Set the netCDF variable name.

nc_global_attributes

Return the selection of properties to be written as netCDF global attributes.

nc_clear_global_attributes

Remove the selection of properties to be written as netCDF global attributes.

nc_set_global_attribute

Select a property to be written as a netCDF global attribute.

nc_set_global_attributes

Set properties to be written as netCDF global attributes.

ncdimensions

Groups

Methods

nc_variable_groups

Return the netCDF variable group hierarchy.

nc_set_variable_groups

Set the netCDF variable group hierarchy.

nc_clear_variable_groups

Remove the netCDF variable group hierarchy.

nc_group_attributes

Return the selection of properties to be written as netCDF group attributes.

nc_clear_group_attributes

Remove the selection of properties to be written as netCDF group attributes.

nc_set_group_attribute

Select a property to be written as a netCDF group attribute.

nc_set_group_attributes

Set properties to be written as netCDF group attributes.

Geometries

Methods

nc_del_geometry_variable

Remove the netCDF geometry container variable name.

nc_get_geometry_variable

Return the netCDF geometry container variable name.

nc_has_geometry_variable

Whether the netCDF geometry container variable name has been set.

nc_set_geometry_variable

Set the netCDF geometry container variable name.

nc_geometry_variable_groups

Return the netCDF geometry variable group hierarchy.

nc_set_geometry_variable_groups

Set the netCDF geometry variable group hierarchy.

nc_clear_geometry_variable_groups

Remove the netCDF geometry variable group hierarchy.

Components

Methods

nc_del_component_variable

Remove the netCDF variable name for all components of the given type.

nc_set_component_variable

Set the netCDF variable name for all components of the given type.

nc_set_component_variable_groups

Set the netCDF variable groups hierarchy for all components of the given type.

nc_clear_component_variable_groups

Remove the netCDF variable groups hierarchy for all components of the given type.

nc_del_component_dimension

Remove the netCDF dimension name for all components of the given type.

nc_set_component_dimension

Set the netCDF dimension name for all components of the given type.

nc_set_component_dimension_groups

Set the netCDF dimension groups hierarchy for all components of the given type.

nc_clear_component_dimension_groups

Remove the netCDF dimension groups hierarchy for all components of the given type.

nc_del_component_sample_dimension

Remove the netCDF sample dimension name for all components of the given type.

nc_set_component_sample_dimension

Set the netCDF sample dimension name for all components of the given type.

nc_set_component_sample_dimension_groups

Set the netCDF sample dimension groups hierarchy for all components of the given type.

nc_clear_component_sample_dimension_groups

Remove the netCDF sample dimension groups hierarchy for all components of the given type.

Domain axes

analyse_items

Analyse a domain.

autocyclic

Set dimensions to be cyclic.

axes

Return domain axis constructs.

axes_names

Return canonical identities for each domain axis construct.

cf.Field.axes_sizes

axis

Alias of cf.Field.domain_axis.

axis_name

Return the canonical name for an axis.

axis_size

Return the size of a domain axis construct.

cyclic

Set the cyclicity of an axis.

data_axes

Return the domain axes for the data array dimensions.

direction

Whether or not a domain axis is increasing.

directions

Return a dictionary mapping all domain axes to their directions.

iscyclic

Returns True if the given axis is cyclic.

isperiodic

TODO

item_axes

Return the axes of a domain item of the field.

items_axes

Return the axes of items of the field.

Subspacing

__getitem__

Return a subspace of the field construct defined by indices.

subspace

Create a subspace of the field construct.

indices

Create indices that define a subspace of the field construct.

Mathematical operations

Trigonometrical and hyperbolic functions

arccos

Take the trigonometric inverse cosine of the data element-wise.

arccosh

Take the inverse hyperbolic cosine of the data element-wise.

arcsin

Take the trigonometric inverse sine of the data element-wise.

arcsinh

Take the inverse hyperbolic sine of the data element-wise.

arctan

Take the trigonometric inverse tangent of the data element-wise.

arctanh

Take the inverse hyperbolic tangent of the data element-wise.

cos

Take the trigonometric cosine of the data element-wise.

cosh

Take the hyperbolic cosine of the data element-wise.

sin

Take the trigonometric sine of the data element-wise.

sinh

Take the hyperbolic sine of the data element-wise.

tan

Take the trigonometric tangent of the data element-wise.

tanh

Take the hyperbolic tangent of the data array.

Rounding and truncation

ceil

The ceiling of the data, element-wise.

clip

Limit the values in the data.

floor

Floor the data array, element-wise.

rint

Round the data to the nearest integer, element-wise.

round

Round the data to the given number of decimals.

trunc

Truncate the data, element-wise.

Statistical collapses

collapse

Collapse axes of the field.

moving_window

Perform moving window calculations along an axis.

cell_area

Return a field containing horizontal cell areas.

max

Alias for maximum.

mean

The unweighted mean the data array.

mid_range

The unweighted average of the maximum and minimum of the data array.

min

Alias for minimum.

range

The absolute difference between the maximum and minimum of the data array.

sample_size

The number of non-missing data elements in the data array.

sum

The sum of the data array.

sd

Alias for standard_deviation

var

Alias for variance

weights

Return weights for the data array values.

standard_deviation

The unweighted sample standard deviation of the data array.

variance

The unweighted sample variance of the data array.

maximum

The maximum of the data array.

minimum

The minimum of the data array.

Exponential and logarithmic functions

exp

The exponential of the data, element-wise.

log

The logarithm of the data array.

Derivatives

derivative

Return the derivative along the specified axis.

Convolution filters

convolution_filter

Convolve the field construct along the given axis with the specified filter.

moving_window

Perform moving window calculations along an axis.

Cumulative sums

cumsum

Return the field cumulatively summed along the given axis.

Binning operations

bin

Collapse the data values that lie in N-dimensional bins.

digitize

Return the indices of the bins to which each value belongs.

histogram

Return a multi-dimensional histogram of the data.

percentile

Compute percentiles of the data along the specified axes.

Data array operations

Adding and removing elements

unique

The unique elements of the data.

Miscellaneous data array operations

argmax

Return the indices of the maximum values along an axis.

chunk

Partition the data array.

isscalar

True if the data array is scalar.

Regridding operations

regridc

Return the field with the specified Cartesian axes regridded onto a new grid.

regrids

Return the field regridded onto a new latitude-longitude grid.

Date-time operations

day

The day of each date-time data array element.

datetime_array

An independent numpy array of date-time objects.

hour

The hour of each date-time data array element.

minute

The minute of each date-time data array element.

month

The month of each date-time data array element.

second

The second of each date-time data array element.

year

The year of each date-time data array element.

convert_reference_time

Convert reference time data values to have new units.

Logic functions

Truth value testing

all

Test whether all data elements evaluate to True.

any

Test whether any data elements evaluate to True.

Comparison

allclose

Test whether all data are element-wise equal to other, broadcastable data.

equals

Whether two instances are the same.

equivalent

True if two fields are equivalent, False otherwise.

cf.Field.equivalent_data

cf.Field.equivalent_domain

Set operations

unique

The unique elements of the data.

Arithmetic and comparison operations

Arithmetic, bitwise and comparison operations are defined on a field construct as element-wise operations on its data which yield a new field construct or, for augmented assignments, modify the field construct’s data in-place.

Relational operators

__lt__

The rich comparison operator <

__le__

The rich comparison operator <=

__eq__

The rich comparison operator ==

__ne__

The rich comparison operator !=

__gt__

The rich comparison operator >

__ge__

The rich comparison operator >=

Binary arithmetic operators

__add__

The binary arithmetic operation +

__sub__

The binary arithmetic operation -

__mul__

The binary arithmetic operation *

__div__

The binary arithmetic operation /

__truediv__

The binary arithmetic operation / (true division)

__floordiv__

The binary arithmetic operation //

__pow__

The binary arithmetic operations ** and pow

__mod__

The binary arithmetic operation %

Binary arithmetic operators with reflected (swapped) operands

__radd__

The binary arithmetic operation + with reflected operands

__rsub__

The binary arithmetic operation - with reflected operands

__rmul__

The binary arithmetic operation * with reflected operands

__rdiv__

The binary arithmetic operation / with reflected operands

__rtruediv__

The binary arithmetic operation / (true division) with reflected operands

__rfloordiv__

The binary arithmetic operation // with reflected operands

__rpow__

The binary arithmetic operations ** and pow with reflected operands

__rmod__

The binary arithmetic operation % with reflected operands

Augmented arithmetic assignments

__iadd__

The augmented arithmetic assignment +=

__isub__

The augmented arithmetic assignment -=

__imul__

The augmented arithmetic assignment *=

__idiv__

The augmented arithmetic assignment /=

__itruediv__

The augmented arithmetic assignment /= (true division)

__ifloordiv__

The augmented arithmetic assignment //=

__ipow__

The augmented arithmetic assignment **=

__imod__

The binary arithmetic operation %=

Unary arithmetic operators

__neg__

The unary arithmetic operation -

__pos__

The unary arithmetic operation +

__abs__

The unary arithmetic operation abs

Binary bitwise operators

__and__

The binary bitwise operation &

__or__

The binary bitwise operation |

__xor__

The binary bitwise operation ^

__lshift__

The binary bitwise operation <<

__rshift__

The binary bitwise operation >>

Binary bitwise operators with reflected (swapped) operands

__rand__

The binary bitwise operation & with reflected operands

__ror__

The binary bitwise operation | with reflected operands

__rxor__

The binary bitwise operation ^ with reflected operands

__rlshift__

The binary bitwise operation << with reflected operands

__rrshift__

The binary bitwise operation >> with reflected operands

Augmented bitwise assignments

__iand__

The augmented bitwise assignment &=

__ior__

The augmented bitwise assignment |=

__ixor__

The augmented bitwise assignment ^=

__ilshift__

The augmented bitwise assignment <<=

__irshift__

The augmented bitwise assignment >>=

Unary bitwise operators

__invert__

The unary bitwise operation ~

Groups

Methods

nc_variable_groups

Return the netCDF variable group hierarchy.

nc_set_variable_groups

Set the netCDF variable group hierarchy.

nc_clear_variable_groups

Remove the netCDF variable group hierarchy.

nc_group_attributes

Return the selection of properties to be written as netCDF group attributes.

nc_set_group_attribute

Select a property to be written as a netCDF group attribute.

nc_set_group_attributes

Set properties to be written as netCDF group attributes.

nc_clear_group_attributes

Remove the selection of properties to be written as netCDF group attributes.

nc_geometry_variable_groups

Return the netCDF geometry variable group hierarchy.

nc_set_geometry_variable_groups

Set the netCDF geometry variable group hierarchy.

nc_clear_geometry_variable_groups

Remove the netCDF geometry variable group hierarchy.

Special

Methods

__deepcopy__

Called by the copy.deepcopy function.

__getitem__

Return a subspace of the field construct defined by indices.

__repr__

Called by the repr built-in function.

__str__

Called by the str built-in function.

Deprecated

Methods

asdatetime

Deprecated at version 3.0.0.

asreftime

Deprecated at version 3.0.0.

axis_name

Return the canonical name for an axis.

data_axes

Return the domain axes for the data array dimensions.

delprop

Deprecated at version 3.0.0, use method del_property instead.

equivalent

True if two fields are equivalent, False otherwise.

example_field

Return an example field construct.

expand_dims

Insert a size 1 axis into the data array.

field

Create an independent field from a domain item.

getprop

Deprecated at version 3.0.0, use method get_property instead.

HDF_chunks

Deprecated at version 3.0.0.

hasprop

Deprecated at version 3.0.0, use method has_property instead.

insert_aux

Insert an auxiliary coordinate object into the field.

insert_axis

Insert a domain axis into the field.

insert_cell_methods

Insert one or more cell method objects into the field.

insert_data

Insert a data array into the field.

insert_domain_anc

Insert a domain ancillary object into the field.

insert_field_anc

Insert a field ancillary object into the field.

insert_item

Insert an item into the field.

insert_measure

Insert a cell measure object into the field.

insert_ref

Insert a coordinate reference object into the field.

isauxiliary

Deprecated at version 3.7.0, use construct_type attribute instead.

isdimension

Deprecated at version 3.7.0, use construct_type attribute instead.

isdomainancillary

Deprecated at version 3.7.0, use construct_type attribute instead.

isfieldancillary

Deprecated at version 3.7.0, use construct_type attribute instead.

ismeasure

Deprecated at version 3.7.0, use construct_type attribute instead.

item_axes

Return the axes of a domain item of the field.

key_item

Return an item, or its identifier, from the field.

name

Deprecated at version 3.0.0, use method ‘identity’ instead.

new_identifier

Return a new, unused construct key.

remove_axes

Remove and return axes from the field.

remove_axis

Remove and return a unique axis from the field.

remove_data

Remove and return the data array.

remove_item

Remove and return an item from the field.

remove_items

Remove and return items from the field.

select

Deprecated at version 3.0.0.

setprop

Deprecated at version 3.0.0, use method set_property instead.

transpose_item

Permute the axes of a field item data array.

unlimited

Deprecated at version 3.0.0.

Attributes

attributes

Deprecated at version 3.0.0.

_Axes

CellMethods

CM

Deprecated at version 3.0.0

Data

The Data object containing the data array.

dtvarray

Deprecated at version 3.0.0.

hasbounds

Deprecated at version 3.0.0, use has_bounds method instead.

hasdata

Deprecated at version 3.0.0, use has_data method instead.

Items

Deprecated at version 3.0.0.

unsafe_array

Deprecated at version 3.0.0, use array attribute instead.