Skip to content

Commit 56708ea

Browse files
authored
Merge pull request #90 from umr-lops/replace-datatree-xarray
first attempt to replace xarray-datatree by xarray native DataTrees
2 parents e1d9469 + a3b7dc9 commit 56708ea

39 files changed

+1658
-1340
lines changed

.github/workflows/ci.yaml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
workflow_dispatch:
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
detect-skip-ci-trigger:
16+
name: "Detect CI Trigger: [skip-ci]"
17+
if: |
18+
github.repository == 'umr-lops/utils_xsarslc_l1b'
19+
&& (
20+
github.event_name == 'push' || github.event_name == 'pull_request'
21+
)
22+
runs-on: ubuntu-latest
23+
outputs:
24+
triggered: ${{ steps.detect-trigger.outputs.trigger-found }}
25+
steps:
26+
- uses: actions/checkout@v4
27+
with:
28+
fetch-depth: 2
29+
- uses: xarray-contrib/ci-trigger@v1
30+
id: detect-trigger
31+
with:
32+
keyword: "[skip-ci]"
33+
34+
ci:
35+
name: ${{ matrix.os }} py${{ matrix.python-version }}
36+
runs-on: ${{ matrix.os }}
37+
needs: detect-skip-ci-trigger
38+
39+
if: needs.detect-skip-ci-trigger.outputs.triggered == 'false'
40+
41+
defaults:
42+
run:
43+
shell: bash -l {0}
44+
45+
strategy:
46+
fail-fast: false
47+
matrix:
48+
python-version: ["3.10", "3.11", "3.12"]
49+
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
50+
51+
steps:
52+
- name: Checkout the repository
53+
uses: actions/checkout@v4
54+
with:
55+
# need to fetch all tags to get a correct version
56+
fetch-depth: 0 # fetch all branches and tags
57+
58+
- name: Setup environment variables
59+
run: |
60+
echo "TODAY=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
61+
62+
echo "CONDA_ENV_FILE=ci/requirements/environment.yaml" >> $GITHUB_ENV
63+
64+
- name: Setup micromamba
65+
uses: mamba-org/setup-micromamba@v2
66+
with:
67+
environment-file: ${{ env.CONDA_ENV_FILE }}
68+
environment-name: slcl1butils-tests
69+
cache-environment: true
70+
cache-environment-key: "${{runner.os}}-${{runner.arch}}-py${{matrix.python-version}}-${{env.TODAY}}-${{hashFiles(env.CONDA_ENV_FILE)}}"
71+
create-args: >-
72+
python=${{matrix.python-version}}
73+
74+
- name: Install slcl1butils
75+
run: |
76+
python -m pip install --no-deps -e .
77+
78+
- name: Import slcl1butils
79+
run: |
80+
python -c "import slcl1butils"
81+
82+
- name: Run tests
83+
run: |
84+
python -m pytest --cov=slcl1butils

ci/requirements/environment.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: slcl1butils-tests
22
channels:
33
- conda-forge
44
dependencies:
5-
- python=3.10
5+
- python
66
# development
77
- ipython
88
- pre-commit
@@ -14,6 +14,7 @@ dependencies:
1414
# testing
1515
- pytest
1616
- pytest-reportlog
17+
- pytest-cov
1718
- hypothesis
1819
- coverage
1920
# I/O
@@ -23,7 +24,6 @@ dependencies:
2324
- fsspec
2425
# data
2526
- xarray
26-
- xarray-datatree
2727
- dask
2828
- numpy
2929
- pandas

docs/conf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
"numpy": ("https://numpy.org/doc/stable", None),
6161
"xarray": ("https://docs.xarray.dev/en/latest/", None),
6262
"rasterio": ("https://rasterio.readthedocs.io/en/latest/", None),
63-
"datatree": ("https://xarray-datatree.readthedocs.io/en/latest/", None),
6463
'geoviews': ('https://geoviews.org/index.html', None)
6564
}
6665

docs/examples/display_a_IW_L1B_xspectra.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"source": [
2828
"import glob\n",
2929
"import os\n",
30-
"import datatree\n",
30+
"import xarray as xr\n",
3131
"from slcl1butils.utils import get_test_file\n",
3232
"#l1bncfile_pattern = os.path.abspath('../../assests/*iw*nc')\n",
3333
"one_safe_l1b = get_test_file('S1B_IW_XSP__1SDV_20210328T055258_20210328T055325_026211_0320D4_DC31_A13.SAFE')\n",
@@ -47,7 +47,7 @@
4747
},
4848
"outputs": [],
4949
"source": [
50-
"dt = datatree.open_datatree(l1bncfile)\n",
50+
"dt = xr.open_datatree(l1bncfile)\n",
5151
"dt"
5252
]
5353
},
@@ -187,7 +187,7 @@
187187
"tile_line_i = 0\n",
188188
"tile_sample_i = 3\n",
189189
"fig = plt.figure()\n",
190-
"slcl1butils.plotting.display_one_spectra.plot_a_single_xspec_cart_L1B_IW(ds,'VV',tile_line_i,tile_sample_i,'test display',fig,cat_xspec=cat_xspec,part='Re')"
190+
"slcl1butils.plotting.display_one_spectra.plot_a_single_xspec_cart_l1b_iw(ds,'VV',tile_line_i,tile_sample_i,'test display',fig,cat_xspec=cat_xspec,part='Re')"
191191
]
192192
}
193193
],
@@ -207,7 +207,7 @@
207207
"name": "python",
208208
"nbconvert_exporter": "python",
209209
"pygments_lexer": "ipython3",
210-
"version": "3.11.0"
210+
"version": "3.9.15"
211211
}
212212
},
213213
"nbformat": 4,

docs/examples/do_L1C_SAFE_from_L1B_SAFE_example.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
"name": "python",
109109
"nbconvert_exporter": "python",
110110
"pygments_lexer": "ipython3",
111-
"version": "3.11.0"
111+
"version": "3.9.15"
112112
}
113113
},
114114
"nbformat": 4,

docs/examples/plotting_L1B_geometry_with_holoview_example.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@
164164
"name": "python",
165165
"nbconvert_exporter": "python",
166166
"pygments_lexer": "ipython3",
167-
"version": "3.11.0"
167+
"version": "3.9.15"
168168
}
169169
},
170170
"nbformat": 4,

docs/index.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ slcl1butils: functions to play with IFREMER L1B Sentinel-1 SLC SAR products
66

77
Acquisition modes available in L1B IFREMER product family are IW and WV.
88

9-
The products are *netCDF* files containing `datatree`_ object.
9+
The products are *netCDF* files containing `xarray.datatree` object.
1010

1111

1212

@@ -104,5 +104,4 @@ Last documentation build: |today|
104104
basic_api
105105

106106
.. _on github: https://github.com/umr-lops/utils_xsarslc_l1b
107-
.. _datatree: https://github.com/xarray-contrib/datatree
108107
.. _xarray: http://xarray.pydata.org

docs/installing.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
Installation
55
************
66

7-
L1B SAR SLC IFREMER products are netCDF (.nc) files containing groups.
8-
To read netCDF files with groups, a possible python library is `xarray-datatree`.
7+
Level-1B SAR SLC IFREMER products are netCDF (.nc) files containing groups.
8+
To read netCDF files with groups, a possible python library is `xarray`.
99
Installation in a conda_ environment is recommended.
1010

1111

environment.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ dependencies:
66
- geoviews
77
- fsspec
88
- numpy
9-
- xarray-datatree
109
- xarray
1110
- rasterio
1211
- rioxarray

get_polygons_from_l1b.py

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
# +
2-
import datatree
32
import numpy as np
4-
from glob import glob
5-
import os
6-
import matplotlib.pyplot as plt
73
from shapely import geometry
84
from shapely import wkt
9-
import time
5+
106
import xarray as xr
117

12-
# from xsarslc.tools import xndindex
138

149
# +
1510
def get_swath_tiles_polygons_from_l1bgroup(l1b_ds, swath_only=False, variable_names = [None],ik=0,burst_type=None):
@@ -176,66 +171,3 @@ def get_swath_tiles_polygons_from_l1bfiles(l1b_files, variable_names = [None], i
176171
return polygons,coordinates,variables
177172
else:
178173
return polygons,coordinates
179-
180-
181-
# def get_polygons_from_l1b(files, varnames = None):
182-
183-
# pts_tiles_intra = []; pts_tiles_inter = []; pts_swath = []
184-
# t0 = time.time()
185-
186-
# pts_tiles = {}
187-
# burst_type = ['intraburst','interburst']
188-
# variables = {}
189-
# for brst in burst_type:
190-
# variables[brst] = {}
191-
# pts_tiles[brst] = []
192-
# if (varnames is not None):
193-
# for varname in varnames:
194-
# variables[brst][varname] = []
195-
196-
# for cpt,_file in enumerate(files):
197-
198-
# dt = datatree.open_datatree(_file)
199-
200-
# polyswath = wkt.loads(dt['intraburst'].ds.attrs['footprint'])
201-
# lon,lat = polyswath.exterior.xy
202-
# _pts_swath = [(x,y) for x,y in zip(lon,lat)]
203-
# pts_swath.append(_pts_swath)
204-
205-
206-
# for brst in burst_type:
207-
208-
# lon_corners = dt[brst]['corner_longitude'].squeeze()
209-
# lat_corners = dt[brst]['corner_latitude'].squeeze()
210-
# Nt = dt[brst].ds.sizes['tile_sample']
211-
# bursts = dt[brst]['burst'].values
212-
# for ib in bursts:
213-
# for it in np.arange(Nt):
214-
215-
# # Get corner list
216-
# _lon1 = lon_corners.sel(burst=ib).isel(tile_sample=it,c_line=0)
217-
# _lon2 = lon_corners.sel(burst=ib).isel(tile_sample=it,c_line=1)
218-
# _lat1 = lat_corners.sel(burst=ib).isel(tile_sample=it,c_line=0)
219-
# _lat2 = lat_corners.sel(burst=ib).isel(tile_sample=it,c_line=1)
220-
# lon = list(_lon1.values) + list(_lon2.values[::-1])
221-
# lat = list(_lat1.values) + list(_lat2.values[::-1])
222-
# _pts_tiles = [ (x,y) for x,y in zip(lon,lat)]
223-
# pts_tiles[brst].append(_pts_tiles)
224-
225-
# # Get variables
226-
# if (varnames is not None):
227-
# for varname in varnames:
228-
# variables[brst][varname].append(dt[brst][varname].sel(burst=ib).isel(tile_sample=it).values[0])
229-
230-
231-
232-
233-
# t1 = time.time()
234-
# print(t1-t0)
235-
# if (varnames is not None):
236-
# return pts_swath, pts_tiles, variables
237-
# else:
238-
# return pts_swath, pts_tiles
239-
# -
240-
241-

0 commit comments

Comments
 (0)