84 support snap ou#106
Draft
rogerkuou wants to merge 7 commits into
Draft
Conversation
Contributor
There was a problem hiding this comment.
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_DATALAYERplus ZNAP variable-name constants inconf.py. - Refactor
from_snap_datasetto use_read_one_znap_archive, build a time stack, and derivecomplex/amplitude/phase. - Add
_read_one_znap_archivehelper 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 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 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 | ||
|
|
| return metadata | ||
|
|
||
|
|
||
| def _read_one_znap_archive(file: str | Path) -> (xr.Dataset, bool): |
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 |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.