cfdm.unique_constructs¶
-
cfdm.
unique_constructs
(constructs, ignore_properties=None, 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.
- ignore_properties: (sequence of)
str
, optional The names of construct properties to be ignored when testing for uniqueness. Any of these properties which have unequal values on otherwise equal input constructs are removed from the returned unique construct.
New in version (cfdm): 1.10.0.3
- copy:
bool
, optional If True (the default) then each returned construct is a deep copy of an input construct, otherwise they are not copies.
If ignore_properties has been set then copy is ignored and deep copies are always returned, even if ignore_properties is an empty sequence.
- Returns
- Sequence of constructs
The unique constructs in a sequence of the same type as the input constructs. If constructs was a generator then a generator is returned.
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>]