Skip to content
This repository has been archived by the owner on Jan 4, 2022. It is now read-only.

Commit

Permalink
making rasterio optional and only used for creating geotiffs
Browse files Browse the repository at this point in the history
  • Loading branch information
chelm committed Dec 19, 2017
1 parent 63c0d2d commit 2a3baf4
Show file tree
Hide file tree
Showing 19 changed files with 18 additions and 60 deletions.
2 changes: 0 additions & 2 deletions appveyor.yml
Expand Up @@ -39,8 +39,6 @@ install:
- "%PYTHON%\\python.exe -m pip install GDAL-2.1.3-cp27-cp27m-win32.whl"
- "appveyor DownloadFile https://github.com/DigitalGlobe/gbdxtools-windows-binaries/raw/master/Shapely-1.5.17-cp27-cp27m-win32.whl"
- "%PYTHON%\\python.exe -m pip install Shapely-1.5.17-cp27-cp27m-win32.whl"
- "appveyor DownloadFile https://github.com/DigitalGlobe/gbdxtools-windows-binaries/raw/master/rasterio-1.0a5-cp27-cp27m-win32.whl"
- "%PYTHON%\\python.exe -m pip install rasterio-1.0a5-cp27-cp27m-win32.whl"
- "appveyor DownloadFile https://github.com/DigitalGlobe/gbdxtools-windows-binaries/raw/master/pyproj-1.9.5.1-cp27-cp27m-win32.whl"
- "%PYTHON%\\python.exe -m pip install pyproj-1.9.5.1-cp27-cp27m-win32.whl"
- "%PYTHON%\\python.exe -m pip install matplotlib pytest"
Expand Down
5 changes: 1 addition & 4 deletions docs/conf.py
Expand Up @@ -29,7 +29,7 @@ class Mock(MagicMock):
def __getattr__(cls, name):
return Mock()

MOCK_MODULES = ['pycurl', 'pyproj', 'rasterio', 'rio_hist']
MOCK_MODULES = ['pycurl', 'pyproj']
sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES)

# 'boto',
Expand All @@ -49,9 +49,6 @@ def __getattr__(cls, name):
# 'dask.array',
# 'numpy',
# 'numpy.linalg',
# 'rasterio',
# 'rasterio.io',
# 'rasterio.transform',
# 'skimage',
# 'skimage.transform',
# 'skimage.transform._geometric']
Expand Down
2 changes: 0 additions & 2 deletions environment.yml
Expand Up @@ -215,8 +215,6 @@ dependencies:
'pywavelets=0.5.2=py27_1'
- !!python/unicode
'pyyaml=3.12=py27_1'
- !!python/unicode
'rasterio=0.36.0=py27_1'
- !!python/unicode
'readline=6.2=0'
- !!python/unicode
Expand Down
19 changes: 7 additions & 12 deletions gbdxtools/images/tms_image.py
Expand Up @@ -16,12 +16,8 @@
from cachetools.func import lru_cache

import numpy as np
import rasterio
try:
from rasterio import RasterioIOError
except ImportError:
from rasterio.errors import RasterioIOError
from rasterio.transform import from_bounds as transform_from_bounds
from affine import Affine
from scipy.misc import imread

import mercantile

Expand Down Expand Up @@ -57,18 +53,16 @@ def load_url(url, shape=(8, 256, 256)):
try:
if(code != 200):
raise TypeError("Request for {} returned unexpected error code: {}".format(url, code))
temp.file.flush()
temp.close()
with rasterio.open(temp.name) as dataset:
arr = dataset.read()
except (TypeError, RasterioIOError) as e:
arr = np.rollaxis(imread(temp), 2, 0)
except Exception as e:
print(e)
temp.seek(0)
print(temp.read())
arr = np.zeros(shape, dtype=np.uint8)
_curl.close()
del _curl_pool[thread_id]
finally:
temp.file.flush()
temp.close()
os.remove(temp.name)
return arr
Expand Down Expand Up @@ -149,7 +143,8 @@ def chunks(self):

@property
def __geo_transform__(self):
tfm = transform_from_bounds(*tuple(e for e in chain(self.bounds, self.shape[2:0:-1])))
west, south, east, north = self.bounds
tfm = Affine.translation(west, north) * Affine.scale((east - west) / self.shape[2], (south - north) / self.shape[1])
return AffineTransform(tfm, "EPSG:3857")

def _collect_urls(self, bounds):
Expand Down
12 changes: 3 additions & 9 deletions gbdxtools/ipe/interface.py
Expand Up @@ -16,12 +16,7 @@
except ImportError:
from cachetools.func import lru_cache

import rasterio
try:
from rasterio import RasterioIOError
except ImportError:
from rasterio.errors import RasterioIOError

from skimage.io import imread
import pycurl
import numpy as np

Expand Down Expand Up @@ -70,11 +65,10 @@ def load_url(url, token, shape=(8, 256, 256)):
raise TypeError("Request for {} returned unexpected error code: {}".format(url, code))
temp.file.flush()
temp.close()
with rasterio.open(temp.name) as dataset:
arr = dataset.read()
arr = np.rollaxis(imread(temp.name), 2, 0)
success = True
return arr
except (TypeError, RasterioIOError) as e:
except Exception as e:
print(e)
_curl.close()
del _curl_pool[thread_id]
Expand Down
8 changes: 7 additions & 1 deletion gbdxtools/ipe/io.py
@@ -1,4 +1,9 @@
import rasterio
try:
import rasterio
has_rasterio = True
except:
has_rasterio = False

import numpy as np
from dask.array import store

Expand All @@ -12,6 +17,7 @@ def __setitem__(self, location, chunk):
self.dst.write(chunk, window=window)

def to_geotiff(arr, path='./output.tif', proj=None, bands=None, **kwargs):
assert has_rasterio, "To create geotiff images please install rasterio"
if bands is not None:
arr = arr[bands,...]

Expand Down
7 changes: 0 additions & 7 deletions install_windows.md
Expand Up @@ -26,13 +26,6 @@ curl -outf Shapely-1.5.17-cp27-cp27m-win32.whl https://github.com/DigitalGlobe/g
pip install .\Shapely-1.5.17-cp27-cp27m-win32.whl
```

Install rasterio:

```
curl -outf rasterio-1.0a5-cp27-cp27m-win32.whl https://github.com/DigitalGlobe/gbdxtools-windows-binaries/blob/master/rasterio-1.0a5-cp27-cp27m-win32.whl?raw=true
pip install .\rasterio-1.0a5-cp27-cp27m-win32.whl
```

Install pyproj:

```
Expand Down
2 changes: 0 additions & 2 deletions meta.yaml
Expand Up @@ -26,7 +26,6 @@ requirements:
- dask ==0.15.4
- numpy
- pycurl
- rasterio >=0.36.0
- pyproj
- requests-futures
- configparser
Expand All @@ -50,7 +49,6 @@ requirements:
- dask ==0.15.4
- {{ pin_compatible('numpy', min_pin='1.9') }}
- pycurl
- rasterio >=0.36.0
- pyproj
- requests-futures
- configparser
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Expand Up @@ -15,7 +15,6 @@ cloudpickle
dask==0.15.4
numpy
pycurl
rasterio>=0.36
pyproj
requests_futures
configparser
Expand Down
1 change: 0 additions & 1 deletion tests/unit/test_catalog_image.py
Expand Up @@ -10,7 +10,6 @@
from os.path import join, isfile, dirname, realpath
import tempfile
import unittest
import rasterio

# How to use the mock_gbdx_session and vcr to create unit tests:
# 1. Add a new test that is dependent upon actually hitting GBDX APIs.
Expand Down
1 change: 0 additions & 1 deletion tests/unit/test_dem_image.py
Expand Up @@ -12,7 +12,6 @@
from os.path import join, isfile, dirname, realpath
import tempfile
import unittest
import rasterio
import dask.array as da

try:
Expand Down
1 change: 0 additions & 1 deletion tests/unit/test_geoeye_image.py
Expand Up @@ -12,7 +12,6 @@
from os.path import join, isfile, dirname, realpath
import tempfile
import unittest
import rasterio
import dask.array as da

def force(r1, r2):
Expand Down
1 change: 0 additions & 1 deletion tests/unit/test_ikonos_image.py
Expand Up @@ -12,7 +12,6 @@
from os.path import join, isfile, dirname, realpath
import tempfile
import unittest
import rasterio
import dask.array as da

def force(r1, r2):
Expand Down
11 changes: 0 additions & 11 deletions tests/unit/test_ipe_image.py
Expand Up @@ -152,14 +152,3 @@ def test_ipe_image_ortho(self):
aoi.ortho = read_mock
ortho = aoi.warp()
assert isinstance(ortho, DaskImage)

#@my_vcr.use_cassette('tests/unit/cassettes/test_ipe_image_geotiff.yaml', filter_headers=['authorization'])
#def test_ipe_image_geotiff(self):
# idahoid = '179269b9-fdb3-49d8-bb62-d15de54ad15d'
# img = self.gbdx.idaho_image(idahoid, bbox=[-110.85299491882326,32.167148499672855,-110.84870338439943,32.170236308395644])
# tif = img.geotiff(path='/tmp/tmp.tif', dtype='uint16')
# with rasterio.open(tif) as src:
# assert [round(x, 3) for x in list(src.bounds)] == [-110.853, 32.167, -110.849, 32.17]
# assert src.meta['width'] == 239
# assert src.meta['height'] == 172
# assert src.meta['dtype'] == 'uint16'
1 change: 0 additions & 1 deletion tests/unit/test_landsat_image.py
Expand Up @@ -12,7 +12,6 @@
from os.path import join, isfile, dirname, realpath
import tempfile
import unittest
import rasterio
import dask.array as da

def force(r1, r2):
Expand Down
1 change: 0 additions & 1 deletion tests/unit/test_quickbird_image.py
Expand Up @@ -12,7 +12,6 @@
from os.path import join, isfile, dirname, realpath
import tempfile
import unittest
import rasterio
import dask.array as da

def force(r1, r2):
Expand Down
1 change: 0 additions & 1 deletion tests/unit/test_s3_image.py
Expand Up @@ -12,7 +12,6 @@
from os.path import join, isfile, dirname, realpath
import tempfile
import unittest
import rasterio
import dask.array as da

def force(r1, r2):
Expand Down
1 change: 0 additions & 1 deletion tests/unit/test_sentinel2_image.py
Expand Up @@ -12,7 +12,6 @@
from os.path import join, isfile, dirname, realpath
import tempfile
import unittest
import rasterio
import dask.array as da

def force(r1, r2):
Expand Down
1 change: 0 additions & 1 deletion tests/unit/test_worldview.py
Expand Up @@ -12,7 +12,6 @@
from os.path import join, isfile, dirname, realpath
import tempfile
import unittest
import rasterio

try:
from urlparse import urlparse
Expand Down

0 comments on commit 2a3baf4

Please sign in to comment.