Skip to content

84 support snap ou#106

Draft
rogerkuou wants to merge 7 commits into
84-support-snapfrom
84-support-snap-ou
Draft

84 support snap ou#106
rogerkuou wants to merge 7 commits into
84-support-snapfrom
84-support-snap-ou

Conversation

@rogerkuou

Copy link
Copy Markdown
Member

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors SNAP ZNAP ingestion to better support “SNAP OU”/ZNAP-style archives by introducing explicit datalayer name patterns and a helper for reading/normalizing a single ZNAP archive, then building a stacked xr.Dataset with complex/amplitude/phase outputs.

Changes:

  • Add RE_PATTERNS_SNAP_DATALAYER plus ZNAP variable-name constants in conf.py.
  • Refactor from_snap_dataset to use _read_one_znap_archive, build a time stack, and derive complex/amplitude/phase.
  • Add _read_one_znap_archive helper to drop tiepoint dims and rename ZNAP datalayers into canonical variable names.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
sarxarray/conf.py Adds regex patterns/constants for canonicalizing SNAP ZNAP datalayer names and lists of expected ZNAP variables.
sarxarray/_io.py Refactors SNAP ZNAP reading/stacking logic and adds a helper to normalize each archive before concatenation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread sarxarray/_io.py
Comment on lines +299 to +311
# Read the metadata from the mother epoch if it exists
if ds_stack.attrs["mother_epoch"] is not None:
ds_stack.attrs["mother_epoch"] = epoch
metadata_file = f"{file}/SNAP/product_metadata.json"
metadata = read_metadata(metadata_file, driver="snap")
else:
warning_msg = (
"Mother epoch has not been identified. "
"Using first epoch for metadata instead."
)
logger.warning(warning_msg)
metadata_file = f"{snap_znap_archives[0]}/SNAP/product_metadata.json"
metadata = read_metadata(metadata_file, driver="snap")
Comment thread sarxarray/_io.py
Comment on lines +871 to +879
# Rename the data variables according to RE_PATTERNS_SNAP_DATALAYER
for layer in data.data_vars.keys():
for key, pattern in RE_PATTERNS_SNAP_DATALAYER.items():
if re.match(pattern, layer):
data = data.rename({layer: key})
# Check if mother epoch
if any(layer in data.data_vars.keys() for layer in ZNAP_DATA_VAR_MOTHER):
is_mother = True

Comment thread sarxarray/_io.py
return metadata


def _read_one_znap_archive(file: str | Path) -> (xr.Dataset, bool):
Comment thread sarxarray/_io.py
Comment on lines +255 to +272
cur_epoch = data.attrs["time_coverage_start"]
time_stamp = datetime.strptime(cur_epoch, "%Y-%m-%dT%H:%M:%S.%fZ")
epoch = time_stamp.strftime("%Y%m%d")

# If mother epoch
# keep variables ZNAP_DATA_VAR_MOTHER separately
# Assign an all zero h2ph variable
if is_mother:
data_mother = data[ZNAP_DATA_VAR_MOTHER]
data = data.drop_vars(ZNAP_DATA_VAR_MOTHER)
data = data.assign(
{"h2ph": (("y", "x"), np.zeros((data.sizes["y"], data.sizes["x"])))}
)

# Assign to ds_stack along the time dimension
if ds_stack is None: # first epoch, initialize ds_stack
ds_stack = data.expand_dims(time=[time_stamp])
# Drop attrs inherited from the first epoch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants