From beceb34eda69a4a63e0821e45fc14562f3b3c1ff Mon Sep 17 00:00:00 2001 From: LHEUREUX Date: Fri, 20 Dec 2024 15:53:06 +0000 Subject: [PATCH 1/2] fix cv2 issue on datarmor --- grdwindinversion/gradientFeatures.py | 12 +++++++++--- grdwindinversion/inversion.py | 14 ++++++++++++++ grdwindinversion/main.py | 6 ++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/grdwindinversion/gradientFeatures.py b/grdwindinversion/gradientFeatures.py index 43806e9..a122a62 100644 --- a/grdwindinversion/gradientFeatures.py +++ b/grdwindinversion/gradientFeatures.py @@ -1,5 +1,4 @@ import xsarsea.gradients -import cv2 import xarray as xr import xarray as xr from scipy.ndimage import binary_dilation @@ -55,6 +54,7 @@ def _compute_gradients(self): None """ + self.gradients = xsarsea.gradients.Gradients( self.xr_dataset_100['sigma0_detrend'], windows_sizes=self.windows_sizes, @@ -111,8 +111,14 @@ def get_heterogeneity_mask(self, config): sig = xr.where(sig <= 0, 1e-15, sig) # map incidence for detrend - incidence = xr.DataArray(data=cv2.resize( - self.xr_dataset_100.incidence.values, sig.shape[::-1], cv2.INTER_NEAREST), dims=sig.dims, coords=sig.coords) + # incidence = xr.DataArray(data=cv2.resize( + # self.xr_dataset_100.incidence.values, sig.shape[::-1], cv2.INTER_NEAREST), dims=sig.dims, coords=sig.coords) + + incidence = self.xr_dataset_100.incidence.interp( + line=sig.coords['line'], + sample=sig.coords['sample'], + method="nearest" # Équivaut à INTER_NEAREST + ) sigma0_detrend = xsarsea.sigma0_detrend(sig, incidence) diff --git a/grdwindinversion/inversion.py b/grdwindinversion/inversion.py index 158c14d..77e8709 100644 --- a/grdwindinversion/inversion.py +++ b/grdwindinversion/inversion.py @@ -1,3 +1,17 @@ +## To place here in the code to not have errors with cv2. +## if placed in main => error .. +import os +os.environ["OMP_NUM_THREADS"] = "1" +os.environ["OPENBLAS_NUM_THREADS"] = "1" +os.environ["MKL_NUM_THREADS"] = "1" +os.environ["VECLIB_MAXIMUM_THREADS"] = "1" +os.environ["NUMEXPR_NUM_THREADS"] = "1" +try : + import cv2 +except: + import cv2 +cv2.setNumThreads(1) + import tempfile import traceback diff --git a/grdwindinversion/main.py b/grdwindinversion/main.py index d9456d6..af10d4d 100644 --- a/grdwindinversion/main.py +++ b/grdwindinversion/main.py @@ -25,6 +25,12 @@ def processor_starting_point(): help="En cas d'activation, désactive la génération du .csv") args = parser.parse_args() + + + + + + fmt = '%(asctime)s %(levelname)s %(filename)s(%(lineno)d) %(message)s' if args.verbose: logging.basicConfig(level=logging.DEBUG, format=fmt, From b0c31ca73f57b3092203e80df0ce62fbe02e65a2 Mon Sep 17 00:00:00 2001 From: LHEUREUX Date: Fri, 20 Dec 2024 15:54:08 +0000 Subject: [PATCH 2/2] changed log for add_nrcs --- grdwindinversion/inversion.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grdwindinversion/inversion.py b/grdwindinversion/inversion.py index 77e8709..4cae8f1 100644 --- a/grdwindinversion/inversion.py +++ b/grdwindinversion/inversion.py @@ -616,7 +616,7 @@ def preprocess(filename, outdir, config_path, overwrite=False, add_gradientsfeat add_nrcs_model = config_base["add_nrcs_model"] add_nrcs_model = False logging.warning( - f'Force this variable to be false, before fixing the issue' + f'Force add_nrcs_model to be false, before fixing an issue' ) else: add_nrcs_model = False