From 91c1c23303a516e8851d689623fb7ba4e849eaf5 Mon Sep 17 00:00:00 2001 From: BuddyVolly Date: Thu, 16 Sep 2021 11:06:00 +0200 Subject: [PATCH 1/3] downgrade gdal minimum for colab env --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 7eedf4d6..3d0495c2 100755 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ descartes fiona>=1.8 -gdal>=3 +gdal>=2 godale geopandas>=0.8 jupyterlab>=1.2 From 0de23f01fe0f455e29a225ff07a12c264ba179ca Mon Sep 17 00:00:00 2001 From: BuddyVolly Date: Thu, 16 Sep 2021 11:18:01 +0200 Subject: [PATCH 2/3] downgarde other req for colab env --- requirements.txt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/requirements.txt b/requirements.txt index 3d0495c2..f1868e88 100755 --- a/requirements.txt +++ b/requirements.txt @@ -1,20 +1,20 @@ descartes -fiona>=1.8 +fiona gdal>=2 godale geopandas>=0.8 -jupyterlab>=1.2 +jupyterlab matplotlib -numpy>=1.19 -pandas>=1.1 +numpy +pandas psycopg2-binary -rasterio>=1.1 -requests>=2.2 -scipy>=1.5 +rasterio +requests +scipy shapely -tqdm>=4.51 +tqdm imageio -rtree>=0.9 +rtree retrying pytest pytest-cov From 4ff7b483dac3a26d01108ccaff29091ed13f3013 Mon Sep 17 00:00:00 2001 From: BuddyVolly Date: Thu, 16 Sep 2021 16:30:57 +0200 Subject: [PATCH 3/3] complete full osgeo import compatability --- ost/generic/ard_to_ts.py | 7 ++++--- ost/generic/mosaic.py | 7 ++++--- ost/generic/ts_ls_mask.py | 2 +- ost/helpers/db.py | 7 ++++--- ost/helpers/helpers.py | 8 ++++---- ost/helpers/raster.py | 7 ++++--- ost/helpers/vector.py | 11 +++++++++-- 7 files changed, 30 insertions(+), 19 deletions(-) diff --git a/ost/generic/ard_to_ts.py b/ost/generic/ard_to_ts.py index 550de496..ee7f0b3e 100644 --- a/ost/generic/ard_to_ts.py +++ b/ost/generic/ard_to_ts.py @@ -11,9 +11,10 @@ try: import gdal except ModuleNotFoundError as e: - from osgeo import gdal -except ModuleNotFoundError as e: - raise e + try: + from osgeo import gdal + except ModuleNotFoundError: + raise e from ost.generic.common_wrappers import create_stack, mt_speckle_filter from ost.helpers import raster as ras, helpers as h diff --git a/ost/generic/mosaic.py b/ost/generic/mosaic.py index 1d07827d..1a563bb9 100644 --- a/ost/generic/mosaic.py +++ b/ost/generic/mosaic.py @@ -13,9 +13,10 @@ try: import gdal except ModuleNotFoundError as e: - from osgeo import gdal -except ModuleNotFoundError as e: - raise e + try: + from osgeo import gdal + except ModuleNotFoundError: + raise e from ost.helpers import vector as vec from ost.helpers import helpers as h diff --git a/ost/generic/ts_ls_mask.py b/ost/generic/ts_ls_mask.py index 6e7359b7..fbc8ebb1 100644 --- a/ost/generic/ts_ls_mask.py +++ b/ost/generic/ts_ls_mask.py @@ -18,7 +18,7 @@ except ModuleNotFoundError: raise e -from ost.helpers import raster as ras, vector as vec +from ost.helpers import vector as vec logger = logging.getLogger(__name__) diff --git a/ost/helpers/db.py b/ost/helpers/db.py index e411c6b3..e8e383b3 100644 --- a/ost/helpers/db.py +++ b/ost/helpers/db.py @@ -16,9 +16,10 @@ try: import ogr except ModuleNotFoundError as e: - from osgeo import ogr -except ModuleNotFoundError as e: - raise e + try: + from osgeo import ogr + except ModuleNotFoundError: + raise e from ost.helpers.vector import get_proj4, reproject_geometry diff --git a/ost/helpers/helpers.py b/ost/helpers/helpers.py index ac948d7e..497b6455 100644 --- a/ost/helpers/helpers.py +++ b/ost/helpers/helpers.py @@ -19,10 +19,10 @@ try: import gdal except ModuleNotFoundError as e: - from osgeo import gdal -except ModuleNotFoundError as e: - raise e - + try: + from osgeo import gdal + except ModuleNotFoundError: + raise e logger = logging.getLogger(__name__) diff --git a/ost/helpers/raster.py b/ost/helpers/raster.py index 6ac72182..e29671ff 100644 --- a/ost/helpers/raster.py +++ b/ost/helpers/raster.py @@ -15,9 +15,10 @@ try: import gdal except ModuleNotFoundError as e: - from osgeo import gdal -except ModuleNotFoundError as e: - raise e + try: + from osgeo import gdal + except ModuleNotFoundError: + raise e import fiona import imageio diff --git a/ost/helpers/vector.py b/ost/helpers/vector.py index 4b3e3267..89dd33e7 100644 --- a/ost/helpers/vector.py +++ b/ost/helpers/vector.py @@ -3,12 +3,19 @@ from functools import partial from pathlib import Path -import osr -import warnings import pyproj import geopandas as gpd import logging +# osgeo safe imports +try: + import osr +except ModuleNotFoundError as e: + try: + from osgeo import osr + except ModuleNotFoundError: + raise e + try: import ogr except ModuleNotFoundError as e: