Skip to content

84 support snap#105

Open
Simon-van-Diepen wants to merge 3 commits into
mainfrom
84-support-snap
Open

84 support snap#105
Simon-van-Diepen wants to merge 3 commits into
mainfrom
84-support-snap

Conversation

@Simon-van-Diepen

Copy link
Copy Markdown
Contributor

Adds:

  • from_snap_dataset in _io.py and as top level function, capable of reading output .znap archives from SNAP into the same output format as from_binary and from_ds
  • snap driver to read_metadata, capable of reading the relevant fields from the output json into familiar formats

from_snap_dataset takes a list of .znap archives as input, and converts them into a single xr.Dataset, where the y and x local coordinate system is replaced with azimuth and range (including offset management), and dates are automatically put in chronological order. The complex layer is recreated from the i (real) and q (imaginary) parts, and any other layers in x/y coordinates are preserved (e.g. h2ph as a (azimuth/range/time) layer and longitude as a (azimuth/range) layer.

@sonarqubecloud

Copy link
Copy Markdown

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

Adds SNAP .znap ingestion support so SNAP-produced outputs can be read into sarxarray’s standard (azimuth, range, time) stack model, including metadata parsing from SNAP’s JSON.

Changes:

  • Added from_snap_dataset(...) to load a list of SNAP .znap archives into a single xr.Dataset, rebuilding complex from i/q and carrying through additional layers.
  • Extended read_metadata(..., driver="snap") with a JSON-based parser + new SNAP regex patterns and array-shape handling.
  • Added tests and bundled SNAP .znap-style Zarr test fixtures under tests/data/zarrs/....

Reviewed changes

Copilot reviewed 54 out of 65 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
sarxarray/_io.py Implements from_snap_dataset, SNAP JSON metadata flattening/parsing, and integrates driver="snap" into read_metadata.
sarxarray/conf.py Adds SNAP metadata key patterns, array-shape hints, and unit conversion settings.
sarxarray/init.py Exposes from_snap_dataset as a top-level API.
tests/test_io.py Adds coverage for read_metadata(..., driver="snap") and from_snap_dataset(...).
tests/data/zarrs/20230331-coreg.znap/.zattrs SNAP Zarr fixture metadata for the 2023-03-31 sample.
tests/data/zarrs/20230331-coreg.znap/.zgroup Root Zarr group marker for the 2023-03-31 fixture.
tests/data/zarrs/20230331-coreg.znap/SNAP/.zgroup SNAP sub-group marker for the 2023-03-31 fixture.
tests/data/zarrs/20230331-coreg.znap/SNAP/vector_data/ground_control_points.csv SNAP vector-data fixture (GCPs).
tests/data/zarrs/20230331-coreg.znap/SNAP/vector_data/pins.csv SNAP vector-data fixture (pins).
tests/data/zarrs/20230331-coreg.znap/elevation_VV/.zarray Zarr array metadata for elevation layer.
tests/data/zarrs/20230331-coreg.znap/elevation_VV/.zattrs Zarr attrs for elevation layer.
tests/data/zarrs/20230331-coreg.znap/i_VV_31Mar2023/.zarray Zarr array metadata for I (real) layer.
tests/data/zarrs/20230331-coreg.znap/i_VV_31Mar2023/.zattrs Zarr attrs for I (real) layer.
tests/data/zarrs/20230331-coreg.znap/incident_angle/.zarray Zarr array metadata for incident angle layer.
tests/data/zarrs/20230331-coreg.znap/incident_angle/.zattrs Zarr attrs for incident angle layer.
tests/data/zarrs/20230331-coreg.znap/incident_angle/0.0 Binary Zarr chunk for incident angle layer.
tests/data/zarrs/20230331-coreg.znap/latitude/.zarray Zarr array metadata for latitude tiepoint layer.
tests/data/zarrs/20230331-coreg.znap/latitude/.zattrs Zarr attrs for latitude tiepoint layer.
tests/data/zarrs/20230331-coreg.znap/latitude/0.0 Binary Zarr chunk for latitude tiepoint layer.
tests/data/zarrs/20230331-coreg.znap/latitude_VV/.zarray Zarr array metadata for latitude full-res layer.
tests/data/zarrs/20230331-coreg.znap/latitude_VV/.zattrs Zarr attrs for latitude full-res layer.
tests/data/zarrs/20230331-coreg.znap/longitude/.zarray Zarr array metadata for longitude tiepoint layer.
tests/data/zarrs/20230331-coreg.znap/longitude/.zattrs Zarr attrs for longitude tiepoint layer.
tests/data/zarrs/20230331-coreg.znap/longitude/0.0 Binary Zarr chunk for longitude tiepoint layer.
tests/data/zarrs/20230331-coreg.znap/longitude_VV/.zarray Zarr array metadata for longitude full-res layer.
tests/data/zarrs/20230331-coreg.znap/longitude_VV/.zattrs Zarr attrs for longitude full-res layer.
tests/data/zarrs/20230331-coreg.znap/q_VV_31Mar2023/.zarray Zarr array metadata for Q (imag) layer.
tests/data/zarrs/20230331-coreg.znap/q_VV_31Mar2023/.zattrs Zarr attrs for Q (imag) layer.
tests/data/zarrs/20230331-coreg.znap/slant_range_time/.zarray Zarr array metadata for slant range time layer.
tests/data/zarrs/20230331-coreg.znap/slant_range_time/.zattrs Zarr attrs for slant range time layer.
tests/data/zarrs/20230331-coreg.znap/slant_range_time/0.0 Binary Zarr chunk for slant range time layer.
tests/data/zarrs/20230319-coreg.znap/.zattrs SNAP Zarr fixture metadata for the 2023-03-19 sample.
tests/data/zarrs/20230319-coreg.znap/.zgroup Root Zarr group marker for the 2023-03-19 fixture.
tests/data/zarrs/20230319-coreg.znap/SNAP/.zgroup SNAP sub-group marker for the 2023-03-19 fixture.
tests/data/zarrs/20230319-coreg.znap/SNAP/vector_data/ground_control_points.csv SNAP vector-data fixture (GCPs).
tests/data/zarrs/20230319-coreg.znap/SNAP/vector_data/pins.csv SNAP vector-data fixture (pins).
tests/data/zarrs/20230319-coreg.znap/h2ph_VV_19Mar2023/.zarray Zarr array metadata for extra h2ph layer.
tests/data/zarrs/20230319-coreg.znap/h2ph_VV_19Mar2023/.zattrs Zarr attrs for extra h2ph layer.
tests/data/zarrs/20230319-coreg.znap/i_VV_19Mar2023/.zarray Zarr array metadata for I (real) layer.
tests/data/zarrs/20230319-coreg.znap/i_VV_19Mar2023/.zattrs Zarr attrs for I (real) layer.
tests/data/zarrs/20230319-coreg.znap/incident_angle/.zarray Zarr array metadata for incident angle layer.
tests/data/zarrs/20230319-coreg.znap/incident_angle/.zattrs Zarr attrs for incident angle layer.
tests/data/zarrs/20230319-coreg.znap/incident_angle/0.0 Binary Zarr chunk for incident angle layer.
tests/data/zarrs/20230319-coreg.znap/latitude/.zarray Zarr array metadata for latitude tiepoint layer.
tests/data/zarrs/20230319-coreg.znap/latitude/.zattrs Zarr attrs for latitude tiepoint layer.
tests/data/zarrs/20230319-coreg.znap/latitude/0.0 Binary Zarr chunk for latitude tiepoint layer.
tests/data/zarrs/20230319-coreg.znap/longitude/.zarray Zarr array metadata for longitude tiepoint layer.
tests/data/zarrs/20230319-coreg.znap/longitude/.zattrs Zarr attrs for longitude tiepoint layer.
tests/data/zarrs/20230319-coreg.znap/longitude/0.0 Binary Zarr chunk for longitude tiepoint layer.
tests/data/zarrs/20230319-coreg.znap/q_VV_19Mar2023/.zarray Zarr array metadata for Q (imag) layer.
tests/data/zarrs/20230319-coreg.znap/q_VV_19Mar2023/.zattrs Zarr attrs for Q (imag) layer.
tests/data/zarrs/20230319-coreg.znap/slant_range_time/.zarray Zarr array metadata for slant range time layer.
tests/data/zarrs/20230319-coreg.znap/slant_range_time/.zattrs Zarr attrs for slant range time layer.
tests/data/zarrs/20230319-coreg.znap/slant_range_time/0.0 Binary Zarr chunk for slant range time layer.

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

Comment thread sarxarray/_io.py
return ds_stack


def from_snap_dataset(snap_znap_archives: list[str, Path]) -> xr.Dataset:
Comment thread sarxarray/_io.py
Comment thread sarxarray/_io.py
Comment on lines +367 to +369
cur_layer_data = full_data[epoch]["data"][
full_data[epoch]["cleaned_layer_names"][layer]
].data
Comment thread sarxarray/_io.py
Comment on lines +749 to 753
for key, pattern in patterns.items():
matches = list(filter(re.compile(pattern).match, raw_keys))
if len(matches) == 1:
results[key] = raw_results[matches[0]]
else:
Comment thread sarxarray/_io.py
Comment on lines +779 to +785
if content["data"]["type"] == "utc": # in MJD
val = datetime(2000, 1, 1) + timedelta(
days=content["data"]["elems"][0],
seconds=content["data"]["elems"][1],
microseconds=content["data"]["elems"][2],
)
val = val.timestamp()
Comment thread sarxarray/_io.py
Comment on lines +838 to 842
if time_format == "timestamp": # SNAP returns timestamps
dt = datetime.fromtimestamp(time)
else:
dt = datetime.strptime(time, time_format)
list_time.append(np.datetime64(dt).astype("datetime64[ns]"))
Comment thread sarxarray/_io.py
Comment on lines +862 to +864
regulated_array = np.zeros(
(len(arr), len(arr[0])), dtype=np.dtypes.StringDType
)
@rogerkuou

Copy link
Copy Markdown
Member

Hi @Simon-van-Diepen , I am working on reviewing this PR. I find there are some structural changes I want to suggest. I will do this by opening a new PR to this branch. For now you can ignore the Copilot suggestions. I was using them only as references

@rogerkuou

Copy link
Copy Markdown
Member

Hi @Simon-van-Diepen , while I am working on the suggestion PR, I think I can already make some comments on the test data tests/data/zarrs:

  1. It seems the metadata of image 20230319-coreg.znap is not correct. For example in .zattrs the timestamp information is 20230331. Is this error caused by corregistration itself, or by copying the metadata of 20230331? Can we have a small crop but with the corect metadata? (I am asking this because I would like to change the current behavior of getting time information from the datalayer names)
  2. The current size of metadata is 7MB, which IMO is still big (spatially 84x338). If possible, can we have a even smaller crop? like 50x50?

Thanks! Meanwhile I will continue working on my suggestion PR.

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.

Support SNAP .znap input reading Support reading metadata from SNAP corregistration results Reading binary data with separated REAL and IMAG part

3 participants