Skip to content

Facet map

FacetMapExtract

Bases: ExtractionMethod

In some cases, you may wish to map the header attributes to different facets. This method takes a map and converts the facet labels into those specified.

Method name: facet_map

Example Configuration

.. code-block:: yaml

- method: facet_map
  inputs:
    term_map:
        old_key: new_key
        time_coverage_start: start_time
Source code in extraction_methods/plugins/facet_map.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
class FacetMapExtract(ExtractionMethod):
    """
    In some cases, you may wish to map the header attributes to different
    facets. This method takes a map and converts the facet labels into those
    specified.

    **Method name:** ``facet_map``

    Example Configuration:
        .. code-block:: yaml

            - method: facet_map
              inputs:
                term_map:
                    old_key: new_key
                    time_coverage_start: start_time
    """

    input_class = FacetMapInput

    @update_input
    def run(self, body: dict[str, Any]) -> dict[str, Any]:

        for old_key, new_key in self.input.term_map:
            try:
                value = body.pop(old_key)
                body[new_key] = value

            except KeyError:
                pass

        return body

FacetMapInput

Bases: Input

Model for Facet Map Input.

Parameters:

Name Type Description Default
term_map dict[str, str]

Dictionary of terms to be mapped.

{}
Source code in extraction_methods/plugins/facet_map.py
23
24
25
26
27
28
29
30
31
class FacetMapInput(Input):
    """
    Model for Facet Map Input.
    """

    term_map: dict[str, str] = Field(
        default={},
        description="Dictionary of terms to be mapped.",
    )