cf.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_constructcommands 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 theset_constructmethod 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
Datainstances, 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 cf package. This is prefixed to the class name in commands that instantiate instances of cf objects. By default, or if
None, the name space is assumed to be consistent with cf being imported asimport cf.- Parameter example:
If cf was imported as
import cf as xyzthen setnamespace='xyz'- Parameter example:
If cf was imported as
from cf import *then setnamespace=''
- 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.
- representative_data:
- Returns
Examples
>>> f = cf.example_domain(0) >>> print(d.creation_commands()) # # domain: domain = cf.Domain() # # domain_axis: ncdim%lat c = cf.DomainAxis() c.set_size(5) c.nc_set_dimension('lat') domain.set_construct(c, key='domainaxis0', copy=False) # # domain_axis: ncdim%lon c = cf.DomainAxis() c.set_size(8) c.nc_set_dimension('lon') domain.set_construct(c, key='domainaxis1', copy=False) # # domain_axis: c = cf.DomainAxis() c.set_size(1) domain.set_construct(c, key='domainaxis2', copy=False) # # dimension_coordinate: latitude c = cf.DimensionCoordinate() c.set_properties({'units': 'degrees_north', 'standard_name': 'latitude'}) c.nc_set_variable('lat') data = cf.Data([-75.0, -45.0, 0.0, 45.0, 75.0], units='degrees_north', dtype='f8') c.set_data(data) b = cf.Bounds() b.nc_set_variable('lat_bnds') data = cf.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 = cf.DimensionCoordinate() c.set_properties({'units': 'degrees_east', 'standard_name': 'longitude'}) c.nc_set_variable('lon') data = cf.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 = cf.Bounds() b.nc_set_variable('lon_bnds') data = cf.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 = cf.DimensionCoordinate() c.set_properties({'units': 'days since 2018-12-01', 'standard_name': 'time'}) c.nc_set_variable('time') data = cf.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 = <CF Data(5): [-75.0, ..., 75.0] degrees_north> # Representative data c.set_data(data) b = Bounds() b.nc_set_variable('lat_bnds') data = <CF 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 = <CF Data(8): [22.5, ..., 337.5] degrees_east> # Representative data c.set_data(data) b = Bounds() b.nc_set_variable('lon_bnds') data = <CF 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 = <CF Data(1): [2019-01-01 00:00:00]> # Representative data c.set_data(data) domain.set_construct(c, axes=('domainaxis2',), key='dimensioncoordinate2', copy=False)