-
Notifications
You must be signed in to change notification settings - Fork 20
s1_geocode_stack.py: Add ability to read "DH" SAFE files #193
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
Open
scottstanie
wants to merge
1
commit into
opera-adt:main
Choose a base branch
from
scottstanie:stack-hh
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+31
−3
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -79,7 +79,8 @@ def create_parser(): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def generate_burst_map(zip_files, orbit_dir, output_epsg=None, bbox=None, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
bbox_epsg=4326, burst_db_file=DEFAULT_BURST_DB_FILE): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
bbox_epsg=4326, burst_db_file=DEFAULT_BURST_DB_FILE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pol_type: str = "co-pol"): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"""Generates a dataframe of geogrid infos for each burst ID in `zip_files`. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Parameters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -98,6 +99,8 @@ def generate_burst_map(zip_files, orbit_dir, output_epsg=None, bbox=None, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
to be lon/lat degrees (default: 4326). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
burst_db_file: str | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Path to the burst database file to load bounding boxes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pol-type: str | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Polarizations to process. Choices: co-pol, cross-pol, dual-pol | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Returns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -112,10 +115,11 @@ def generate_burst_map(zip_files, orbit_dir, output_epsg=None, bbox=None, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
i_subswath = [1, 2, 3] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
for zip_file in zip_files: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pol = _get_pol_str(zip_file, pol_type) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
orbit_path = get_orbit_file_from_dir(zip_file, orbit_dir, auto_download=True) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
for subswath in i_subswath: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ref_bursts = load_bursts(zip_file, orbit_path, subswath) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ref_bursts = load_bursts(zip_file, orbit_path, subswath, pol=pol) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
for burst in ref_bursts: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
epsg, bbox_utm = _get_burst_epsg_and_bbox( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
burst, output_epsg, bbox, bbox_epsg, burst_db_file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -135,6 +139,30 @@ def generate_burst_map(zip_files, orbit_dir, output_epsg=None, bbox=None, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
burst_map = pd.DataFrame(data=burst_map) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return burst_map | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def _get_pol_str(zip_file, pol_type): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"""Get the polarization string from the zip file name and the type of polarization.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# S1A_IW_SLC__1SDV_20150224T114043_ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# File name format: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# MMM_BB_TTTR_LFPP_YYYYMMDDTHHMMSS_YYYYMMDDTHHMMSS_OOOOOO_DDDDDD_CCCC.EEEE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# PP: Polarization: SH (single HH), SV (single VV), DH (dual HH+HV), DV (dual VV+VH) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
from pathlib import Path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pp = Path(zip_file).stem[14:16] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
count = pp[0] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
h_or_v = pp[1] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if count == "S" and pol_type in ["dual-pol", "cross-pol"]: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
raise ValueError(f"{zip_file} is single-pol. Unable to process {pol_type}") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if pol_type == "dual-pol": | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
raise NotImplementedError("TODO") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if h_or_v == "H": | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return ["hh", "hv"] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return ["vv", "vh"] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
elif pol_type == "cross-pol": | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return 'hv' if h_or_v == "H" else "vh" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
elif pol_type == "co-pol": | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return 'hh' if h_or_v == "H" else "vv" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
raise ValueError(f"Invalid {pol_type = }") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+152
to
+165
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Early returns for readability |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def _get_burst_epsg_and_bbox(burst, output_epsg, bbox, bbox_epsg, burst_db_file): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"""Returns the EPSG code and bounding box for a burst. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -437,7 +465,7 @@ def run(slc_dir, dem_file, burst_id=None, common_bursts_only=False, start_date=N | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
info.log(f'Generating burst map for {len(zip_file_list)} SAFE files') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
burst_map = generate_burst_map( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
zip_file_list, orbit_dir, output_epsg, bbox, bbox_epsg, burst_db_file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
zip_file_list, orbit_dir, output_epsg, bbox, bbox_epsg, burst_db_file, pol_type=pol | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Identify burst IDs common across the stack and remove from the dataframe | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to mention what values are expected for
pol_type
in the docstring.