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