Skip to content

Xarray

XarrayHeader

Bases: ExtractionMethod

Xarray backend for header method.

Method name: xarray

Example configuration

.. code-block:: yaml

  • method: xarray inputs: input_term: hello_world
Source code in extraction_methods/plugins/header/backends/xarray.py
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
66
67
class XarrayHeader(ExtractionMethod):
    """
    Xarray backend for header method.

    **Method name:** ``xarray``

    Example configuration:
        .. code-block:: yaml

        - method: xarray
          inputs:
            input_term: hello_world
    """

    input_class = XarrayHeaderInput

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

        ds = xr.open_dataset(self.input.input_term, **self.input.dataset_kwargs)

        for attribute in self.input.attributes:
            value = ds.attrs.get(attribute.key)

            if value:
                body[attribute.output_key] = value

        return body

XarrayHeaderInput

Bases: Input

Model for Xarray Header Method Input.

Parameters:

Name Type Description Default
input_term str

term for method to run on.

'$uri'
dataset_kwargs dict[str, Any]

kwargs to open dataset.

{}
attributes list[KeyOutputKey]

attributes to be extracted.

[]
Source code in extraction_methods/plugins/header/backends/xarray.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class XarrayHeaderInput(Input):
    """
    Model for Xarray Header Method Input.
    """

    input_term: str = Field(
        default="$uri",
        description="term for method to run on.",
    )
    dataset_kwargs: dict[str, Any] = Field(
        default={},
        description="kwargs to open dataset.",
    )
    attributes: list[KeyOutputKey] = Field(
        default=[],
        description="attributes to be extracted.",
    )