From 3992ebfcf8b9e30dcd330aa5d318cd154496e04f Mon Sep 17 00:00:00 2001 From: rhugonne Date: Mon, 9 Aug 2021 22:59:22 +0200 Subject: [PATCH 01/10] add optional import for opencv --- xdem/coreg.py | 6 ++++++ xdem/misc.py | 11 ++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/xdem/coreg.py b/xdem/coreg.py index 202f6357..af7f2f3f 100644 --- a/xdem/coreg.py +++ b/xdem/coreg.py @@ -917,9 +917,11 @@ def __init__(self, max_iterations=100, tolerance=0.05, rejection_scale=2.5, num_ def _fit_func(self, ref_dem: np.ndarray, tba_dem: np.ndarray, transform: Optional[rio.transform.Affine], weights: Optional[np.ndarray], verbose: bool = False): """Estimate the rigid transform from tba_dem to ref_dem.""" + if weights is not None: warnings.warn("ICP was given weights, but does not support it.") + bounds, resolution = _transform_to_bounds_and_res(ref_dem.shape, transform) points: dict[str, np.ndarray] = {} # Generate the x and y coordinates for the reference_dem @@ -1392,6 +1394,10 @@ def apply_matrix(dem: np.ndarray, transform: rio.transform.Affine, matrix: np.nd if np.mean(np.abs(empty_matrix - matrix)) == 0.0: return demc + matrix[2, 3] + # Opencv is required down from here + if not _has_cv2: + raise ValueError("Optional dependency needed. Install 'opencv'") + nan_mask = xdem.spatial_tools.get_mask(dem) assert np.count_nonzero(~nan_mask) > 0, "Given DEM had all nans." # Create a filled version of the DEM. (skimage doesn't like nans) diff --git a/xdem/misc.py b/xdem/misc.py index 697b77ca..2cac70d9 100644 --- a/xdem/misc.py +++ b/xdem/misc.py @@ -5,7 +5,12 @@ import warnings from typing import Any, Callable -import cv2 +try: + import cv2 + _has_cv2 = True +except ImportError: + _has_cv2 = False + import numpy as np import xdem.version @@ -28,6 +33,10 @@ def generate_random_field(shape: tuple[int, int], corr_size: int) -> np.ndarray: :returns: A numpy array of semi-random values from 0 to 1 """ + + if not _has_cv2: + raise ValueError("Optional dependency needed. Install 'opencv'") + field = cv2.resize( cv2.GaussianBlur( np.repeat( From 7170ce41093a09181063514e8dd00a8fadb6a25f Mon Sep 17 00:00:00 2001 From: rhugonne Date: Mon, 9 Aug 2021 22:59:45 +0200 Subject: [PATCH 02/10] provide solution for TLS import error --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index b0fef582..e025b45e 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,14 @@ conda install -c conda-forge --strict-channel-priority xdem ``` The `--strict-channel-priority` flag seems essential for Windows installs to function correctly, and is recommended for UNIX-based systems as well. +If running into the `sklearn` error `ImportError: dlopen: cannot load any more object with static TLS`, your system +needs to update its `glibc` (see details [here](https://github.com/scikit-learn/scikit-learn/issues/14485)). +If you have no administrator right on the system, you can circumvent this issue by installing an environment with a + downgraded version of scikit-learn: +```bash +mamba create -n xdem-env -c conda-forge xdem scikit-learn==0.20.3 numpy=1.19.* + +``` ### Installing with pip **NOTE**: Setting up GDAL and PROJ may need some extra steps, depending on your operating system and configuration. From 019cd814a7d710052e5239f03b3fe02b7b186b7b Mon Sep 17 00:00:00 2001 From: rhugonne Date: Tue, 10 Aug 2021 11:20:30 +0200 Subject: [PATCH 03/10] add note on mamba --- README.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e025b45e..319e64b7 100644 --- a/README.md +++ b/README.md @@ -19,12 +19,18 @@ conda install -c conda-forge --strict-channel-priority xdem ``` The `--strict-channel-priority` flag seems essential for Windows installs to function correctly, and is recommended for UNIX-based systems as well. +Solving dependencies can take a long time with `conda`. To speed up this, consider installing `mamba`: + +`conda install mamba -n base -c conda-forge` + +Once installed, the same commands can be run by simply replacing `conda` by `mamba`. More details available through the [mamba project](https://github.com/mamba-org/mamba). + If running into the `sklearn` error `ImportError: dlopen: cannot load any more object with static TLS`, your system needs to update its `glibc` (see details [here](https://github.com/scikit-learn/scikit-learn/issues/14485)). -If you have no administrator right on the system, you can circumvent this issue by installing an environment with a - downgraded version of scikit-learn: +If you have no administrator right on the system, you might be able to circumvent this issue by installing a working +environment with specific downgraded versions of `scikit-learn` and `numpy`: ```bash -mamba create -n xdem-env -c conda-forge xdem scikit-learn==0.20.3 numpy=1.19.* +conda create -n xdem-env -c conda-forge xdem scikit-learn==0.20.3 numpy=1.19.* ``` From aae5b2896780d9f70c6cf8f5755b4c0a492c0990 Mon Sep 17 00:00:00 2001 From: rhugonne Date: Tue, 10 Aug 2021 11:22:38 +0200 Subject: [PATCH 04/10] remove unused space --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 319e64b7..b9c6e280 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,6 @@ If you have no administrator right on the system, you might be able to circumven environment with specific downgraded versions of `scikit-learn` and `numpy`: ```bash conda create -n xdem-env -c conda-forge xdem scikit-learn==0.20.3 numpy=1.19.* - ``` ### Installing with pip From 8bb5d4ef3b97840cd309b9af4aaaf6ab2f20e7f0 Mon Sep 17 00:00:00 2001 From: rhugonne Date: Tue, 10 Aug 2021 12:22:45 +0200 Subject: [PATCH 05/10] bash command in appropriate box --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b9c6e280..28f6f67c 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,9 @@ The `--strict-channel-priority` flag seems essential for Windows installs to fun Solving dependencies can take a long time with `conda`. To speed up this, consider installing `mamba`: -`conda install mamba -n base -c conda-forge` +```bash +conda install mamba -n base -c conda-forge` +``` Once installed, the same commands can be run by simply replacing `conda` by `mamba`. More details available through the [mamba project](https://github.com/mamba-org/mamba). From eacdf231a7f6d668a70b96e300f4383a58d8b6da Mon Sep 17 00:00:00 2001 From: rhugonne Date: Tue, 10 Aug 2021 14:28:06 +0200 Subject: [PATCH 06/10] move cv2 import before xdem --- xdem/coreg.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/xdem/coreg.py b/xdem/coreg.py index af7f2f3f..983ae6ef 100644 --- a/xdem/coreg.py +++ b/xdem/coreg.py @@ -11,6 +11,11 @@ from enum import Enum from typing import Any, Callable, Optional, overload, Union, Sequence, TypeVar +try: + import cv2 + _has_cv2 = True +except ImportError: + _has_cv2 = False import fiona import geoutils as gu from geoutils.georaster import RasterType @@ -35,12 +40,6 @@ except ImportError: _has_rd = False -try: - import cv2 - _has_cv2 = True -except ImportError: - _has_cv2 = False - try: from pytransform3d.transform_manager import TransformManager import pytransform3d.transformations From 07fb7f29cf9ddcac521c3327dd9010444aa4ef76 Mon Sep 17 00:00:00 2001 From: rhugonne Date: Tue, 10 Aug 2021 14:58:07 +0200 Subject: [PATCH 07/10] add details of more specific fix for segmentation faults --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 28f6f67c..c14cee66 100644 --- a/README.md +++ b/README.md @@ -32,8 +32,10 @@ needs to update its `glibc` (see details [here](https://github.com/scikit-learn/ If you have no administrator right on the system, you might be able to circumvent this issue by installing a working environment with specific downgraded versions of `scikit-learn` and `numpy`: ```bash -conda create -n xdem-env -c conda-forge xdem scikit-learn==0.20.3 numpy=1.19.* +conda create -n xdem-env -c conda-forge xdem scikit-learn==0.20.3 numpy==1.19.* ``` +On very old systems, if the above install results in segmentation faults, try setting more specifically: + `numpy==1.19.2=py37h54aff64_0` (worked with Debian 8.11, GLIBC 2.19) ### Installing with pip **NOTE**: Setting up GDAL and PROJ may need some extra steps, depending on your operating system and configuration. From 666a5c903549a12c384c60f9ea607d4581ea4bb1 Mon Sep 17 00:00:00 2001 From: rhugonne Date: Tue, 10 Aug 2021 14:59:23 +0200 Subject: [PATCH 08/10] more specific link to glibc comment --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c14cee66..4c8a9ea4 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ conda install mamba -n base -c conda-forge` Once installed, the same commands can be run by simply replacing `conda` by `mamba`. More details available through the [mamba project](https://github.com/mamba-org/mamba). If running into the `sklearn` error `ImportError: dlopen: cannot load any more object with static TLS`, your system -needs to update its `glibc` (see details [here](https://github.com/scikit-learn/scikit-learn/issues/14485)). +needs to update its `glibc` (see details [here](https://github.com/scikit-learn/scikit-learn/issues/14485#issuecomment-822678559)). If you have no administrator right on the system, you might be able to circumvent this issue by installing a working environment with specific downgraded versions of `scikit-learn` and `numpy`: ```bash From 3cc7c6e3871ec764bc5485b56c0a6d130419c986 Mon Sep 17 00:00:00 2001 From: rhugonne Date: Tue, 10 Aug 2021 15:00:36 +0200 Subject: [PATCH 09/10] final polish --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4c8a9ea4..cf1a2cb3 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,8 @@ environment with specific downgraded versions of `scikit-learn` and `numpy`: ```bash conda create -n xdem-env -c conda-forge xdem scikit-learn==0.20.3 numpy==1.19.* ``` -On very old systems, if the above install results in segmentation faults, try setting more specifically: - `numpy==1.19.2=py37h54aff64_0` (worked with Debian 8.11, GLIBC 2.19) +On very old systems, if the above install results in segmentation faults, try setting more specifically +`numpy==1.19.2=py37h54aff64_0` (worked with Debian 8.11, GLIBC 2.19). ### Installing with pip **NOTE**: Setting up GDAL and PROJ may need some extra steps, depending on your operating system and configuration. From a10463cdc3d7a93f1ff9149291cf276d3be128c5 Mon Sep 17 00:00:00 2001 From: rhugonne Date: Tue, 10 Aug 2021 15:01:17 +0200 Subject: [PATCH 10/10] final polish --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cf1a2cb3..5c2494c1 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ The `--strict-channel-priority` flag seems essential for Windows installs to fun Solving dependencies can take a long time with `conda`. To speed up this, consider installing `mamba`: ```bash -conda install mamba -n base -c conda-forge` +conda install mamba -n base -c conda-forge ``` Once installed, the same commands can be run by simply replacing `conda` by `mamba`. More details available through the [mamba project](https://github.com/mamba-org/mamba).