Skip to content

Commit 4c0184c

Browse files
authored
Merge pull request #39 from umr-lops/replace-datatree-by-array
replace all import/usage of xarray-datatree by xarray.datatree
2 parents 57ea648 + 4581c3e commit 4c0184c

File tree

5 files changed

+40
-12
lines changed

5 files changed

+40
-12
lines changed

docs/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ Overview
1313
........
1414

1515
**safe_s1** rely on `xarray.open_rasterio` and `rasterio` to read *digital_number* from SAFE
16-
product to return an xarray-datatree.
16+
product to return an xarray.datatree.
1717

1818
Luts are decoded from xml files following `ESA Sentinel-1 Product Specification`_.
1919

2020

21-
`safe_s1.metadata.Sentinel1reader` is the main class and contains a xarray-datatree with the useful data. In the following example, you will find some additional functions and properties that can be useful.
21+
`safe_s1.metadata.Sentinel1reader` is the main class and contains a xarray.datatree with the useful data. In the following example, you will find some additional functions and properties that can be useful.
2222

2323
Examples
2424
........

highleveltests/open_GRD_IW.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import pdb
2+
from safe_s1 import Sentinel1Reader, getconfig
3+
import time
4+
import logging
5+
logging.basicConfig(level=logging.DEBUG)
6+
logging.debug('start GRD test')
7+
conf = getconfig.get_config()
8+
subswath = conf['product_paths'][0]
9+
print(subswath)
10+
t0 = time.time()
11+
if 'GRD' in subswath:
12+
sub_reader = Sentinel1Reader(subswath)
13+
else:
14+
sub_reader = Sentinel1Reader('SENTINEL1_DS:'+subswath+':IW3')
15+
elapse_t = time.time()-t0
16+
17+
dt = sub_reader.datatree
18+
print('out of the reader')
19+
print(dt)
20+
print('time to read the SAFE through nfs: %1.2f sec'%elapse_t)
21+
DN = sub_reader.load_digital_number(chunks={'pol':'VV','line':6000,'sample':8000})
22+
print('DN',DN)
23+
# pdb.set_trace()

highleveltests/open_SLC_IW.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
dt = sub_reader.datatree
1212
print('out of the reader')
1313
print(dt)
14-
print('time to read the SAFE through S3: %1.2f sec'%elapse_t)
14+
print('time to read the SAFE through nfs: %1.2f sec'%elapse_t)
1515
pdb.set_trace()

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ license = {text = "MIT"}
55
dependencies = [
66
"geopandas",
77
"numpy",
8-
"xarray",
9-
"xarray-datatree",
8+
"xarray>=2024.10.0",
109
"lxml",
1110
"rioxarray",
1211
"jmespath",

safe_s1/reader.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@
88
import yaml
99
from affine import Affine
1010
from rioxarray import rioxarray
11-
12-
from . import sentinel1_xml_mappings
13-
from .xml_parser import XmlParser
11+
import logging
12+
from safe_s1 import sentinel1_xml_mappings
13+
from safe_s1.xml_parser import XmlParser
1414
import xarray as xr
15-
import datatree
1615
import pandas as pd
1716
import warnings
1817

1918

2019
class Sentinel1Reader:
2120

2221
def __init__(self, name, backend_kwargs=None):
22+
logging.debug('input name: %s',name)
2323
if not isinstance(name, (str, os.PathLike)):
2424
raise ValueError(f"cannot deal with object of type {type(name)}: {name}")
2525
# gdal dataset name
@@ -29,13 +29,19 @@ def __init__(self, name, backend_kwargs=None):
2929
"""Gdal dataset name"""
3030
name_parts = self.name.split(':')
3131
if len(name_parts) > 3:
32+
logging.debug('windows case')
3233
# windows might have semicolon in path ('c:\...')
3334
name_parts[1] = ':'.join(name_parts[1:-1])
3435
del name_parts[2:-1]
3536
name_parts[1] = os.path.basename(name_parts[1])
3637
self.short_name = ':'.join(name_parts)
38+
logging.debug('short_name : %s',self.short_name)
3739
"""Like name, but without path"""
38-
self.path = ':'.join(self.name.split(':')[1:-1])
40+
if len(name_parts) == 2:
41+
self.path = self.name.split(':')[1]
42+
else:
43+
self.path = ':'.join(self.name.split(':')[1:-1])
44+
logging.debug('path: %s',self.path)
3945
# remove trailing slash in the safe path
4046
if self.path[-1]=='/':
4147
self.path = self.path.rstrip('/')
@@ -108,7 +114,7 @@ def __init__(self, name, backend_kwargs=None):
108114
'antenna_pattern':self.antenna_pattern,
109115
'swath_merging': self.swath_merging
110116
}
111-
self.dt = datatree.DataTree.from_dict(self._dict)
117+
self.dt = xr.DataTree.from_dict(self._dict)
112118
assert self.dt==self.datatree
113119
else:
114120
print('multidataset')
@@ -341,7 +347,7 @@ def datatree(self):
341347
342348
Returns
343349
-------
344-
datatree.DataTree
350+
xr.DataTree
345351
Contains data from the reader
346352
"""
347353
return self.dt

0 commit comments

Comments
 (0)