Commit 7fd740e0 authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Adjusted code according to changes within py_tools_ds.

Updated __version__ and __versionalias__.
parent 9394812d
Pipeline #716 passed with stages
in 1 minute and 3 seconds
......@@ -2,8 +2,8 @@
__author__ = """Daniel Scheffler"""
__email__ = 'danschef@gfz-potsdam.de'
__version__ = '0.5.7'
__versionalias__ = 'v20170819.01'
__version__ = '0.5.8'
__versionalias__ = 'v20170819.02'
from .baseclasses import GeoArray
......
......@@ -34,7 +34,6 @@ from py_tools_ds.geo.vector.topology \
import get_footprint_polygon, polyVertices_outside_poly, fill_holes_within_poly
from py_tools_ds.geo.vector.geometry import boxObj
from py_tools_ds.io.raster.gdal import get_GDAL_ds_inmem
from py_tools_ds.numeric.array import find_noDataVal
from py_tools_ds.compatibility.python.exceptions \
import TimeoutError as TimeoutError_comp, FileNotFoundError as FileNotFoundError_comp
from py_tools_ds.compatibility.gdal import get_gdal_func
......@@ -342,7 +341,7 @@ class GeoArray(object):
if not self.is_inmem:
self.set_gdalDataset_meta()
if self._nodata is None:
self._nodata = find_noDataVal(self)
self._nodata = self.find_noDataVal()
if self._nodata == 'ambiguous':
warnings.warn('Nodata value could not be clearly identified. It has been set to None.')
self._nodata = None
......@@ -451,8 +450,8 @@ class GeoArray(object):
self._footprint_poly = self.box.mapPoly
else:
try:
multipolygon = raster2polygon(self, 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:
......@@ -650,6 +649,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.
......@@ -1337,6 +1367,8 @@ class GeoArray(object):
#
# return sub_gA if return_GeoArray else (sub_gA.arr, sub_gA.gt, sub_gA.prj)
def reproject(self, **kwargs_warp):
raise NotImplementedError() # TODO
def reproject_to_new_grid(self, prototype=None, tgt_prj=None, tgt_xygrid=None, rspAlg='cubic', CPUs=None):
"""Reproject all array-like attributes to a given target grid.
......
......@@ -11,17 +11,17 @@ with open('HISTORY.rst') as history_file:
history = history_file.read()
requirements = [
'py_tools_ds>=0.4.1', 'numpy', 'matplotlib', 'six', 'gdal', 'shapely', 'geopandas', 'dill', 'mpld3', 'geojson',
'py_tools_ds>=0.4.2', 'numpy', 'matplotlib', 'six', 'gdal', 'shapely', 'geopandas', '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.7',
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",
......
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