11import logging
2+ import pathlib
23from typing import Any
34
45import fsspec
56import xarray as xr
67
7- from . import esa_safe , sentinel1
8+ from . import eopf_metadata , esa_safe , sentinel1
89
910
1011def open_datatree (
@@ -14,41 +15,82 @@ def open_datatree(
1415 storage_options : dict [str , Any ] | None = None ,
1516 check_files_exist : bool = False ,
1617 override_product_files : str | None = None ,
17- parse_geospatial_attrs : bool = True ,
1818 ** kwargs : Any ,
1919) -> xr .DataTree :
20+ product_name = pathlib .Path (product_urlpath ).stem
2021 root = sentinel1 .open_sentinel1_dataset (
2122 product_urlpath ,
2223 fs = fs ,
2324 storage_options = storage_options ,
2425 check_files_exist = check_files_exist ,
26+ override_product_files = override_product_files ,
2527 )
28+ xarray_sentinel_groups = root .attrs ["subgroups" ]
2629 dt = xr .DataTree ()
27- for group in root . attrs [ "subgroups" ] :
28- subgroup = group .partition ("/" )[ 2 ]
30+ for xarray_sentinel_group in xarray_sentinel_groups :
31+ _ , _ , pol_group = xarray_sentinel_group .partition ("/" )
2932 try :
30- product_type , _ , dataset = subgroup .partition ("/" )
31- if not product_type :
33+ pol , _ , dataset = pol_group .partition ("/" )
34+ eopf_product_name = f"{ product_name } _{ pol .upper ()} "
35+ if not pol :
3236 continue
3337 if not dataset :
34- dt [f"{ product_type } /measurement" ] = sentinel1 .open_sentinel1_dataset (
38+ if eopf_product_name not in dt .children :
39+ product_ds = xr .Dataset (
40+ attrs = {
41+ "other_metadata" : eopf_metadata .build_other_metadata (
42+ product_urlpath
43+ ),
44+ "stac_metadata" : {},
45+ }
46+ )
47+ dt [f"{ eopf_product_name } " ] = product_ds
48+ ds = sentinel1 .open_sentinel1_dataset (
3549 product_urlpath ,
3650 fs = fs ,
3751 storage_options = storage_options ,
3852 check_files_exist = check_files_exist ,
39- group = group ,
53+ override_product_files = override_product_files ,
54+ group = xarray_sentinel_group ,
4055 )
41- else :
42- dt [f"{ product_type } /conditions/{ dataset } " ] = (
43- sentinel1 .open_sentinel1_dataset (
44- product_urlpath ,
45- fs = fs ,
46- storage_options = storage_options ,
47- check_files_exist = check_files_exist ,
48- group = group ,
49- )
56+ ds .attrs .clear ()
57+ dt [f"{ eopf_product_name } /measurement" ] = ds .rename (
58+ {"measurement" : "slc" }
59+ )
60+ elif dataset in {
61+ "antenna_pattern" ,
62+ "orbit" ,
63+ "attitude" ,
64+ "azimuth_fm_rate" ,
65+ "doppler_centroid" ,
66+ "reference_replica" ,
67+ "replica" ,
68+ "gcp" ,
69+ }:
70+ ds = sentinel1 .open_sentinel1_dataset (
71+ product_urlpath ,
72+ fs = fs ,
73+ storage_options = storage_options ,
74+ check_files_exist = check_files_exist ,
75+ group = xarray_sentinel_group ,
76+ override_product_files = override_product_files ,
5077 )
78+ ds .attrs .clear ()
79+ dt [f"{ eopf_product_name } /conditions/{ dataset } " ] = ds
80+ elif dataset in {"calibration" , "noise_range" , "noise_azimuth" }:
81+ ds = sentinel1 .open_sentinel1_dataset (
82+ product_urlpath ,
83+ fs = fs ,
84+ storage_options = storage_options ,
85+ check_files_exist = check_files_exist ,
86+ group = xarray_sentinel_group ,
87+ override_product_files = override_product_files ,
88+ )
89+ ds .attrs .clear ()
90+ dt [f"{ eopf_product_name } /quality/{ dataset } " ] = ds
91+ else :
92+ print (f"Skipping { xarray_sentinel_group = } " )
5193 except Exception :
52- logging .exception (f"{ group = } failed to load" )
94+ logging .exception (f"{ xarray_sentinel_group = } failed to load" )
5395
5496 return dt
0 commit comments