Commit ffb64967 authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

GeoArray.tiles now has a length (added __len__).

parent 6f624008
Pipeline #1483 failed with stages
in 1 minute and 4 seconds
...@@ -4,7 +4,6 @@ import os ...@@ -4,7 +4,6 @@ import os
import warnings import warnings
from importlib import util from importlib import util
from collections import OrderedDict from collections import OrderedDict
from typing import Generator # noqa F401 # flake8 issue
import numpy as np import numpy as np
from matplotlib import pyplot as plt from matplotlib import pyplot as plt
...@@ -1011,7 +1010,7 @@ class GeoArray(object): ...@@ -1011,7 +1010,7 @@ class GeoArray(object):
res_factor=res_factor, nodataVal=nodataVal) res_factor=res_factor, nodataVal=nodataVal)
# set color palette # set color palette
palette = cmap if cmap else plt.cm.gray palette = cmap if cmap else plt.get_cmap('gray')
if nodataVal is not None and np.std(image2plot) != 0: # do not show nodata if nodataVal is not None and np.std(image2plot) != 0: # do not show nodata
image2plot = np.ma.masked_equal(image2plot, nodataVal) image2plot = np.ma.masked_equal(image2plot, nodataVal)
vmin_auto, vmax_auto = \ vmin_auto, vmax_auto = \
...@@ -1141,7 +1140,7 @@ class GeoArray(object): ...@@ -1141,7 +1140,7 @@ class GeoArray(object):
urcrnrlon=UR_XY[0], urcrnrlat=UR_XY[1], llcrnrlon=LL_XY[0], llcrnrlat=LL_XY[1]) urcrnrlon=UR_XY[0], urcrnrlat=UR_XY[1], llcrnrlon=LL_XY[0], llcrnrlat=LL_XY[1])
# set color palette # set color palette
palette = cmap if cmap else plt.cm.gray palette = cmap if cmap else plt.get_cmap('gray')
if nodataVal is not None and np.std(image2plot) != 0: # do not show nodata if nodataVal is not None and np.std(image2plot) != 0: # do not show nodata
image2plot = np.ma.masked_equal(image2plot, nodataVal) image2plot = np.ma.masked_equal(image2plot, nodataVal)
vmin_auto, vmax_auto = \ vmin_auto, vmax_auto = \
...@@ -1213,7 +1212,7 @@ class GeoArray(object): ...@@ -1213,7 +1212,7 @@ class GeoArray(object):
# m.pcolormesh(Xarr, Yarr, self[:], cmap=plt.cm.jet) # m.pcolormesh(Xarr, Yarr, self[:], cmap=plt.cm.jet)
# set color palette # set color palette
palette = cmap if cmap else plt.cm.gray palette = cmap if cmap else plt.get_cmap('gray')
if nodataVal is not None: # do not show nodata if nodataVal is not None: # do not show nodata
image2plot = np.ma.masked_equal(image2plot, nodataVal) image2plot = np.ma.masked_equal(image2plot, nodataVal)
vmin_auto, vmax_auto = \ vmin_auto, vmax_auto = \
...@@ -1323,18 +1322,30 @@ class GeoArray(object): ...@@ -1323,18 +1322,30 @@ class GeoArray(object):
self.footprint_poly = self.footprint_poly.intersection(self.box.mapPoly) self.footprint_poly = self.footprint_poly.intersection(self.box.mapPoly)
def tiles(self, tilesize=(100, 100)): def tiles(self, tilesize=(100, 100)):
# type: (tuple) -> Generator # type: (tuple) -> GeneratorLen
"""Get tiles of the full dataset in the given tile size. """Get tiles of the full dataset in the given tile size.
:param tilesize: target size of the tiles (rows, columns) :param tilesize: target size of the tiles (rows, columns)
NOTE: If rows or columns are None, all rows/columns are returned NOTE: If rows or columns are None, all rows/columns are returned
:return: Generator with elements like: ((rowStart, rowEnd), (colStart, colEnd),tiledata :return: Generator with elements like: (((rowStart, rowEnd), (colStart, colEnd)), tiledata)
""" """
bounds_alltiles = get_array_tilebounds(self.shape, tilesize) bounds_alltiles = get_array_tilebounds(self.shape, tilesize)
for bounds_tile in bounds_alltiles: class GeneratorLen(object):
(rS, rE), (cS, cE) = bounds_tile """Generator class adding __len__."""
yield bounds_tile, self[rS: rE + 1, cS: cE + 1, :] def __init__(self, gen, length):
self.gen = gen
self.length = length
def __len__(self):
return self.length
def __iter__(self):
return self.gen
out_gen = ((((rS, rE), (cS, cE)), self[rS: rE + 1, cS: cE + 1, :]) for (rS, rE), (cS, cE) in bounds_alltiles)
return GeneratorLen(out_gen, length=len(bounds_alltiles))
def get_mapPos(self, mapBounds, mapBounds_prj, band2get=None, out_prj=None, arr_gt=None, arr_prj=None, fillVal=None, def get_mapPos(self, mapBounds, mapBounds_prj, band2get=None, out_prj=None, arr_gt=None, arr_prj=None, fillVal=None,
rspAlg='near', progress=None, v=False): # TODO implement slice for indexing bands rspAlg='near', progress=None, v=False): # TODO implement slice for indexing bands
...@@ -1357,7 +1368,6 @@ class GeoArray(object): ...@@ -1357,7 +1368,6 @@ class GeoArray(object):
:param v: verbose mode (not related to GeoArray.v; must be explicitly set) :param v: verbose mode (not related to GeoArray.v; must be explicitly set)
:return: :return:
""" """
arr_gt = arr_gt or self.geotransform arr_gt = arr_gt or self.geotransform
arr_prj = arr_prj or self.projection arr_prj = arr_prj or self.projection
out_prj = out_prj or arr_prj out_prj = out_prj or arr_prj
......
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