umr-lops / xsar

Synthetic Aperture Radar (SAR) Level-1 GRD python mapper for efficient xarray/dask based processing
https://cyclobs.ifremer.fr/static/sarwing_datarmor/xsar/
MIT License
24 stars 8 forks source link

footprint / index issue WV product #80

Closed agrouaze closed 2 years ago

agrouaze commented 2 years ago

issue spotted by https://github.com/owenod1 `Salut, when using xsar's .footprint function on sentinel-1 WV train metadata the returned imagette footprints appear to follow a different sorting than the file listing (e.g. footprints 3,4 and 5 belongs to imagettes 23, 21 and 22). When retrieving the imagette footprints from the subdataset directly the footprints are sorted correctly but this requires to open the subdatasets individually. Is there a xsar way to connect the correct footprints directly to files without having to open the individual subdatasets?

example of the issue:

train = '/home/datawork-cersat-public/cache/project/mpc-sentinel1/data/esa/sentinel-1a/L1/WV/S1A_WV_SLC__1S/2019/328/S1A_WV_SLC__1SSV_20191124T112814_20191124T113354_030052_036E86_6C90.SAFE'
right = [xsar.open_dataset(i).footprint.centroid.coords[0] for i in xsar.Sentinel1Meta(train).subdatasets]  # slow but correct
wrong = [i.centroid.coords[0] for i in xsar.Sentinel1Meta(train).footprint] # fast but unsorted

image

here a correct decreasing latitude is shown for descending train when loading the footprints individually, but when loading the footprints from the metadata directly the latitudes (and thus the footprints) follow an incorrect pattern `

oarcher commented 2 years ago

The problem is that for a multidataset, the returned geometry is a union from all geometries, that are unorderded:

https://github.com/umr-lops/xsar/blob/develop/src/xsar/sentinel1_meta.py#L364-L369

There is s1meta.manifest_attrs['footprints'] that should be an ordered list.

Can you try with

[i.centroid.coords[0] for i in xsar.Sentinel1Meta(train).manifest_attrs['footprints']`] 
owenodriscoll commented 2 years ago

This works, thanks

oarcher commented 2 years ago

Perhaps that there is a way to make it clearer for the user.

currently, s1meta.subdatasets and s1meta.manifest_attrs['footprints'] are zippable list.

We might consider to make s1meta.subdatasets be a geodataframe, with index from subdatasets, and geometry from manifest_attrs['footprints']

oarcher commented 2 years ago

The above solution won't works with TOPS SLC products, because there is only one footprint in s1meta.manifest_attrs['footprints'] ( the global one ).

What we can do for TOPS SLC is:

cc @agrouaze

oarcher commented 2 years ago

In #81, I've choose to recursively open all TOPS _IW_SLC_ subdatasets, to get their individual footprint.

This slow down a little the product opening, but I think it's an acceptable solution, as the subdataset count is low (3)

@owenodriscoll , can you try my fork (pip install git+https://github.com/oarcher/xsar)?

You should now use

[i.centroid.coords[0] for i in xsar.Sentinel1Meta(train).subdatasets.geometry]

cc @rmarquarlops, I think you will have to update you code after this PR is merged

owenodriscoll commented 2 years ago

@oarcher the code works using your fork, cheers