Commit 153cd3ae authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Merge branch 'master' into dev

Conflicts:
	geoarray/baseclasses.py
	setup.py
parents 99a36e0b 932008c2
......@@ -2,8 +2,8 @@
__author__ = """Daniel Scheffler"""
__email__ = 'danschef@gfz-potsdam.de'
__version__ = '0.5.4'
__versionalias__ = 'v20170719.01'
__version__ = '0.5.8'
__versionalias__ = 'v20170819.02'
from .baseclasses import GeoArray
......
......@@ -464,8 +464,8 @@ class GeoArray(object):
self._footprint_poly = self.box.mapPoly
else:
try:
multipolygon = raster2polygon(self, self.gt, self.prj, exact=False, progress=self.progress,
q=self.q, maxfeatCount=10, timeout=3)
multipolygon = raster2polygon(self.mask_nodata.astype(np.uint8), self.gt, self.prj, exact=False,
progress=self.progress, q=self.q, maxfeatCount=10, timeout=3)
self._footprint_poly = fill_holes_within_poly(multipolygon)
except (RuntimeError, TimeoutError, TimeoutError_comp):
if not self.q:
......@@ -663,6 +663,37 @@ class GeoArray(object):
np.all(np.where(arr == self.nodata, 0, 1), axis=2).astype(np.bool)
def find_noDataVal(self, bandIdx=0, sz=3):
"""Tries to derive no data value from homogenious corner pixels within 3x3 windows (by default).
:param bandIdx:
:param sz: window size in which corner pixels are analysed
"""
get_mean_std = lambda corner_subset: {'mean': np.mean(corner_subset), 'std': np.std(corner_subset)}
wins = [self[0:sz, 0:sz, bandIdx], self[0:sz, -sz:, bandIdx],
self[-sz:, -sz:, bandIdx], self[-sz:, 0:sz, bandIdx]] # UL, UR, LR, LL
means_stds = [get_mean_std(win) for win in wins]
possVals = [i['mean'] for i in means_stds if i['std'] == 0]
# possVals==[]: all corners are filled with data; np.std(possVals)==0: noDataVal clearly identified
if possVals:
if np.std(possVals) != 0:
# different possible nodata values have been found in the image corner
return 'ambiguous'
else:
if len(possVals) <= 2:
# each window in each corner
warnings.warn("\nAutomatic nodata value detection returned the value %s for GeoArray '%s' but this "
"seems to be unreliable (occurs in only %s). To avoid automatic detection, just pass "
"the correct nodata value." % (possVals[0], self.basename,
('2 image corners' if len(
possVals) == 2 else '1 image corner')))
return possVals[0]
else:
return None
def set_gdalDataset_meta(self):
"""Retrieves GDAL metadata from file. This function is only executed once to avoid overwriting of user defined
attributes, that are defined after object instanciation.
......@@ -802,27 +833,28 @@ class GeoArray(object):
# read subset area from disk
if bL == list(range(0, B)):
tempArr = gdalnumeric.LoadFile(path, cS, rS, cE - cS + 1, rE - rS + 1)
if tempArr is None:
raise Exception('Error reading file: ' + gdal.GetLastErrorMsg())
out_arr = np.swapaxes(np.swapaxes(tempArr, 0, 2), 0, 1) if B > 1 else tempArr
if out_arr is None:
raise Exception('Error reading file: ' + gdal.GetLastErrorMsg())
else:
ds = gdal.Open(path)
if len(bL) == 1:
band = ds.GetRasterBand(bL[0] + 1)
out_arr= band.ReadAsArray(cS, rS, cE - cS + 1, rE - rS + 1)
if out_arr is None:
raise Exception('Error reading file: ' + gdal.GetLastErrorMsg())
del band
else:
out_arr = np.empty((rE - rS + 1, cE - cS + 1, len(bL)))
for i, bIdx in enumerate(bL):
band = ds.GetRasterBand(bIdx + 1)
out_arr[:, :, i] = band.ReadAsArray(cS, rS, cE - cS + 1, rE - rS + 1)
if out_arr is None:
raise Exception('Error reading file: ' + gdal.GetLastErrorMsg())
del band
del ds
if out_arr is None:
raise Exception('Error reading file: ' + gdal.GetLastErrorMsg())
# only set self.arr if the whole cube has been read (in order to avoid sudden shape changes)
if out_arr.shape==self.shape:
self.arr = out_arr
......
......@@ -33,7 +33,7 @@ def _clip_array_at_mapPos(arr, mapBounds, arr_gt, band2clip=None, fillVal=0):
# get array metadata
rows, cols = arr.shape[:2]
bands = arr.shape[2] if len(arr.shape) == 3 else 1
bands = arr.shape[2] if arr.ndim == 3 else 1
arr_dtype = arr.dtype
ULxy, LLxy, LRxy, URxy = get_corner_coordinates(gt=arr_gt, rows=rows, cols=cols)
arrBounds = ULxy[0], LRxy[1], LRxy[0], ULxy[1]
......@@ -90,7 +90,7 @@ def _clip_array_at_mapPos(arr, mapBounds, arr_gt, band2clip=None, fillVal=0):
# fill newly created array with read data from input array
if tgt_bands==1:
out_arr[rS_out:rE_out + 1, cS_out:cE_out + 1] = data
out_arr[rS_out:rE_out + 1, cS_out:cE_out + 1] = data if data.ndim == 2 else data[:,:,0]
else:
out_arr[rS_out:rE_out + 1, cS_out:cE_out + 1,:] = data
......
py_tools_ds
py_tools_ds>=0.4.2
numpy
matplotlib
six
......@@ -12,4 +12,4 @@ geojson
folium
scikit-image
#holoviews
git+https://github.com/matplotlib/basemap.git
#git+https://github.com/matplotlib/basemap.git
......@@ -11,17 +11,17 @@ with open('HISTORY.rst') as history_file:
history = history_file.read()
requirements = [
'py_tools_ds', 'numpy', 'matplotlib', 'six', 'gdal', 'shapely', 'geopandas', 'pandas', 'dill', 'mpld3', 'geojson',
'py_tools_ds>=0.4.2', 'numpy', 'matplotlib', 'six', 'gdal', 'shapely', 'geopandas', 'pandas', 'dill', 'mpld3', 'geojson',
'folium', 'scikit-image'
#'holoviews', # conda install --yes -c ioam bokeh holoviews=1.8.0 ; \
# git+https://github.com/matplotlib/basemap.git
# git+https://github.com/matplotlib/basemap.git # conda install --yes -c conda-forge basemap
]
test_requirements = ["coverage"]
setup(
name='geoarray',
version='0.5.4',
version='0.5.8',
description="Fast Python interface for geodata - either on disk or in memory.",
long_description=readme + '\n\n' + history,
author="Daniel Scheffler",
......
FROM centos:7
RUN yum update -y && \
yum install -y wget vim bzip2 gcc gcc-c++ make libgl1-mesa-glx mesa-libGL qt5-qtbase-gui git # TODO
yum install -y wget vim bzip2 gcc gcc-c++ make libgl1-mesa-glx mesa-libGL qt5-qtbase-gui git
ENV anaconda_dl 'Anaconda3-4.3.1-Linux-x86_64.sh'
RUN /bin/bash -i -c "cd /root; wget https://repo.continuum.io/archive/$anaconda_dl ; \
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment