cfdm.Domain.creation_commands

Domain.creation_commands(representative_data=False, namespace=None, indent=0, string=True, name='domain', data_name='data', header=True, _domain=True)[source]

Return the commands that would create the domain construct.

Construct keys

The key parameter of the output set_construct commands is utilised in order minimise the number of commands needed to implement cross-referencing between constructs (e.g. between a coordinate reference construct and coordinate constructs). This is usually not necessary when building domain constructs, as by default the set_construct method returns a unique construct key for the construct being set.

New in version (cfdm): 1.9.0.0

Parameters
representative_data: bool, optional

Return one-line representations of Data instances, which are not executable code but prevent the data being converted in its entirety to a string representation.

namespace: str, optional

The name space containing classes of the cfdm package. This is prefixed to the class name in commands that instantiate instances of cfdm objects. By default, or if None, the name space is assumed to be consistent with cfdm being imported as import cfdm.

Parameter example:

If cfdm was imported as import cfdm as xyz then set namespace='xyz'

Parameter example:

If cfdm was imported as from cfdm import * then set namespace=''

indent: int, optional

Indent each line by this many spaces. By default no indentation is applied. Ignored if string is False.

string: bool, optional

If False then return each command as an element of a list. By default the commands are concatenated into a string, with a new line inserted between each command.

header: bool, optional

If True (the default) output a comment describing the components. If False no such comment is returned.

Returns
str or list

The commands in a string, with a new line inserted between each command. If string is False then the separate commands are returned as each element of a list.

Examples

>>> f = cfdm.example_domain(0)
>>> print(d.creation_commands())
#
# domain:
domain = cfdm.Domain()
#
# domain_axis: ncdim%lat
c = cfdm.DomainAxis()
c.set_size(5)
c.nc_set_dimension('lat')
domain.set_construct(c, key='domainaxis0', copy=False)
#
# domain_axis: ncdim%lon
c = cfdm.DomainAxis()
c.set_size(8)
c.nc_set_dimension('lon')
domain.set_construct(c, key='domainaxis1', copy=False)
#
# domain_axis:
c = cfdm.DomainAxis()
c.set_size(1)
domain.set_construct(c, key='domainaxis2', copy=False)
#
# dimension_coordinate: latitude
c = cfdm.DimensionCoordinate()
c.set_properties({'units': 'degrees_north', 'standard_name': 'latitude'})
c.nc_set_variable('lat')
data = cfdm.Data([-75.0, -45.0, 0.0, 45.0, 75.0], units='degrees_north', dtype='f8')
c.set_data(data)
b = cfdm.Bounds()
b.nc_set_variable('lat_bnds')
data = cfdm.Data([[-90.0, -60.0], [-60.0, -30.0], [-30.0, 30.0], [30.0, 60.0], [60.0, 90.0]], units='degrees_north', dtype='f8')
b.set_data(data)
c.set_bounds(b)
domain.set_construct(c, axes=('domainaxis0',), key='dimensioncoordinate0', copy=False)
#
# dimension_coordinate: longitude
c = cfdm.DimensionCoordinate()
c.set_properties({'units': 'degrees_east', 'standard_name': 'longitude'})
c.nc_set_variable('lon')
data = cfdm.Data([22.5, 67.5, 112.5, 157.5, 202.5, 247.5, 292.5, 337.5], units='degrees_east', dtype='f8')
c.set_data(data)
b = cfdm.Bounds()
b.nc_set_variable('lon_bnds')
data = cfdm.Data([[0.0, 45.0], [45.0, 90.0], [90.0, 135.0], [135.0, 180.0], [180.0, 225.0], [225.0, 270.0], [270.0, 315.0], [315.0, 360.0]], units='degrees_east', dtype='f8')
b.set_data(data)
c.set_bounds(b)
domain.set_construct(c, axes=('domainaxis1',), key='dimensioncoordinate1', copy=False)
#
# dimension_coordinate: time
c = cfdm.DimensionCoordinate()
c.set_properties({'units': 'days since 2018-12-01', 'standard_name': 'time'})
c.nc_set_variable('time')
data = cfdm.Data([31.0], units='days since 2018-12-01', dtype='f8')
c.set_data(data)
domain.set_construct(c, axes=('domainaxis2',), key='dimensioncoordinate2', copy=False)
>>> print(d.creation_commands(representative_data=True, namespace='',
...                           indent=4, header=False))
    domain = Domain()
    c = DomainAxis()
    c.set_size(5)
    c.nc_set_dimension('lat')
    domain.set_construct(c, key='domainaxis0', copy=False)
    c = DomainAxis()
    c.set_size(8)
    c.nc_set_dimension('lon')
    domain.set_construct(c, key='domainaxis1', copy=False)
    c = DomainAxis()
    c.set_size(1)
    domain.set_construct(c, key='domainaxis2', copy=False)
    c = DimensionCoordinate()
    c.set_properties({'units': 'degrees_north', 'standard_name': 'latitude'})
    c.nc_set_variable('lat')
    data = <Data(5): [-75.0, ..., 75.0] degrees_north>  # Representative data
    c.set_data(data)
    b = Bounds()
    b.nc_set_variable('lat_bnds')
    data = <Data(5, 2): [[-90.0, ..., 90.0]] degrees_north>  # Representative data
    b.set_data(data)
    c.set_bounds(b)
    domain.set_construct(c, axes=('domainaxis0',), key='dimensioncoordinate0', copy=False)
    c = DimensionCoordinate()
    c.set_properties({'units': 'degrees_east', 'standard_name': 'longitude'})
    c.nc_set_variable('lon')
    data = <Data(8): [22.5, ..., 337.5] degrees_east>  # Representative data
    c.set_data(data)
    b = Bounds()
    b.nc_set_variable('lon_bnds')
    data = <Data(8, 2): [[0.0, ..., 360.0]] degrees_east>  # Representative data
    b.set_data(data)
    c.set_bounds(b)
    domain.set_construct(c, axes=('domainaxis1',), key='dimensioncoordinate1', copy=False)
    c = DimensionCoordinate()
    c.set_properties({'units': 'days since 2018-12-01', 'standard_name': 'time'})
    c.nc_set_variable('time')
    data = <Data(1): [2019-01-01 00:00:00]>  # Representative data
    c.set_data(data)
    domain.set_construct(c, axes=('domainaxis2',), key='dimensioncoordinate2', copy=False)