Commit 0a6d223b authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Completely excluded geoarray from py_tools_ds (solves circular dependency).

parent c414ce4d
Pipeline #712 passed with stages
in 43 seconds
......@@ -2,7 +2,7 @@
#
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXOPTS = -T
SPHINXBUILD = sphinx-build
PAPER =
BUILDDIR = _build
......
......@@ -6,7 +6,6 @@ from . import io
from . import numeric
from . import similarity
from . import web
from .io.raster.GeoArray import GeoArray
__version__ = '0.4.1'
__versionalias__ = '20170705_02'
......
......@@ -19,11 +19,11 @@ from ...processing.progress_mon import ProgressBar, Timer
from ...compatibility.python.exceptions import TimeoutError as TimeoutError_comp
def raster2polygon(array_or_GeoArray, gt=None, prj=None, DN2extract=1, exact=True, maxfeatCount=None,
def raster2polygon(array, gt, prj, DN2extract=1, exact=True, maxfeatCount=None,
timeout=None, progress=True, q=False):
"""Calculates a footprint polygon for the given array or GeoArray.
"""Calculates a footprint polygon for the given array.
:param array_or_GeoArray:
:param array: 2D numpy array
:param gt:
:param prj:
:param DN2extract: <int, float> pixel value to create polygons for
......@@ -35,10 +35,10 @@ def raster2polygon(array_or_GeoArray, gt=None, prj=None, DN2extract=1, exact=Tru
:param q: quiet mode (default: False)
:return:
"""
from geoarray import GeoArray
geoArr = array_or_GeoArray if isinstance(array_or_GeoArray, GeoArray) else GeoArray(array_or_GeoArray, gt, prj)
src_ds = get_GDAL_ds_inmem(geoArr.mask_nodata.astype(np.uint8), geoArr.gt, geoArr.prj)
assert array.ndim == 2, "Only 2D arrays are supported. Got a %sD array." % array.ndim
src_ds = get_GDAL_ds_inmem(array, gt, prj)
src_band = src_ds.GetRasterBand(1)
# Create a memory OGR datasource to put results in.
......@@ -46,7 +46,7 @@ def raster2polygon(array_or_GeoArray, gt=None, prj=None, DN2extract=1, exact=Tru
mem_ds = mem_drv.CreateDataSource('out')
srs = osr.SpatialReference()
srs.ImportFromWkt(geoArr.prj)
srs.ImportFromWkt(prj)
mem_layer = mem_ds.CreateLayer('poly', srs, ogr.wkbPolygon)
......
......@@ -136,8 +136,7 @@ def warp_ndarray_OLD(ndarray, in_gt, in_prj, out_prj, out_gt=None, outRowsCols=N
print('calc_trafo_args')
for i in [src_crs, dst_crs, cols, rows, left, bottom, right, top, out_res]:
print(i, '\n')
from geoarray import GeoArray
left, right, bottom, top = GeoArray(ndarray, in_gt, in_prj).box.boundsMap
left, right, bottom, top = corner_coord_to_minmax(get_corner_coordinates(gt=in_gt, rows=rows, cols=cols))
dst_transform, out_cols, out_rows = rio_calc_transform(
src_crs, dst_crs, cols, rows, left, bottom, right, top, resolution=out_res)
......@@ -193,7 +192,7 @@ def warp_ndarray_OLD(ndarray, in_gt, in_prj, out_prj, out_gt=None, outRowsCols=N
rio_reproject(ndarray, out_arr,
src_transform=in_gt, src_crs=src_crs, dst_transform=out_gt, dst_crs=dst_crs,
resampling=dict_rspInt_rspAlg[rsp_alg], src_nodata=in_nodata, dst_nodata=out_nodata)
from matplotlib import pyplot as plt
#from matplotlib import pyplot as plt
#print(out_arr.shape)
#plt.figure()
#plt.imshow(out_arr[:,:,1])
......@@ -211,9 +210,11 @@ def warp_ndarray_OLD(ndarray, in_gt, in_prj, out_prj, out_gt=None, outRowsCols=N
def warp_GeoArray(geoArr, **kwargs):
ndarray = geoArr[:]
from geoarray import GeoArray
return GeoArray(*warp_ndarray(ndarray, geoArr.geotransform, geoArr.projection, **kwargs)) # FIXME this does not copy GeoArray attributes
# TODO remove that function
warnings.warn("warp_GeoArray is deprecated. Use geoarray.GeoArray.reproject_to_new_grid instead.", DeprecationWarning)
# ndarray = geoArr[:]
# from geoarray import GeoArray
# return GeoArray(*warp_ndarray(ndarray, geoArr.geotransform, geoArr.projection, **kwargs)) # FIXME this does not copy GeoArray attributes
def warp_ndarray(ndarray, in_gt, in_prj, out_prj=None, out_dtype=None, out_gsd=(None, None),
......
# -*- coding: utf-8 -*-
__author__='Daniel Scheffler'
import warnings
get_msg = lambda cls, impt:\
"\n%s class has been moved to the new stand-alone package 'geoarray'.\n" %cls +\
"If you encounter issues importing geoarray, request access to the new GitLab repository from Daniel Scheffler and " \
"follow the installation instructions there! Otherwise, just update your import statement!\n" \
"Import %s as follows: '%s'\n" %(cls, impt)
def alias_property(*args, **kwargs):
warnings.warn("py_tools_ds.io.raster.GeoArray.alias_property is deprecated. "
"Use py_tools_ds.convenience.alias_property instead.",
DeprecationWarning)
from ...convenience.object_oriented import alias_property
return alias_property(*args, **kwargs)
def GeoArray(*args, **kwargs):
warnings.warn(get_msg('GeoArray', "from geoarray import GeoArray"), DeprecationWarning)#, stacklevel=2)
from geoarray import GeoArray
return GeoArray(*args, **kwargs)
def MultiGeoArray(*args, **kwargs):
warnings.warn(get_msg('GeoArray', "from geoarray.baseclasses import MultiGeoArray"), DeprecationWarning, stacklevel=2)
from geoarray.baseclasses import MultiGeoArray
return MultiGeoArray(*args, **kwargs)
def BadDataMask(*args, **kwargs):
warnings.warn(get_msg('GeoArray', "from geoarray.masks import BadDataMask"), DeprecationWarning, stacklevel=2)
from geoarray.masks import BadDataMask
return BadDataMask(*args, **kwargs)
def NoDataMask(*args, **kwargs):
warnings.warn(get_msg('GeoArray', "from geoarray.masks import NoDataMask"), DeprecationWarning, stacklevel=2)
from geoarray.masks import NoDataMask
return NoDataMask(*args, **kwargs)
def CloudMask(*args, **kwargs):
warnings.warn(get_msg('GeoArray',"from geoarray.masks import CloudMask"), DeprecationWarning, stacklevel=2)
from geoarray.masks import CloudMask
return CloudMask(*args, **kwargs)
......@@ -2,8 +2,6 @@
__author__ = "Daniel Scheffler"
import numpy as np
import warnings
def get_outFillZeroSaturated(dtype):
......@@ -21,36 +19,3 @@ def get_outFillZeroSaturated(dtype):
return dict_outFill[dtype], dict_outZero[dtype], dict_outSaturated[dtype]
def find_noDataVal(pathIm_or_GeoArray,bandIdx=0,sz=3):
"""tries to derive no data value from homogenious corner pixels within 3x3 windows (by default)
:param pathIm_or_GeoArray:
:param bandIdx:
:param sz: window size in which corner pixels are analysed
"""
from geoarray import GeoArray
geoArr = pathIm_or_GeoArray if isinstance(pathIm_or_GeoArray, GeoArray) else GeoArray(pathIm_or_GeoArray)
get_mean_std = lambda corner_subset: {'mean':np.mean(corner_subset), 'std':np.std(corner_subset)}
wins = [geoArr[0:sz,0:sz,bandIdx], geoArr[0:sz,-sz:,bandIdx],
geoArr[-sz:,-sz:,bandIdx], geoArr[-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], geoArr.basename,
('2 image corners' if len(possVals)==2 else '1 image corner')))
return possVals[0]
else:
return None
......@@ -11,7 +11,7 @@ with open('README.rst') as readme_file:
with open('HISTORY.rst') as history_file:
history = history_file.read()
requirements = ['gdal', 'numpy', 'shapely', 'six', 'rasterio', 'geopandas','geoarray']
requirements = ['gdal', 'numpy', 'shapely', 'six', 'rasterio', 'geopandas']
setup_requirements = [] # TODO(danschef): put setup requirements (distutils extensions, etc.) here
test_requirements = requirements + ['coverage']
......
......@@ -5,10 +5,6 @@ dockerfile="py_tools_ds_ci.docker"
tag="py_tools_ds_ci:latest"
gitlab_runner="py_tools_ds_gitlab_CI_runner"
# get geoarray project # TODO move this to setup.py as soon as package is public
rm -rf context/geoarray
git clone https://gitext.gfz-potsdam.de/danschef/geoarray.git ./context/geoarray
echo "#### Build runner docker image"
sudo docker rmi ${tag}
sudo docker build -f ${context_dir}/${dockerfile} -m 20G -t ${tag} ${context_dir}
......
......@@ -19,9 +19,6 @@ RUN /bin/bash -i -c "source /root/anaconda3/bin/activate ; \
#COPY *.pkl /root/ # EXAMPLE
#COPY *.h5 /root/ # EXAMPLE
# copy geoarray code to /tmp # TODO move this to setup.py as soon as package is public
COPY geoarray /tmp/geoarray
# install git lfs
RUN /bin/bash -i -c "curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.rpm.sh | bash"
......@@ -37,7 +34,3 @@ RUN bash -i -c 'source /root/anaconda3/bin/activate; \
sed -i "/backend : tkagg/c\backend : Agg" $(python -c "import matplotlib; print(matplotlib.matplotlib_fname())"); \
sed -i "/backend : Qt4Agg/c\backend : Agg" $(python -c "import matplotlib; print(matplotlib.matplotlib_fname())"); \
sed -i "/backend : qt5agg/c\backend : Agg" $(python -c "import matplotlib; print(matplotlib.matplotlib_fname())")'
RUN bash -i -c "source /root/anaconda3/bin/activate; \
cd /tmp/geoarray/; python setup.py install;" # TODO move this to setup.py as soon as package is public
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