Repository: nansencenter/nansat (language: python)

Issue:
import gdal, osr, ogr deprecated
should now use `from osgeo import gdal, osr, ogr`
there is already a fix in `utils.py` so can change the other files to be like `domain.py` and import from `nansat.utils`
import gdal, osr, ogr deprecated
should now use `from osgeo import gdal, osr, ogr`
there is already a fix in `utils.py` so can change the other files to be like `domain.py` and import from `nansat.utils`


Discussion / hints:

Fix patch:
diff --git a/nansat/exporter.py b/nansat/exporter.py
index f5c08df34..f0fae804f 100644
--- a/nansat/exporter.py
+++ b/nansat/exporter.py
@@ -19,7 +19,7 @@
 import datetime
 import warnings
 
-import gdal
+from nansat.utils import gdal
 import numpy as np
 
 from netCDF4 import Dataset
diff --git a/nansat/geolocation.py b/nansat/geolocation.py
index 857313cca..de4e6f81b 100644
--- a/nansat/geolocation.py
+++ b/nansat/geolocation.py
@@ -14,7 +14,7 @@
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 from __future__ import absolute_import
 
-import gdal, osr
+from nansat.utils import gdal, osr
 
 from nansat.nsr import NSR
 
diff --git a/nansat/mappers/mapper_ascat.py b/nansat/mappers/mapper_ascat.py
index f6fc6ae4f..bc7effdfd 100644
--- a/nansat/mappers/mapper_ascat.py
+++ b/nansat/mappers/mapper_ascat.py
@@ -6,7 +6,7 @@
 
 from netCDF4 import Dataset
 
-import gdal
+from nansat.utils import gdal
 
 from nansat.vrt import VRT
 from nansat.geolocation import Geolocation
diff --git a/nansat/mappers/mapper_netcdf_cf.py b/nansat/mappers/mapper_netcdf_cf.py
index 350fadbd1..acaee716e 100644
--- a/nansat/mappers/mapper_netcdf_cf.py
+++ b/nansat/mappers/mapper_netcdf_cf.py
@@ -7,7 +7,7 @@
 import warnings, os, datetime
 import numpy as np
 import collections
-import gdal
+from nansat.utils import gdal
 
 from dateutil.parser import parse
 from netCDF4 import Dataset
diff --git a/nansat/mappers/mapper_opendap_sentinel1.py b/nansat/mappers/mapper_opendap_sentinel1.py
index a38a4df5d..225f95427 100644
--- a/nansat/mappers/mapper_opendap_sentinel1.py
+++ b/nansat/mappers/mapper_opendap_sentinel1.py
@@ -11,7 +11,7 @@
 
 import numpy as np
 from netCDF4 import Dataset
-import gdal
+from nansat.utils import gdal
 
 try:
     import scipy
diff --git a/nansat/mappers/mapper_opendap_sentinel2.py b/nansat/mappers/mapper_opendap_sentinel2.py
index 8451a8ba8..6cfd30b89 100644
--- a/nansat/mappers/mapper_opendap_sentinel2.py
+++ b/nansat/mappers/mapper_opendap_sentinel2.py
@@ -11,7 +11,7 @@
 
 import numpy as np
 from netCDF4 import Dataset
-import gdal
+from nansat.utils import gdal
 
 import pythesint as pti
 
diff --git a/nansat/mappers/mapper_quikscat.py b/nansat/mappers/mapper_quikscat.py
index 9e21d4424..cea6e5038 100644
--- a/nansat/mappers/mapper_quikscat.py
+++ b/nansat/mappers/mapper_quikscat.py
@@ -4,7 +4,7 @@
 from datetime import datetime
 import pythesint as pti
 
-import gdal
+from nansat.utils import gdal
 
 from nansat.vrt import VRT
 from nansat.geolocation import Geolocation
diff --git a/nansat/mappers/mapper_sentinel1_l2.py b/nansat/mappers/mapper_sentinel1_l2.py
index 11b5ae806..06bbc96f3 100644
--- a/nansat/mappers/mapper_sentinel1_l2.py
+++ b/nansat/mappers/mapper_sentinel1_l2.py
@@ -18,7 +18,7 @@
 import os
 from dateutil.parser import parse
 
-import gdal
+from nansat.utils import gdal
 
 from nansat.vrt import VRT
 from nansat.exceptions import WrongMapperError
diff --git a/nansat/mappers/scatterometers.py b/nansat/mappers/scatterometers.py
index e1f9ce10f..b6fc7268c 100644
--- a/nansat/mappers/scatterometers.py
+++ b/nansat/mappers/scatterometers.py
@@ -3,7 +3,7 @@
 from datetime import datetime
 import pythesint as pti
 
-import gdal
+from nansat.utils import gdal
 
 from nansat.vrt import VRT
 from nansat.geolocation import Geolocation
diff --git a/nansat/mappers/sentinel1.py b/nansat/mappers/sentinel1.py
index 12c9daab3..e1def6bb7 100644
--- a/nansat/mappers/sentinel1.py
+++ b/nansat/mappers/sentinel1.py
@@ -7,14 +7,13 @@
 else:
     IMPORT_SCIPY = True
 
-import gdal
 from netCDF4 import Dataset
 
 import pythesint as pti
 
 from nansat.nsr import NSR
 from nansat.vrt import VRT
-from nansat.utils import initial_bearing
+from nansat.utils import initial_bearing, gdal
 from nansat.exceptions import WrongMapperError, NansatReadError
 
 class Sentinel1(VRT):
diff --git a/nansat/nsr.py b/nansat/nsr.py
index bbfa5c5ad..0f8d81d14 100644
--- a/nansat/nsr.py
+++ b/nansat/nsr.py
@@ -14,7 +14,7 @@
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 from __future__ import absolute_import, unicode_literals
 import sys
-import osr
+from nansat.utils import osr
 
 from nansat.exceptions import NansatProjectionError
 
diff --git a/nansat/vrt.py b/nansat/vrt.py
index 5bd24efef..6263e6f8a 100644
--- a/nansat/vrt.py
+++ b/nansat/vrt.py
@@ -22,14 +22,12 @@
 import warnings
 import pythesint as pti
 
-import osr
-import gdal
 import numpy as np
 
 from nansat.node import Node
 from nansat.nsr import NSR
 from nansat.geolocation import Geolocation
-from nansat.utils import add_logger, numpy_to_gdal_type, gdal_type_to_offset, remove_keys
+from nansat.utils import add_logger, numpy_to_gdal_type, gdal_type_to_offset, remove_keys, osr, gdal
 
 from nansat.exceptions import NansatProjectionError
 


Test patch:
diff --git a/nansat/tests/mappers/test_mapper_netcdf_cf.py b/nansat/tests/mappers/test_mapper_netcdf_cf.py
index fdeef9dab..d73e94459 100644
--- a/nansat/tests/mappers/test_mapper_netcdf_cf.py
+++ b/nansat/tests/mappers/test_mapper_netcdf_cf.py
@@ -4,7 +4,7 @@
 import tempfile
 
 import numpy as np
-import gdal
+from nansat.utils import gdal
 from netCDF4 import Dataset
 
 from nansat.mappers.mapper_netcdf_cf import Mapper
diff --git a/nansat/tests/test_exporter.py b/nansat/tests/test_exporter.py
index 40067a4f2..694610d29 100644
--- a/nansat/tests/test_exporter.py
+++ b/nansat/tests/test_exporter.py
@@ -35,10 +35,10 @@
 else:
     MATPLOTLIB_IS_INSTALLED = True
 
-import gdal
 from netCDF4 import Dataset
 
 from nansat import Nansat, Domain, NSR
+from nansat.utils import gdal
 from nansat.tests.nansat_test_base import NansatTestBase
 
 warnings.simplefilter("always", UserWarning)
diff --git a/nansat/tests/test_figure.py b/nansat/tests/test_figure.py
index 94b930370..813c26bad 100644
--- a/nansat/tests/test_figure.py
+++ b/nansat/tests/test_figure.py
@@ -30,10 +30,10 @@
 except:
     from PIL import Image, ImageDraw, ImageFont
 
-import gdal
 import numpy as np
 
 from nansat import Figure, Nansat, Domain
+from nansat.utils import gdal
 from nansat.tests.nansat_test_base import NansatTestBase
 
 IS_CONDA = 'conda' in os.environ['PATH']
diff --git a/nansat/tests/test_geolocation.py b/nansat/tests/test_geolocation.py
index f762bbfa4..744e7b2aa 100644
--- a/nansat/tests/test_geolocation.py
+++ b/nansat/tests/test_geolocation.py
@@ -13,12 +13,11 @@
 import unittest
 import os
 
-import gdal
 import numpy as np
-import osr
 
 from nansat.vrt import VRT
 from nansat.geolocation import Geolocation
+from nansat.utils import gdal, osr
 from nansat.tests import nansat_test_data as ntd
 
 class GeolocationTest(unittest.TestCase):
diff --git a/nansat/tests/test_vrt.py b/nansat/tests/test_vrt.py
index c4bf00cbe..d88efb79b 100644
--- a/nansat/tests/test_vrt.py
+++ b/nansat/tests/test_vrt.py
@@ -20,7 +20,7 @@
 import warnings
 
 import numpy as np
-import gdal
+from nansat.utils import gdal
 import pythesint as pti
 
 from nansat.node import Node