cfdm.unique_constructs

cfdm.unique_constructs(constructs, copy=True)[source]

Return the unique constructs from a sequence.

New in version (cfdm): 1.9.0.0

Parameters
constructs: sequence of constructs

The constructs to be compared. The constructs may comprise a mixture of types. The sequence can be empty.

copy: bool, optional

If False then do not copy returned constructs. By default they are deep copies.

Returns
list

The unique constructs. May be an empty list.

Examples:

>>> f = cfdm.example_field(0)
>>> g = cfdm.example_field(1)
>>> f
<Field: specific_humidity(latitude(5), longitude(8)) 1>
>>> g
<Field: air_temperature(atmosphere_hybrid_height_coordinate(1), grid_latitude(10), grid_longitude(9)) K>
>>> fields = [f, f, g]
>>> cfdm.unique_constructs(fields)
[<Field: specific_humidity(latitude(5), longitude(8)) 1>,
 <Field: air_temperature(atmosphere_hybrid_height_coordinate(1), grid_latitude(10), grid_longitude(9)) K>]
>>> domains = [x.domain for x in fields]
>>> cfdm.unique_constructs(domains)
[<Domain: {latitude(5), longitude(8), time(1)}>,
 <Domain: {atmosphere_hybrid_height_coordinate(1), grid_latitude(10), grid_longitude(9), time(1)}>]
>>> cfdm.unique_constructs(domains + fields + [f.domain])
[<Domain: {latitude(5), longitude(8), time(1)}>,
 <Domain: {atmosphere_hybrid_height_coordinate(1), grid_latitude(10), grid_longitude(9), time(1)}>,
 <Field: specific_humidity(latitude(5), longitude(8)) 1>,
 <Field: air_temperature(atmosphere_hybrid_height_coordinate(1), grid_latitude(10), grid_longitude(9)) K>]
>>> cfdm.unique_constructs(x for x in fields)
[<Field: specific_humidity(latitude(5), longitude(8)) 1>,
 <Field: air_temperature(atmosphere_hybrid_height_coordinate(1), grid_latitude(10), grid_longitude(9)) K>]