File: xarray_backends.py

package info (click to toggle)
xarray-sentinel 0.9.5%2Bds-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 21,540 kB
  • sloc: xml: 77,744; python: 2,076; makefile: 32; sh: 17
file content (39 lines) | stat: -rw-r--r-- 1,260 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import os
from typing import Any, Dict, Optional, Tuple

import fsspec
import xarray as xr

from . import sentinel1


class Sentinel1Backend(xr.backends.common.BackendEntrypoint):
    def open_dataset(  # type: ignore
        self,
        filename_or_obj: str,
        drop_variables: Optional[Tuple[str]] = None,
        group: Optional[str] = None,
        storage_options: Optional[Dict[str, Any]] = None,
        override_product_files: Optional[str] = None,
        fs: Optional[fsspec.AbstractFileSystem] = None,
        check_files_exist: bool = False,
        parse_geospatial_attrs: bool = True,
    ) -> xr.Dataset:
        ds = sentinel1.open_sentinel1_dataset(
            filename_or_obj,
            drop_variables=drop_variables,
            group=group,
            storage_options=storage_options,
            override_product_files=override_product_files,
            fs=fs,
            check_files_exist=check_files_exist,
            parse_geospatial_attrs=parse_geospatial_attrs,
        )
        return ds

    def guess_can_open(self, filename_or_obj: Any) -> bool:
        try:
            _, ext = os.path.splitext(filename_or_obj)
        except TypeError:
            return False
        return ext.lower() in {".safe", ".safe/"}