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

Sentinel-1 datatree memory footprint multiplied by 6 (94Go) with `xsar==2024.5.15` #209

Closed agrouaze closed 1 month ago

agrouaze commented 1 month ago

The problem: in previous verison of xsar loading the datatree of a Sentinel-1 IW SLC product was using maximum 18Go of RAM. With version xsar==2024.5.15, the RAM footprint jumped to 94Go (x 6).

datatree loaded RAM usage: 94.0 Go

with previous version xsar==2024.2.1 and xarray-safe-s1==2024.1.9 is was only 11Go RAM.

to reproduce:

import xsar
import logging
logging.basicConfig(level=logging.INFO)
def get_memory_usage():
    try:
        import resource
        memory_used_go = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1000. / 1000.
    except:  # on windows resource is not usable
        import psutil
        memory_used_go = psutil.virtual_memory().used / 1000 / 1000 / 1000.
    str_mem = 'RAM usage: %1.1f Go' % memory_used_go
    return str_mem
slc_iw_path = '/home/datawork-cersat-public/project/mpc-sentinel1/data/esa/sentinel-1b/L1/IW/S1B_IW_SLC__1S/2020/319/S1B_IW_SLC__1SDV_20201114T185653_20201114T185720_024265_02E237_F25A.SAFE/measurement/s1b-iw2-slc-vh-20201114t185653-20201114t185718-024265-02e237-002.tiff'
slc_iw_path = '/home/datawork-cersat-public/project/mpc-sentinel1/data/esa/sentinel-1b/L1/IW/S1B_IW_SLC__1S/2020/319/S1B_IW_SLC__1SDV_20201114T185653_20201114T185720_024265_02E237_F25A.SAFE/:IW2'

xsarobj = xsar.Sentinel1Dataset('SENTINEL1_DS:'+slc_iw_path)
dt = xsarobj.datatree
dt.load()  # took 4min to load and 35Go RAM
logging.info('datatree loaded %s', get_memory_usage())
agrouaze commented 1 month ago

explanation the call

self.add_high_resolution_variables(patch_variable=patch_variable, luts=luts, lazy_loading=lazyloading)

has been extended to SLC products in #204 resulting in 21 variables by default in the datatree['measurement'] (while before it was only 4).