84 support znap format from SNAP#105
Conversation
There was a problem hiding this comment.
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.znaparchives into a singlexr.Dataset, rebuildingcomplexfromi/qand 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 undertests/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.
|
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 |
|
Hi @Simon-van-Diepen , while I am working on the suggestion PR, I think I can already make some comments on the test data
Thanks! Meanwhile I will continue working on my suggestion PR. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
Hi @Simon-van-Diepen , I made PR #106 as suggestions for |
After discussing with Simon:
|
PR suggestions for from_znap_dataset
|
@rogerkuou could you have another look at this PR? I have lowered the cognitive complexity of both functions but don't see a clean way to get it below 15, mainly due to various checks that need to be completed.
|
rogerkuou
left a comment
There was a problem hiding this comment.
Hi @Simon-van-Diepen, thanks!
I added more suggestions via #113. I think for complexity it is fine for now. I accept that the metadata flattening function is now 16>15.
Could please see if they make sense?
…mplexity reduce function complexity
|
Hi @rogerkuou I have taken up all your suggestions, they make sense to me. I added an extra case for if |
rogerkuou
left a comment
There was a problem hiding this comment.
Hi @Simon-van-Diepen I have one last comment on the function name. After that please feel free to merge. Thanks for this awesome implementation!
|



Adds:
from_snap_datasetin_io.pyand as top level function, capable of reading output.znaparchives from SNAP into the same output format asfrom_binaryandfrom_dssnapdriver toread_metadata, capable of reading the relevant fields from the output json into familiar formatsfrom_snap_datasettakes a list of.znaparchives as input, and converts them into a singlexr.Dataset, where theyandxlocal coordinate system is replaced withazimuthandrange(including offset management), and dates are automatically put in chronological order. Thecomplexlayer is recreated from thei(real) andq(imaginary) parts, and any other layers inx/ycoordinates are preserved (e.g.h2phas a(azimuth/range/time)layer andlongitudeas a(azimuth/range)layer.