Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch to get correct line coordinates in the range noise dataset for SLC products #204

Merged
merged 9 commits into from
May 14, 2024

Conversation

agrouaze
Copy link
Member

@agrouaze agrouaze commented Mar 29, 2024

issue in the data IW SLC documented here:
https://jira-projects.cls.fr/browse/MPCS-3581 and https://github.com/umr-lops/xsar_slc/issues/175
to replace umr-lops/xarray-safe-s1#20
An example of product which needs correction:
safe = '/home/datawork-cersat-public/cache/project/mpc-sentinel1/data/esa/sentinel-1a/L1/IW/S1A_IW_SLC__1S/2021/026/S1A_IW_SLC__1SDV_20210126T154330_20210126T154357_036311_0442A0_0003.SAFE' #subswath 1 -> shift 1503 lines

  • check IW SLC
  • check EW SLC -> found an issue, line_jump_meas=14 while line_jump_noise=15 -> we exclude EW from this patch for now.
  • check IW GRD (not concerned by the correction)
  • check IW SL2 (currently azimuth time used to correct is not OK -> cannot check it properly)
  • check WV SLC (not concerned by the correction)
  • check EW GRD (not concerned by the correction)
  • compile sphinx doc
  • test over 300 slice IW SLC (900 subswath)

@agrouaze agrouaze self-assigned this Mar 29, 2024
@agrouaze agrouaze added the enhancement New feature or request label Mar 29, 2024
@agrouaze
Copy link
Member Author

for EW SLC the correction cannot be done for now:

ValueError                                Traceback (most recent call last)
Cell In[23], line 9
      7 reload(xsar)
      8 print(xsar.__file__)
----> 9 handlerS1 = xsar.Sentinel1Dataset(prod_name)
     10 # obxsar = xsar.open_dataset(prod_name)
     11 # obxsar
     12 handlerS1.datatree

File [/home1/datahome/agrouaze/sources/git/xsar/src/xsar/sentinel1_dataset.py:297](http://grougrou1:8888/home1/datahome/agrouaze/sources/git/xsar/src/xsar/sentinel1_dataset.py#line=296), in Sentinel1Dataset.__init__(***failed resolving arguments***)
    295 self.datatree['measurement'].attrs = self.datatree.attrs
    296 if self.sar_meta.product == 'SLC' and 'WV' not in self.sar_meta.swath:  # TOPS cases
--> 297     tmp = self.corrected_range_noise_lut(self.datatree)
    298     self.datatree['noise_range'].ds = tmp # the corrcted noise_range dataset shold now contain an attrs 'corrected_range_noise_lut'
    299 self.sliced = False

File [/home1/datahome/agrouaze/sources/git/xsar/src/xsar/sentinel1_dataset.py:323](http://grougrou1:8888/home1/datahome/agrouaze/sources/git/xsar/src/xsar/sentinel1_dataset.py#line=322), in Sentinel1Dataset.corrected_range_noise_lut(self, dt)
    321 line_jump_meas = dt['measurement']['line'][i_jump] # line number of jumps
    322 line_jump_noise = np.ravel(dt['noise_range']['line'][1:-1].data) # annotated line number of burst begining, this one is corrupted for some S1 TOPS product
--> 323 burst_first_lineshift = line_jump_meas-line_jump_noise
    324 if len(np.unique(burst_first_lineshift))==1:
    325     line_shift = int(np.unique(burst_first_lineshift)[0])

File [/opt/conda-envs/dev/lib/python3.10/site-packages/xarray/core/_typed_ops.py:248](http://grougrou1:8888/opt/conda-envs/dev/lib/python3.10/site-packages/xarray/core/_typed_ops.py#line=247), in DataArrayOpsMixin.__sub__(self, other)
    247 def __sub__(self, other: DaCompatible) -> Self:
--> 248     return self._binary_op(other, operator.sub)

File [/opt/conda-envs/dev/lib/python3.10/site-packages/xarray/core/dataarray.py:4657](http://grougrou1:8888/opt/conda-envs/dev/lib/python3.10/site-packages/xarray/core/dataarray.py#line=4656), in DataArray._binary_op(self, other, f, reflexive)
   4653 other_variable_or_arraylike: DaCompatible = getattr(other, "variable", other)
   4654 other_coords = getattr(other, "coords", None)
   4656 variable = (
-> 4657     f(self.variable, other_variable_or_arraylike)
   4658     if not reflexive
   4659     else f(other_variable_or_arraylike, self.variable)
   4660 )
   4661 coords, indexes = self.coords._merge_raw(other_coords, reflexive)
   4662 name = self._result_name(other)

File [/opt/conda-envs/dev/lib/python3.10/site-packages/xarray/core/_typed_ops.py:476](http://grougrou1:8888/opt/conda-envs/dev/lib/python3.10/site-packages/xarray/core/_typed_ops.py#line=475), in VariableOpsMixin.__sub__(self, other)
    475 def __sub__(self, other: VarCompatible) -> Self | T_DataArray:
--> 476     return self._binary_op(other, operator.sub)

File [/opt/conda-envs/dev/lib/python3.10/site-packages/xarray/core/variable.py:2414](http://grougrou1:8888/opt/conda-envs/dev/lib/python3.10/site-packages/xarray/core/variable.py#line=2413), in Variable._binary_op(self, other, f, reflexive)
   2411 attrs = self._attrs if keep_attrs else None
   2412 with np.errstate(all="ignore"):
   2413     new_data = (
-> 2414         f(self_data, other_data) if not reflexive else f(other_data, self_data)
   2415     )
   2416 result = Variable(dims, new_data, attrs=attrs)
   2417 return result

ValueError: operands could not be broadcast together with shapes (14,) (15,)

to be tested with :
SENTINEL1_DS:/home/datawork-cersat-public/cache/project/mpc-sentinel1/data/esa/sentinel-1a/L1/EW/S1A_EW_SLC__1S/2018/272/S1A_EW_SLC__1SDH_20180929T054258_20180929T054346_023909_029C29_88FD.SAFE:EW1

@agrouaze agrouaze requested a review from lanougue March 29, 2024 16:20
@agrouaze
Copy link
Member Author

agrouaze commented Apr 2, 2024

for EW SLC the correction cannot be done for now:

ValueError                                Traceback (most recent call last)
Cell In[23], line 9
      7 reload(xsar)
      8 print(xsar.__file__)
----> 9 handlerS1 = xsar.Sentinel1Dataset(prod_name)
     10 # obxsar = xsar.open_dataset(prod_name)
     11 # obxsar
     12 handlerS1.datatree

File [/home1/datahome/agrouaze/sources/git/xsar/src/xsar/sentinel1_dataset.py:297](http://grougrou1:8888/home1/datahome/agrouaze/sources/git/xsar/src/xsar/sentinel1_dataset.py#line=296), in Sentinel1Dataset.__init__(***failed resolving arguments***)
    295 self.datatree['measurement'].attrs = self.datatree.attrs
    296 if self.sar_meta.product == 'SLC' and 'WV' not in self.sar_meta.swath:  # TOPS cases
--> 297     tmp = self.corrected_range_noise_lut(self.datatree)
    298     self.datatree['noise_range'].ds = tmp # the corrcted noise_range dataset shold now contain an attrs 'corrected_range_noise_lut'
    299 self.sliced = False

File [/home1/datahome/agrouaze/sources/git/xsar/src/xsar/sentinel1_dataset.py:323](http://grougrou1:8888/home1/datahome/agrouaze/sources/git/xsar/src/xsar/sentinel1_dataset.py#line=322), in Sentinel1Dataset.corrected_range_noise_lut(self, dt)
    321 line_jump_meas = dt['measurement']['line'][i_jump] # line number of jumps
    322 line_jump_noise = np.ravel(dt['noise_range']['line'][1:-1].data) # annotated line number of burst begining, this one is corrupted for some S1 TOPS product
--> 323 burst_first_lineshift = line_jump_meas-line_jump_noise
    324 if len(np.unique(burst_first_lineshift))==1:
    325     line_shift = int(np.unique(burst_first_lineshift)[0])

File [/opt/conda-envs/dev/lib/python3.10/site-packages/xarray/core/_typed_ops.py:248](http://grougrou1:8888/opt/conda-envs/dev/lib/python3.10/site-packages/xarray/core/_typed_ops.py#line=247), in DataArrayOpsMixin.__sub__(self, other)
    247 def __sub__(self, other: DaCompatible) -> Self:
--> 248     return self._binary_op(other, operator.sub)

File [/opt/conda-envs/dev/lib/python3.10/site-packages/xarray/core/dataarray.py:4657](http://grougrou1:8888/opt/conda-envs/dev/lib/python3.10/site-packages/xarray/core/dataarray.py#line=4656), in DataArray._binary_op(self, other, f, reflexive)
   4653 other_variable_or_arraylike: DaCompatible = getattr(other, "variable", other)
   4654 other_coords = getattr(other, "coords", None)
   4656 variable = (
-> 4657     f(self.variable, other_variable_or_arraylike)
   4658     if not reflexive
   4659     else f(other_variable_or_arraylike, self.variable)
   4660 )
   4661 coords, indexes = self.coords._merge_raw(other_coords, reflexive)
   4662 name = self._result_name(other)

File [/opt/conda-envs/dev/lib/python3.10/site-packages/xarray/core/_typed_ops.py:476](http://grougrou1:8888/opt/conda-envs/dev/lib/python3.10/site-packages/xarray/core/_typed_ops.py#line=475), in VariableOpsMixin.__sub__(self, other)
    475 def __sub__(self, other: VarCompatible) -> Self | T_DataArray:
--> 476     return self._binary_op(other, operator.sub)

File [/opt/conda-envs/dev/lib/python3.10/site-packages/xarray/core/variable.py:2414](http://grougrou1:8888/opt/conda-envs/dev/lib/python3.10/site-packages/xarray/core/variable.py#line=2413), in Variable._binary_op(self, other, f, reflexive)
   2411 attrs = self._attrs if keep_attrs else None
   2412 with np.errstate(all="ignore"):
   2413     new_data = (
-> 2414         f(self_data, other_data) if not reflexive else f(other_data, self_data)
   2415     )
   2416 result = Variable(dims, new_data, attrs=attrs)
   2417 return result

ValueError: operands could not be broadcast together with shapes (14,) (15,)

to be tested with : SENTINEL1_DS:/home/datawork-cersat-public/cache/project/mpc-sentinel1/data/esa/sentinel-1a/L1/EW/S1A_EW_SLC__1S/2018/272/S1A_EW_SLC__1SDH_20180929T054258_20180929T054346_023909_029C29_88FD.SAFE:EW1

Solution proposed by @lanougue :
line_jump_noise = np.ravel(dt['noise_range']['line'][1:1+len(line_jump_meas)].data) # annoted line number of burst begining

@agrouaze
Copy link
Member Author

agrouaze commented May 6, 2024

still an issue with S1A_IW_SLC__1SDV_20170907T102951_20170907T103021_018268_01EB76_AE7B.SAFE:

ValueError                                Traceback (most recent call last)
Cell In[2], line 5
      3 for subswath in multids.subdatasets.index:
      4     print(subswath)
----> 5     onesubswath = xsar.Sentinel1Dataset(subswath)
      6     print(onesubswath.get_bursts_polygons()['geometry'])

File ~/Documents/sources/xsar/src/xsar/sentinel1_dataset.py:297, in Sentinel1Dataset.__init__(***failed resolving arguments***)
    295 self.datatree['measurement'].attrs = self.datatree.attrs
    296 if "SLC" in str(self.datatree.attrs['product']) and 'WV' not in self.sar_meta.swath: # only TOPS IW or EW SLC
--> 297     tmp = self.corrected_range_noise_lut(self.datatree)
    298     self.datatree['noise_range'].ds = tmp # the corrected noise_range dataset should now contain an attrs 'corrected_range_noise_lut'
    299     # self.datatree = self.corrected_range_noise_lut(self.datatree)

File ~/Documents/sources/xsar/src/xsar/sentinel1_dataset.py:324, in Sentinel1Dataset.corrected_range_noise_lut(self, dt)
    322 line_jump_meas = dt['measurement']['line'][i_jump] # line number of jumps
    323 line_jump_noise = np.ravel(dt['noise_range']['line'][1:-1].data) # annotated line number of burst begining
--> 324 burst_first_lineshift = line_jump_meas-line_jump_noise
    325 if len(np.unique(burst_first_lineshift))==1:
    326     line_shift = int(np.unique(burst_first_lineshift)[0])

File ~/micromamba/envs/micromamba1/lib/python3.10/site-packages/xarray/core/_typed_ops.py:248, in DataArrayOpsMixin.__sub__(self, other)
    247 def __sub__(self, other: DaCompatible) -> Self:
--> 248     return self._binary_op(other, operator.sub)

File ~/micromamba/envs/micromamba1/lib/python3.10/site-packages/xarray/core/dataarray.py:4687, in DataArray._binary_op(self, other, f, reflexive)
   4683 other_variable_or_arraylike: DaCompatible = getattr(other, "variable", other)
   4684 other_coords = getattr(other, "coords", None)
   4686 variable = (
-> 4687     f(self.variable, other_variable_or_arraylike)
   4688     if not reflexive
   4689     else f(other_variable_or_arraylike, self.variable)
   4690 )
   4691 coords, indexes = self.coords._merge_raw(other_coords, reflexive)
   4692 name = self._result_name(other)

File ~/micromamba/envs/micromamba1/lib/python3.10/site-packages/xarray/core/_typed_ops.py:476, in VariableOpsMixin.__sub__(self, other)
    475 def __sub__(self, other: VarCompatible) -> Self | T_DataArray:
--> 476     return self._binary_op(other, operator.sub)

File ~/micromamba/envs/micromamba1/lib/python3.10/site-packages/xarray/core/variable.py:2411, in Variable._binary_op(self, other, f, reflexive)
   2408 attrs = self._attrs if keep_attrs else None
   2409 with np.errstate(all="ignore"):
   2410     new_data = (
-> 2411         f(self_data, other_data) if not reflexive else f(other_data, self_data)
   2412     )
   2413 result = Variable(dims, new_data, attrs=attrs)
   2414 return result

ValueError: operands could not be broadcast together with shapes (9,) (10,) 

You can ignore this error by setting the following in conf.py:

    nbsphinx_allow_errors = True

make: *** [Makefile:21: html] Error 2

…and_denoising() for SLC product, since these methods are not computed correctly/optimaly and xsarslc library is dedicated to such calculus
…hin xsar, for TOPS we know xsarslc will do better
@agrouaze
Copy link
Member Author

agrouaze commented May 6, 2024

still an issue with S1A_IW_SLC__1SDV_20170907T102951_20170907T103021_018268_01EB76_AE7B.SAFE:

ValueError                                Traceback (most recent call last)
Cell In[2], line 5
      3 for subswath in multids.subdatasets.index:
      4     print(subswath)
----> 5     onesubswath = xsar.Sentinel1Dataset(subswath)
      6     print(onesubswath.get_bursts_polygons()['geometry'])

File ~/Documents/sources/xsar/src/xsar/sentinel1_dataset.py:297, in Sentinel1Dataset.__init__(***failed resolving arguments***)
    295 self.datatree['measurement'].attrs = self.datatree.attrs
    296 if "SLC" in str(self.datatree.attrs['product']) and 'WV' not in self.sar_meta.swath: # only TOPS IW or EW SLC
--> 297     tmp = self.corrected_range_noise_lut(self.datatree)
    298     self.datatree['noise_range'].ds = tmp # the corrected noise_range dataset should now contain an attrs 'corrected_range_noise_lut'
    299     # self.datatree = self.corrected_range_noise_lut(self.datatree)

File ~/Documents/sources/xsar/src/xsar/sentinel1_dataset.py:324, in Sentinel1Dataset.corrected_range_noise_lut(self, dt)
    322 line_jump_meas = dt['measurement']['line'][i_jump] # line number of jumps
    323 line_jump_noise = np.ravel(dt['noise_range']['line'][1:-1].data) # annotated line number of burst begining
--> 324 burst_first_lineshift = line_jump_meas-line_jump_noise
    325 if len(np.unique(burst_first_lineshift))==1:
    326     line_shift = int(np.unique(burst_first_lineshift)[0])

File ~/micromamba/envs/micromamba1/lib/python3.10/site-packages/xarray/core/_typed_ops.py:248, in DataArrayOpsMixin.__sub__(self, other)
    247 def __sub__(self, other: DaCompatible) -> Self:
--> 248     return self._binary_op(other, operator.sub)

File ~/micromamba/envs/micromamba1/lib/python3.10/site-packages/xarray/core/dataarray.py:4687, in DataArray._binary_op(self, other, f, reflexive)
   4683 other_variable_or_arraylike: DaCompatible = getattr(other, "variable", other)
   4684 other_coords = getattr(other, "coords", None)
   4686 variable = (
-> 4687     f(self.variable, other_variable_or_arraylike)
   4688     if not reflexive
   4689     else f(other_variable_or_arraylike, self.variable)
   4690 )
   4691 coords, indexes = self.coords._merge_raw(other_coords, reflexive)
   4692 name = self._result_name(other)

File ~/micromamba/envs/micromamba1/lib/python3.10/site-packages/xarray/core/_typed_ops.py:476, in VariableOpsMixin.__sub__(self, other)
    475 def __sub__(self, other: VarCompatible) -> Self | T_DataArray:
--> 476     return self._binary_op(other, operator.sub)

File ~/micromamba/envs/micromamba1/lib/python3.10/site-packages/xarray/core/variable.py:2411, in Variable._binary_op(self, other, f, reflexive)
   2408 attrs = self._attrs if keep_attrs else None
   2409 with np.errstate(all="ignore"):
   2410     new_data = (
-> 2411         f(self_data, other_data) if not reflexive else f(other_data, self_data)
   2412     )
   2413 result = Variable(dims, new_data, attrs=attrs)
   2414 return result

ValueError: operands could not be broadcast together with shapes (9,) (10,) 

You can ignore this error by setting the following in conf.py:

    nbsphinx_allow_errors = True

make: *** [Makefile:21: html] Error 2

this issue is solved with latest patch.

@agrouaze agrouaze merged commit 9ea17e7 into develop May 14, 2024
1 of 2 checks passed
@agrouaze agrouaze deleted the rangenoisepatchMarch2024 branch May 14, 2024 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant