Skip to content

Commit 3dd798f

Browse files
committed
BREAKING CHANGE**: Using now dict2xml rather than dicttoxml #292
1 parent 61db423 commit 3dd798f

6 files changed

Lines changed: 24 additions & 11 deletions

File tree

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## 0.24.0 (2026-mm-dd)
44

5+
- **BREAKING CHANGE**: Using now `dict2xml` rather than `dicttoxml` [#292](https://github.com/sertit/eoreader/issues/292)
56
- **ENH: Adding the support of `Satellogic` (`Aleph-1`) constellation** [#229](https://github.com/sertit/eoreader/issues/229)
67
- **ENH: Add fallback for TSX/TDX extent when `SUPPORT/GEARTH_POLY.kml` is missing** [#290](https://github.com/sertit/eoreader/issues/290)
78
- **ENH: Handle windows when loading DEM bands**

eoreader/products/optical/aleph1_product.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import geopandas as gpd
2525
import numpy as np
2626
import xarray as xr
27-
from dicttoxml import dicttoxml
2827
from lxml import etree
2928
from rasterio.enums import Resampling
3029
from sertit import files, path
@@ -525,6 +524,8 @@ def _read_mtd(self) -> (etree._Element, dict):
525524
"""
526525
# MTD are JSON
527526
try:
527+
from dict2xml import dict2xml
528+
528529
mtd = self._read_mtd_dict()
529530

530531
# Sanitize STAC mtd (remove STAC prefixes with ':' that break XML keys)
@@ -541,7 +542,7 @@ def __sanitize_recursive(d):
541542
mtd.pop("stac_version", None)
542543
mtd.pop("type", None)
543544
__sanitize_recursive(mtd)
544-
root = etree.fromstring(dicttoxml(mtd, attr_type=False))
545+
root = etree.fromstring(dict2xml(mtd, wrap="all"))
545546
except etree.XMLSyntaxError as exc:
546547
raise InvalidProductError(
547548
f"Cannot convert metadata to XML for {self.path}!"

eoreader/products/sar/capella_product.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
import geopandas as gpd
2727
from affine import Affine
28-
from dicttoxml import dicttoxml
2928
from lxml import etree
3029
from rasterio import CRS, transform
3130
from sertit import files, path, vectors
@@ -409,6 +408,8 @@ def _read_mtd(self) -> (etree._Element, dict):
409408

410409
# MTD are JSON
411410
try:
411+
from dict2xml import dict2xml
412+
412413
try:
413414
mtd_file = next(self.path.glob(f"{self.name}.json"))
414415
self._has_stac_mtd = True
@@ -425,7 +426,17 @@ def _read_mtd(self) -> (etree._Element, dict):
425426
) from ex
426427

427428
data = files.read_json(mtd_file, print_file=False)
428-
root = etree.fromstring(dicttoxml(data))
429+
430+
def __sanitize_recursive(d):
431+
for key in d.copy():
432+
k = key.split(":")[-1]
433+
d[k] = d.pop(key)
434+
if isinstance(d[k], dict):
435+
__sanitize_recursive(d[k])
436+
437+
data.pop("assets", None)
438+
__sanitize_recursive(data)
439+
root = etree.fromstring(dict2xml(data, wrap="all"))
429440
except etree.XMLSyntaxError as exc:
430441
raise InvalidProductError(
431442
f"Cannot convert metadata to XML for {self.path}!"
@@ -493,7 +504,7 @@ def get_orbit_direction(self) -> OrbitDirection:
493504
if self._has_stac_mtd:
494505
root, _ = self.read_mtd()
495506

496-
ob = root.findtext(".//key[@name='sat:orbit_state']")
507+
ob = root.findtext(".//orbit_state")
497508
ob = OrbitDirection.from_value(ob.upper())
498509

499510
if ob is None:

eoreader/products/sar/umbra_product.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import geopandas as gpd
2727
import numpy as np
2828
import rasterio
29-
from dicttoxml import dicttoxml
3029
from lxml import etree
3130
from rasterio import crs
3231
from sertit import files, path, vectors
@@ -428,9 +427,10 @@ def _read_mtd(self) -> (etree._Element, dict):
428427
Returns:
429428
(etree._Element, dict): Metadata XML root and its namespaces as a dict
430429
"""
431-
432430
# MTD are JSON
433431
try:
432+
from dict2xml import dict2xml
433+
434434
try:
435435
mtd_file = self._get_stac_mtd_path()
436436
self._has_stac_mtd = True
@@ -462,7 +462,7 @@ def __sanitize_recursive(d):
462462

463463
data.pop("assets", None)
464464
__sanitize_recursive(data)
465-
root = etree.fromstring(dicttoxml(data, attr_type=False))
465+
root = etree.fromstring(dict2xml(data, wrap="all"))
466466
except etree.XMLSyntaxError as exc:
467467
raise InvalidProductError(
468468
f"Cannot convert metadata to XML for {self.path}!"
@@ -488,7 +488,7 @@ def get_raw_band_paths(self, **kwargs) -> dict:
488488

489489
# Open polarizations
490490
# Same for the two MTD
491-
pol = root.find(".//polarizations").findtext("item")
491+
pol = root.findtext(".//polarizations")
492492

493493
# Convert pol to an EOReader band
494494
pol = sab.from_value(pol)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ dependencies = [
5151
"cloudpathlib[s3]>=0.15.0",
5252
"validators",
5353
"methodtools",
54-
"dicttoxml",
54+
"dict2xml",
5555
"tifffile",
5656
"ephem",
5757
]

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ twine
1212
lxml
1313
zarr
1414
h5netcdf
15-
dicttoxml
15+
dict2xml
1616

1717
# Paths
1818
validators

0 commit comments

Comments
 (0)