Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions eof/asf_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def get_download_urls(
"S1A": [eof for eof in eof_list if eof.mission == "S1A"],
"S1B": [eof for eof in eof_list if eof.mission == "S1B"],
"S1C": [eof for eof in eof_list if eof.mission == "S1C"],
"S1D": [eof for eof in eof_list if eof.mission == "S1D"],
}

remaining_orbits = []
Expand Down
4 changes: 2 additions & 2 deletions eof/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@
@click.option(
"--mission",
"-m",
type=click.Choice(["S1A", "S1B", "S1C"]),
type=click.Choice(["S1A", "S1B", "S1C", "S1D"]),
help=(
"If using `--date`, optionally specify Sentinel satellite to download"
" (default: gets S1A, S1B, and S1C)"
" (default: gets S1A, S1B, S1C, and S1D)"
),
)
@click.option(
Expand Down
2 changes: 1 addition & 1 deletion eof/dataspace_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def query_orbit(
satellite_id: str,
product_type: str = "AUX_POEORB",
) -> list[dict]:
assert satellite_id in {"S1A", "S1B", "S1C"}
assert satellite_id in {"S1A", "S1B", "S1C", "S1D"}
assert product_type in {"AUX_POEORB", "AUX_RESORB"}
# return run_query(t0, t1, satellite_id, product_type)
# Construct the query based on the time range parsed from the input file
Expand Down
6 changes: 3 additions & 3 deletions eof/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ def download_eofs(
If there's an HTTP error during download that's not a rate limit error.
"""
# TODO: condense list of same dates, different hours?
if missions and all(m not in ("S1A", "S1B", "S1C") for m in missions):
raise ValueError('missions argument must be "S1A", "S1B" or "S1C"')
if missions and all(m not in ("S1A", "S1B", "S1C", "S1D") for m in missions):
raise ValueError('missions argument must be "S1A", "S1B", "S1C", or "S1D"')
if sentinel_file:
sent = Sentinel(sentinel_file)
orbit_dts, missions = [sent.start_time], [sent.mission]
Expand Down Expand Up @@ -306,7 +306,7 @@ def main(
# Handle parsing in download_eof
orbit_dts, missions = None, None
elif date:
missions = [mission] if mission else ["S1A", "S1B", "S1C"]
missions = [mission] if mission else ["S1A", "S1B", "S1C", "S1D"]
orbit_dts = [parse(date)] * len(missions)
# Check they didn't pass a whole datetime
if all((dt.hour == 0 and dt.minute == 0) for dt in orbit_dts):
Expand Down
3 changes: 3 additions & 0 deletions eof/products.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@ def relative_orbit(self):
return ((self.absolute_orbit - 27) % 175) + 1
elif self.mission == "S1C":
return ((self.absolute_orbit - 172) % 175) + 1
elif self.mission == "S1D":
# Offset derived from abs=2389 -> rel=73; needs verification with ESA
return ((self.absolute_orbit - 42) % 175) + 1
else:
raise ValueError(f"Unknown relative orbit for mission {self.mission}")

Expand Down
87 changes: 87 additions & 0 deletions scripts/get_relative_orbit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/usr/bin/env python
"""
Estimate Sentinel-1 relative orbit directly from SAFE metadata.

Works for S1A/B/C/D — reads relativeOrbitNumber from manifest.safe.
Accepts a .SAFE directory or a zipped SAFE (any extension).

Usage
-----
python get_relative_orbit.py <path_to_SAFE_or_zip>
"""
import sys
import zipfile
import xml.etree.ElementTree as ET
from pathlib import Path

from eof.products import Sentinel

NS = {
"safe": "http://www.esa.int/safe/sentinel-1.0",
"s1": "http://www.esa.int/safe/sentinel-1.0/sentinel-1",
}


def read_manifest(safe_path: str) -> ET.Element:
p = Path(safe_path)
if zipfile.is_zipfile(p):
with zipfile.ZipFile(p) as zf:
manifest = next(f for f in zf.namelist() if f.endswith("manifest.safe"))
return ET.parse(zf.open(manifest)).getroot()
else:
return ET.parse(p / "manifest.safe").getroot()


def get_relative_orbit(safe_path: str) -> dict:
root = read_manifest(safe_path)

def find(tag):
for el in root.iter():
if el.tag.split("}")[-1] == tag:
return el
return None

rel_orbit = find("relativeOrbitNumber")
abs_orbit = find("orbitNumber")
direction = find("pass")
ant = find("ascendingNodeTime")

# Parse mission from filename via the same regex used elsewhere in eof
satellite = Sentinel(Path(safe_path).stem).mission

result = {
"satellite": satellite,
"absolute_orbit": int(abs_orbit.text) if abs_orbit is not None else None,
"relative_orbit": int(rel_orbit.text) if rel_orbit is not None else None,
"orbit_direction": direction.text if direction is not None else None,
"ascending_node_time": ant.text if ant is not None else None,
}

# Derive offset for formula: rel = (abs - offset) % 175 + 1
if result["absolute_orbit"] and result["relative_orbit"]:
abs_o = result["absolute_orbit"]
rel_o = result["relative_orbit"]
# offset = abs - (rel - 1) mod 175; pick smallest positive value < 175
offset_mod = (abs_o - (rel_o - 1)) % 175
result["derived_offset_mod175"] = offset_mod
result["formula_check"] = (abs_o - offset_mod) % 175 + 1

return result


if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: python get_relative_orbit.py <SAFE_or_zip>")
sys.exit(1)

info = get_relative_orbit(sys.argv[1])
print(f"Satellite: {info['satellite']}")
print(f"Absolute orbit: {info['absolute_orbit']}")
print(f"Relative orbit: {info['relative_orbit']}")
print(f"Orbit direction: {info['orbit_direction']}")
print(f"Ascending node time: {info['ascending_node_time']}")
if "derived_offset_mod175" in info:
print(f"Derived offset mod175: {info['derived_offset_mod175']}")
print(
f"Formula check: ({info['absolute_orbit']} - {info['derived_offset_mod175']}) % 175 + 1 = {info['formula_check']}"
)