Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the autogenerated XSD to parse the manifest.safe file #11

Merged
merged 6 commits into from
Apr 15, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions tests/test_esa_safe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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() -> 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)

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]
21 changes: 20 additions & 1 deletion xarray_sentinel/esa_safe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])


Expand Down Expand Up @@ -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(
alexamici marked this conversation as resolved.
Show resolved Hide resolved
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]]:
Expand Down
4 changes: 4 additions & 0 deletions xarray_sentinel/resources/sentinel1/my-gml.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:tns="http://www.opengis.net/gml" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.opengis.net/gml" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="coordinates" type="xs:string" />
</xs:schema>
105 changes: 105 additions & 0 deletions xarray_sentinel/resources/sentinel1/my-no-namespace.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Created with Liquid Technologies Online Tools 1.0 (https://www.liquid-technologies.com) -->
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import schemaLocation="my-xfdu.xsd" namespace="urn:ccsds:schema:xfdu:1" />
<xs:import schemaLocation="my-safe-sentinel-1.0.xsd" namespace="http://www.esa.int/safe/sentinel-1.0" />
<xs:import schemaLocation="my-safe-sentinel-1.0-sentinel-1-sar-level-1.xsd" namespace="http://www.esa.int/safe/sentinel-1.0/sentinel-1/sar/level-1" />
<xs:element name="informationPackageMap">
<xs:complexType>
<xs:sequence>
<xs:element xmlns:q1="urn:ccsds:schema:xfdu:1" ref="q1:contentUnit" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="dataObjectPointer">
<xs:complexType>
<xs:attribute name="dataObjectID" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
<xs:element name="metadataSection">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="metadataObject">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="metadataReference">
<xs:complexType>
<xs:attribute name="mimeType" type="xs:string" use="required" />
<xs:attribute name="vocabularyName" type="xs:string" use="required" />
<xs:attribute name="locatorType" type="xs:string" use="required" />
<xs:attribute name="href" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
<xs:element minOccurs="0" name="metadataWrap">
<xs:complexType>
<xs:sequence>
<xs:element name="xmlData">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" xmlns:q2="http://www.esa.int/safe/sentinel-1.0" ref="q2:frameSet" />
<xs:element minOccurs="0" xmlns:q3="http://www.esa.int/safe/sentinel-1.0" ref="q3:acquisitionPeriod" />
<xs:element minOccurs="0" xmlns:q4="http://www.esa.int/safe/sentinel-1.0/sentinel-1/sar/level-1" ref="q4:standAloneProductInformation" />
<xs:element minOccurs="0" xmlns:q5="http://www.esa.int/safe/sentinel-1.0" ref="q5:orbitReference" />
<xs:element minOccurs="0" xmlns:q6="http://www.esa.int/safe/sentinel-1.0" ref="q6:platform" />
<xs:element minOccurs="0" xmlns:q7="http://www.esa.int/safe/sentinel-1.0" ref="q7:processing" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="mimeType" type="xs:string" use="required" />
<xs:attribute name="vocabularyName" type="xs:string" use="required" />
<xs:attribute name="textInfo" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
<xs:element minOccurs="0" name="dataObjectPointer">
<xs:complexType>
<xs:attribute name="dataObjectID" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="ID" type="xs:string" use="required" />
<xs:attribute name="classification" type="xs:string" use="required" />
<xs:attribute name="category" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="dataObjectSection">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="dataObject">
<xs:complexType>
<xs:sequence>
<xs:element name="byteStream">
<xs:complexType>
<xs:sequence>
<xs:element name="fileLocation">
<xs:complexType>
<xs:attribute name="locatorType" type="xs:string" use="required" />
<xs:attribute name="href" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
<xs:element name="checksum">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="checksumName" type="xs:string" use="required" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="mimeType" type="xs:string" use="required" />
<xs:attribute name="size" type="xs:unsignedInt" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="ID" type="xs:string" use="required" />
<xs:attribute name="repID" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:tns="http://www.esa.int/safe/sentinel-1.0/sentinel-1/sar/level-1" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.esa.int/safe/sentinel-1.0/sentinel-1/sar/level-1" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="instrumentMode">
<xs:complexType>
<xs:sequence>
<xs:element name="mode" type="xs:string" />
<xs:element maxOccurs="unbounded" name="swath" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="standAloneProductInformation">
<xs:complexType>
<xs:sequence>
<xs:element name="instrumentConfigurationID" type="xs:unsignedByte" />
<xs:element name="missionDataTakeID" type="xs:unsignedInt" />
<xs:element maxOccurs="unbounded" name="transmitterReceiverPolarisation" type="xs:string" />
<xs:element name="productClass" type="xs:string" />
<xs:element name="productClassDescription" type="xs:string" />
<xs:element name="productComposition" type="xs:string" />
<xs:element name="productType" type="xs:string" />
<xs:element name="productTimelinessCategory" type="xs:string" />
<xs:element name="sliceProductFlag" type="xs:boolean" />
<xs:element name="segmentStartTime" type="xs:dateTime" />
<xs:element name="sliceNumber" type="xs:unsignedByte" />
<xs:element name="totalSlices" type="xs:unsignedByte" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:tns="http://www.esa.int/safe/sentinel-1.0/sentinel-1" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.esa.int/safe/sentinel-1.0/sentinel-1" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="orbitProperties">
<xs:complexType>
<xs:sequence>
<xs:element name="pass" type="xs:string" />
<xs:element name="ascendingNodeTime" type="xs:dateTime" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="timeANX">
<xs:complexType>
<xs:sequence>
<xs:element name="startTimeANX" type="xs:float" />
<xs:element name="stopTimeANX" type="xs:float" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Loading