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

land mask rasterization is not working with SLC products read with a resolution coarser than native's one #127

Closed agrouaze closed 1 year ago

agrouaze commented 1 year ago

error

ValueError                                Traceback (most recent call last)
Cell In [3], line 9
      7 fig_path = '/tmp/ksdjflksdjfd.png'
      8 sarim_rough = xsar.Sentinel1Dataset(str_gdal, resolution='%sm' % 50)
----> 9 sarim_rough.add_high_resolution_variables()
     10 heading = sarim_rough.dataset.platform_heading
     11 print('heading',heading)

File /home1/datahome/agrouaze/sources/git/xsar/src/xsar/sentinel1_dataset.py:379, in Sentinel1Dataset.add_high_resolution_variables(self, luts, patch_variable)
    377 if self.s1meta.product == 'SLC' and 'WV' not in self.s1meta.swath: # TOPS cases
    378     logger.debug('a TOPS product')
--> 379     self.land_mask_slc_per_bursts() # replace "GRD" like (Affine transform) land_mask by a burst-by-burst rasterised land mask
    380 else:
    381     logger.debug('not a TOPS product')

File /home1/datahome/agrouaze/sources/git/xsar/src/xsar/sentinel1_dataset.py:1197, in Sentinel1Dataset.land_mask_slc_per_bursts(self)
   1195 for kk in da_dict:
   1196     logging.info('da_dict[kk] %s',da_dict[kk])
-> 1197     complet_mask = xr.combine_by_coords(da_dict[kk])
   1198     all_masks.append(complet_mask)
   1199 tmpds = self.datatree['measurement'].to_dataset()

File /home/datawork-cersat-public/cache/project/mpc-sentinel1/workspace/mamba/envs/xsar_oct22/lib/python3.9/site-packages/xarray/core/combine.py:982, in combine_by_coords(data_objects, compat, data_vars, coords, fill_value, join, combine_attrs, datasets)
    980     concatenated_grouped_by_data_vars = []
    981     for vars, datasets_with_same_vars in grouped_by_vars:
--> 982         concatenated = _combine_single_variable_hypercube(
    983             list(datasets_with_same_vars),
    984             fill_value=fill_value,
    985             data_vars=data_vars,
    986             coords=coords,
    987             compat=compat,
    988             join=join,
    989             combine_attrs=combine_attrs,
    990         )
    991         concatenated_grouped_by_data_vars.append(concatenated)
    993 return merge(
    994     concatenated_grouped_by_data_vars,
    995     compat=compat,
   (...)
    998     combine_attrs=combine_attrs,
    999 )

File /home/datawork-cersat-public/cache/project/mpc-sentinel1/workspace/mamba/envs/xsar_oct22/lib/python3.9/site-packages/xarray/core/combine.py:629, in _combine_single_variable_hypercube(datasets, fill_value, data_vars, coords, compat, join, combine_attrs)
    623 if len(datasets) == 0:
    624     raise ValueError(
    625         "At least one Dataset is required to resolve variable names "
    626         "for combined hypercube."
    627     )
--> 629 combined_ids, concat_dims = _infer_concat_order_from_coords(list(datasets))
    631 if fill_value is None:
    632     # check that datasets form complete hypercube
    633     _check_shape_tile_ids(combined_ids)

File /home/datawork-cersat-public/cache/project/mpc-sentinel1/workspace/mamba/envs/xsar_oct22/lib/python3.9/site-packages/xarray/core/combine.py:125, in _infer_concat_order_from_coords(datasets)
    122 # Assume that any two datasets whose coord along dim starts
    123 # with the same value have the same coord values throughout.
    124 if any(index.size == 0 for index in indexes):
--> 125     raise ValueError("Cannot handle size zero dimensions")
    126 first_items = pd.Index([index[0] for index in indexes])
    128 series = first_items.to_series()

ValueError: Cannot handle size zero dimensions

the correction would be to get the right values for each burst at the resolution sought.

agrouaze commented 1 year ago

After discussion, it appears that opening SLC TOPS products at a resolution that is not the native resolution is quite unusual, and it implies to have method to mimick the trasnformation SLC -> GRD. This transformation should include burst merging, (eventually subswath merging), averaging or resampling with a variable pixel spacing (rasterio is not able to do that so far). To conclude, this capability is out of the scope of xsar and we decide not to implement it. It closes this issue.