cfdm.Constructs.inverse_filter

Constructs.inverse_filter(depth=None)[source]

Return the inverse of previous filters.

By default, the inverse comprises all of the constructs that were not selected by all previously applied filters. If no filters have been applied, then this will result in empty Constructs instance being returned.

If the depth parameter is set to N then the inverse is relative to the constructs selected by the N-th most recently applied filter.

A history of the filters that have been applied is returned in a tuple by the filters_applied method. The last element of the tuple describes the last filter applied. If no filters have been applied then the tuple is empty.

New in version (cfdm): 1.7.0

Parameters
depth: int, optional

If set to N then the inverse is relative to the constructs selected by the N-th most recently applied filter. By default the inverse is relative to the constructs selected by all previously applied filters. N may be larger than the total number of filters applied, which results in the default behaviour.

Returns
Constructs

The constructs, and their construct keys, that were not selected by the last filter applied. If no filtering has been applied, or the last filter was an inverse filter, then an empty Constructs instance is returned.

Examples

>>> print(c)
Constructs:
{'cellmethod0': <CellMethod: area: mean>,
 'dimensioncoordinate0': <DimensionCoordinate: latitude(5) degrees_north>,
 'dimensioncoordinate1': <DimensionCoordinate: longitude(8) degrees_east>,
 'dimensioncoordinate2': <DimensionCoordinate: time(1) days since 2018-12-01 >,
 'domainaxis0': <DomainAxis: size(5)>,
 'domainaxis1': <DomainAxis: size(8)>,
 'domainaxis2': <DomainAxis: size(1)>}
>>> print(c.inverse_filter())
Constructs:
{}
>>> d = c.filter_by_type('dimension_coordinate', 'cell_method')
>>> print(d)
Constructs:
{'cellmethod0': <CellMethod: area: mean>,
 'dimensioncoordinate0': <DimensionCoordinate: latitude(5) degrees_north>,
 'dimensioncoordinate1': <DimensionCoordinate: longitude(8) degrees_east>,
 'dimensioncoordinate2': <DimensionCoordinate: time(1) days since 2018-12-01 >}
>>> print(d.inverse_filter())
Constructs:
{'domainaxis0': <DomainAxis: size(5)>,
 'domainaxis1': <DomainAxis: size(8)>,
 'domainaxis2': <DomainAxis: size(1)>}
>>> e = d.filter_by_method('mean')
>>> print(e)
Constructs:
{'cellmethod0': <CellMethod: area: mean>}
>>> print(e.inverse_filter(1))
Constructs:
{'dimensioncoordinate0': <DimensionCoordinate: latitude(5) degrees_north>,
 'dimensioncoordinate1': <DimensionCoordinate: longitude(8) degrees_east>,
 'dimensioncoordinate2': <DimensionCoordinate: time(1) days since 2018-12-01 >}
>>> print(e.inverse_filter())
Constructs:
{'dimensioncoordinate0': <DimensionCoordinate: latitude(5) degrees_north>,
 'dimensioncoordinate1': <DimensionCoordinate: longitude(8) degrees_east>,
 'dimensioncoordinate2': <DimensionCoordinate: time(1) days since 2018-12-01 >,
 'domainaxis0': <DomainAxis: size(5)>,
 'domainaxis1': <DomainAxis: size(8)>,
 'domainaxis2': <DomainAxis: size(1)>}
>>> print(e.inverse_filter(1).inverse_filter())
Constructs:
{'cellmethod0': <CellMethod: area: mean>,
 'domainaxis0': <DomainAxis: size(5)>,
 'domainaxis1': <DomainAxis: size(8)>,
 'domainaxis2': <DomainAxis: size(1)>}