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

`history` attr missing for `noise_lut_range` #207

Closed agrouaze closed 1 month ago

agrouaze commented 1 month ago

traceback

In [1]: import safe_s1

In [2]: safe_s1.__version__
Out[2]: '2024.5.6'

In [3]: import xsar

In [4]: xsar.__version__
Out[4]: '2024.5.15'

In [5]: import xsar
   ...: L1_path = "/home/datawork-cersat-public/cache/project/mpc-sentinel1/data/esa/sentinel-1a/L1/IW/
   ...: S1A_IW_GRDH_1S/2021/001/S1A_IW_GRDH_1SDH_20210101T102321_20210101T102346_035943_0435C4_D007.SAF
   ...: E"
   ...: %timeit ds = xsar.Sentinel1Dataset(L1_path, resolution='1000m')
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In[5], line 3
      1 import xsar
      2 L1_path = "/home/datawork-cersat-public/cache/project/mpc-sentinel1/data/esa/sentinel-1a/L1/IW/S1A_IW_GRDH_1S/2021/001/S1A_IW_GRDH_1SDH_20210101T102321_20210101T102346_035943_0435C4_D007.SAFE"      
----> 3 get_ipython().run_line_magic('timeit', "ds = xsar.Sentinel1Dataset(L1_path, resolution='1000m')")

File ~/.local/lib/python3.10/site-packages/IPython/core/interactiveshell.py:2454, in InteractiveShell.run_line_magic(self, magic_name, line, _stack_depth)
   2452     kwargs['local_ns'] = self.get_local_scope(stack_depth)
   2453 with self.builtin_trap:
-> 2454     result = fn(*args, **kwargs)
   2456 # The code below prevents the output from being displayed
   2457 # when using magics with decorator @output_can_be_silenced
   2458 # when the last Python token in the expression is a ';'.
   2459 if getattr(fn, magic.MAGIC_OUTPUT_CAN_BE_SILENCED, False):

File ~/.local/lib/python3.10/site-packages/IPython/core/magics/execution.py:1185, in ExecutionMagics.timeit(self, line, cell, local_ns)
   1183 for index in range(0, 10):
   1184     number = 10 ** index
-> 1185     time_number = timer.timeit(number)
   1186     if time_number >= 0.2:
   1187         break

File ~/.local/lib/python3.10/site-packages/IPython/core/magics/execution.py:173, in Timer.timeit(self, number)
    171 gc.disable()
    172 try:
--> 173     timing = self.inner(it, self.timer)
    174 finally:
    175     if gcold:

File <magic-timeit>:1, in inner(_it, _timer)

File /opt/conda-envs/xsar_28nov22_3/lib/python3.10/site-packages/xsar/sentinel1_dataset.py:297, in Sentinel1Dataset.__init__(***failed resolving arguments***)
    293 self.datatree.attrs.update(self.sar_meta.to_dict("all"))
    295 # load land_mask by default for GRD products
--> 297 self.add_high_resolution_variables(
    298     patch_variable=patch_variable, luts=luts, lazy_loading=lazyloading)
    299 if 'GRD' in str(self.datatree.attrs['product']):
    300     if self.apply_recalibration:

File /opt/conda-envs/xsar_28nov22_3/lib/python3.10/site-packages/xsar/sentinel1_dataset.py:475, in Sentinel1Dataset.add_high_resolution_variables(self, luts, patch_variable, skip_variables, load_luts, lazy_loading)
    473 self._patch_variable = patch_variable
    474 if load_luts:
--> 475     self._luts = self._lazy_load_luts(self._map_lut_files.keys())
    477     # noise_lut is noise_lut_range * noise_lut_azi
    478     if 'noise_lut_range' in self._luts.keys() and 'noise_lut_azi' in self._luts.keys():

File /opt/conda-envs/xsar_28nov22_3/lib/python3.10/site-packages/xsar/utils.py:95, in timing.<locals>.wrapper(*args, **kwargs)
     93     startrss = process.memory_info().rss
     94 starttime = time.time()
---> 95 result = f(*args, **kwargs)
     96 endtime = time.time()
     97 if mem_monitor:

File /opt/conda-envs/xsar_28nov22_3/lib/python3.10/site-packages/xsar/sentinel1_dataset.py:1092, in Sentinel1Dataset._lazy_load_luts(self, luts_names)
   1089     lut = lut.assign_coords(pol=pol).expand_dims('pol')
   1091 # set xml file and xpath used as history
-> 1092 histo = raw_lut.attrs['history']
   1093 lut.name = lut_name
   1094 if self._patch_variable:

KeyError: 'history'
agrouaze commented 1 month ago

this issue has been spot by @vincelhx after the release of version 2024.5.15 that was succesfully buidl on all python versions and all OS + successful doc compilation on my dev environement. So on top of the problem itself I have to investigate why this bug went through this "security" protocol.

agrouaze commented 1 month ago

fixed by https://github.com/umr-lops/xarray-safe-s1/pull/29

agrouaze commented 1 month ago

attributes kept with https://github.com/umr-lops/xsar/pull/208