From e7b08a48533a27b8fb574c0422d237407e1662fd Mon Sep 17 00:00:00 2001 From: Alessandro Amici Date: Tue, 13 Apr 2021 15:54:13 +0200 Subject: [PATCH 1/5] Add an autogenerated (and manually fixed) XSD for the manifest --- .../resources/sentinel1/my-gml.xsd | 4 + .../resources/sentinel1/my-no-namespace.xsd | 105 ++++++++ ...fe-sentinel-1.0-sentinel-1-sar-level-1.xsd | 29 +++ .../my-safe-sentinel-1.0-sentinel-1.xsd | 19 ++ .../sentinel1/my-safe-sentinel-1.0.xsd | 232 ++++++++++++++++++ .../resources/sentinel1/my-xfdu.xsd | 35 +++ 6 files changed, 424 insertions(+) create mode 100644 xarray_sentinel/resources/sentinel1/my-gml.xsd create mode 100644 xarray_sentinel/resources/sentinel1/my-no-namespace.xsd create mode 100644 xarray_sentinel/resources/sentinel1/my-safe-sentinel-1.0-sentinel-1-sar-level-1.xsd create mode 100644 xarray_sentinel/resources/sentinel1/my-safe-sentinel-1.0-sentinel-1.xsd create mode 100644 xarray_sentinel/resources/sentinel1/my-safe-sentinel-1.0.xsd create mode 100644 xarray_sentinel/resources/sentinel1/my-xfdu.xsd diff --git a/xarray_sentinel/resources/sentinel1/my-gml.xsd b/xarray_sentinel/resources/sentinel1/my-gml.xsd new file mode 100644 index 0000000..64317fe --- /dev/null +++ b/xarray_sentinel/resources/sentinel1/my-gml.xsd @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/xarray_sentinel/resources/sentinel1/my-no-namespace.xsd b/xarray_sentinel/resources/sentinel1/my-no-namespace.xsd new file mode 100644 index 0000000..ae35e95 --- /dev/null +++ b/xarray_sentinel/resources/sentinel1/my-no-namespace.xsd @@ -0,0 +1,105 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/xarray_sentinel/resources/sentinel1/my-safe-sentinel-1.0-sentinel-1-sar-level-1.xsd b/xarray_sentinel/resources/sentinel1/my-safe-sentinel-1.0-sentinel-1-sar-level-1.xsd new file mode 100644 index 0000000..7d7d4c9 --- /dev/null +++ b/xarray_sentinel/resources/sentinel1/my-safe-sentinel-1.0-sentinel-1-sar-level-1.xsd @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/xarray_sentinel/resources/sentinel1/my-safe-sentinel-1.0-sentinel-1.xsd b/xarray_sentinel/resources/sentinel1/my-safe-sentinel-1.0-sentinel-1.xsd new file mode 100644 index 0000000..3591798 --- /dev/null +++ b/xarray_sentinel/resources/sentinel1/my-safe-sentinel-1.0-sentinel-1.xsd @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/xarray_sentinel/resources/sentinel1/my-safe-sentinel-1.0.xsd b/xarray_sentinel/resources/sentinel1/my-safe-sentinel-1.0.xsd new file mode 100644 index 0000000..71e7392 --- /dev/null +++ b/xarray_sentinel/resources/sentinel1/my-safe-sentinel-1.0.xsd @@ -0,0 +1,232 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/xarray_sentinel/resources/sentinel1/my-xfdu.xsd b/xarray_sentinel/resources/sentinel1/my-xfdu.xsd new file mode 100644 index 0000000..cf92efc --- /dev/null +++ b/xarray_sentinel/resources/sentinel1/my-xfdu.xsd @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 6f709f4e4ef2d1a287878337d08bf223c7664c07 Mon Sep 17 00:00:00 2001 From: Alessandro Amici Date: Tue, 13 Apr 2021 19:23:58 +0200 Subject: [PATCH 2/5] Add sentinel1 parsing of manifest.safe metadata --- tests/test_esa_safe.py | 25 +++++++++++++++++++++++++ xarray_sentinel/esa_safe.py | 21 ++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/tests/test_esa_safe.py b/tests/test_esa_safe.py index c0e0448..9b17677 100644 --- a/tests/test_esa_safe.py +++ b/tests/test_esa_safe.py @@ -204,3 +204,28 @@ def test_parse_manifest_sentinel2( res_attrs, res_files = esa_safe.parse_manifest_sentinel2(manifest) assert res_attrs == expected + + +def test_parse_sentinel1_manifest(): + manifest_path = str( + DATA_FOLDER + / "S1B_IW_SLC__1SDV_20210401T052622_20210401T052650_026269_032297_EFA4.SAFE" + / "manifest.safe" + ) + + res, _ = esa_safe.parse_sentinel1_manifest(manifest_path) + + assert isinstance(res, dict) + assert "safe:platform" in res + assert set(res["safe:platform"]) == { + "safe:nssdcIdentifier", + "safe:familyName", + "safe:number", + "safe:instrument", + } + + _, res = esa_safe.parse_sentinel1_manifest(manifest_path) + + assert isinstance(res, list) + assert isinstance(res[0], dict) + assert "@href" in res[0] diff --git a/xarray_sentinel/esa_safe.py b/xarray_sentinel/esa_safe.py index a8fb1de..cf493cb 100644 --- a/xarray_sentinel/esa_safe.py +++ b/xarray_sentinel/esa_safe.py @@ -24,7 +24,10 @@ @functools.lru_cache() def sentinel1_schemas(schema_type: str) -> xmlschema.XMLSchema: support_dir = pkg_resources.resource_filename(__name__, "resources/sentinel1") - schema_paths = {"product": os.path.join(support_dir, "s1-level-1-product.xsd")} + schema_paths = { + "manifest": os.path.join(support_dir, "my-xfdu.xsd"), + "product": os.path.join(support_dir, "s1-level-1-product.xsd"), + } return xmlschema.XMLSchema(schema_paths[schema_type]) @@ -154,6 +157,22 @@ def parse_manifest_sentinel1( return attributes, files +# unused until we add an interface to access original metadata +def parse_sentinel1_manifest( + manifest_path: PathType, +) -> T.Tuple[T.Dict[str, T.Any], T.Dict[str, str]]: + schema = sentinel1_schemas("manifest") + + xml_metadata = {} + for xml_tags in schema.to_dict(manifest_path, ".//xmlData"): + for key, value in xml_tags.items(): + xml_metadata[key] = value + + fileLocation = schema.to_dict(manifest_path, ".//fileLocation") + + return xml_metadata, fileLocation + + def parse_manifest_sentinel2( manifest: ElementTree.ElementTree, ) -> T.Tuple[T.Dict[str, T.Any], T.Dict[str, str]]: From b40bee3ff53c0d65642bae5dbf5786bfe115d40b Mon Sep 17 00:00:00 2001 From: Alessandro Amici Date: Tue, 13 Apr 2021 19:36:49 +0200 Subject: [PATCH 3/5] Fix the only type hint error --- tests/test_esa_safe.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_esa_safe.py b/tests/test_esa_safe.py index 9b17677..167e254 100644 --- a/tests/test_esa_safe.py +++ b/tests/test_esa_safe.py @@ -206,7 +206,7 @@ def test_parse_manifest_sentinel2( assert res_attrs == expected -def test_parse_sentinel1_manifest(): +def test_parse_sentinel1_manifest() -> None: manifest_path = str( DATA_FOLDER / "S1B_IW_SLC__1SDV_20210401T052622_20210401T052650_026269_032297_EFA4.SAFE" From 89224f25f71937b72d644480c4414693b260a806 Mon Sep 17 00:00:00 2001 From: Alessandro Amici Date: Wed, 14 Apr 2021 19:06:34 +0200 Subject: [PATCH 4/5] Better (?) name. --- tests/test_esa_safe.py | 6 +++--- xarray_sentinel/esa_safe.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_esa_safe.py b/tests/test_esa_safe.py index f1c0001..25e3e09 100644 --- a/tests/test_esa_safe.py +++ b/tests/test_esa_safe.py @@ -231,14 +231,14 @@ def test_parse_manifest_sentinel2( assert res_attrs == expected -def test_parse_sentinel1_manifest() -> None: +def test_parse_original_manifest_sentinel1() -> None: manifest_path = str( DATA_FOLDER / "S1B_IW_SLC__1SDV_20210401T052622_20210401T052650_026269_032297_EFA4.SAFE" / "manifest.safe" ) - res, _ = esa_safe.parse_sentinel1_manifest(manifest_path) + res, _ = esa_safe.parse_original_manifest_sentinel1(manifest_path) assert isinstance(res, dict) assert "safe:platform" in res @@ -249,7 +249,7 @@ def test_parse_sentinel1_manifest() -> None: "safe:instrument", } - _, res = esa_safe.parse_sentinel1_manifest(manifest_path) + _, res = esa_safe.parse_original_manifest_sentinel1(manifest_path) assert isinstance(res, list) assert isinstance(res[0], dict) diff --git a/xarray_sentinel/esa_safe.py b/xarray_sentinel/esa_safe.py index 304dc29..2023c8b 100644 --- a/xarray_sentinel/esa_safe.py +++ b/xarray_sentinel/esa_safe.py @@ -162,7 +162,7 @@ def parse_manifest_sentinel1( # unused until we add an interface to access original metadata -def parse_sentinel1_manifest( +def parse_original_manifest_sentinel1( manifest_path: PathType, ) -> T.Tuple[T.Dict[str, T.Any], T.Dict[str, str]]: schema = sentinel1_schemas("manifest") From ca42415506ac0d2775401d60833ddff68f2ce130 Mon Sep 17 00:00:00 2001 From: Alessandro Amici Date: Wed, 14 Apr 2021 19:10:41 +0200 Subject: [PATCH 5/5] Add EOF newlines --- xarray_sentinel/resources/sentinel1/my-gml.xsd | 2 +- xarray_sentinel/resources/sentinel1/my-no-namespace.xsd | 2 +- .../sentinel1/my-safe-sentinel-1.0-sentinel-1-sar-level-1.xsd | 2 +- .../resources/sentinel1/my-safe-sentinel-1.0-sentinel-1.xsd | 2 +- xarray_sentinel/resources/sentinel1/my-xfdu.xsd | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/xarray_sentinel/resources/sentinel1/my-gml.xsd b/xarray_sentinel/resources/sentinel1/my-gml.xsd index 64317fe..9c9a718 100644 --- a/xarray_sentinel/resources/sentinel1/my-gml.xsd +++ b/xarray_sentinel/resources/sentinel1/my-gml.xsd @@ -1,4 +1,4 @@ - \ No newline at end of file + diff --git a/xarray_sentinel/resources/sentinel1/my-no-namespace.xsd b/xarray_sentinel/resources/sentinel1/my-no-namespace.xsd index ae35e95..37c5d5b 100644 --- a/xarray_sentinel/resources/sentinel1/my-no-namespace.xsd +++ b/xarray_sentinel/resources/sentinel1/my-no-namespace.xsd @@ -102,4 +102,4 @@ - \ No newline at end of file + diff --git a/xarray_sentinel/resources/sentinel1/my-safe-sentinel-1.0-sentinel-1-sar-level-1.xsd b/xarray_sentinel/resources/sentinel1/my-safe-sentinel-1.0-sentinel-1-sar-level-1.xsd index 7d7d4c9..cb21d9d 100644 --- a/xarray_sentinel/resources/sentinel1/my-safe-sentinel-1.0-sentinel-1-sar-level-1.xsd +++ b/xarray_sentinel/resources/sentinel1/my-safe-sentinel-1.0-sentinel-1-sar-level-1.xsd @@ -26,4 +26,4 @@ - \ No newline at end of file + diff --git a/xarray_sentinel/resources/sentinel1/my-safe-sentinel-1.0-sentinel-1.xsd b/xarray_sentinel/resources/sentinel1/my-safe-sentinel-1.0-sentinel-1.xsd index 3591798..054f838 100644 --- a/xarray_sentinel/resources/sentinel1/my-safe-sentinel-1.0-sentinel-1.xsd +++ b/xarray_sentinel/resources/sentinel1/my-safe-sentinel-1.0-sentinel-1.xsd @@ -16,4 +16,4 @@ - \ No newline at end of file + diff --git a/xarray_sentinel/resources/sentinel1/my-xfdu.xsd b/xarray_sentinel/resources/sentinel1/my-xfdu.xsd index cf92efc..14eb716 100644 --- a/xarray_sentinel/resources/sentinel1/my-xfdu.xsd +++ b/xarray_sentinel/resources/sentinel1/my-xfdu.xsd @@ -32,4 +32,4 @@ - \ No newline at end of file +