Skip to content

Commit

Permalink
raise proper error when gdal read fails
Browse files Browse the repository at this point in the history
also remove incomplete band kwarg from apply
  • Loading branch information
njwilson23 committed Apr 25, 2017
1 parent 65daeb1 commit e56ccbe
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
2 changes: 2 additions & 0 deletions karta/raster/_gdal.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ def read(fnm, in_memory, ibands=ALL, bandclass=CompressedBand):
bands = [bandclass((ny, nx), dtype) for _ in ibands]
for i, rb in enumerate(rasterbands):
_arr = rb.ReadAsArray(buf_obj=np.empty([ny, nx], dtype=dtype))
if _arr is None:
raise IOError("error reading GDAL band {}".format(i+1))
bands[i].setblock(0, 0, _arr.squeeze()[::-1])
else:
bands = [GdalFileBand(rb, dataset) for rb in rasterbands]
Expand Down
8 changes: 1 addition & 7 deletions karta/raster/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def copy(self):
""" Return a deep copy """
return copy.deepcopy(self)

def apply(self, func, inplace=False, band=None):
def apply(self, func, inplace=False):
""" Apply a vector function to grid values.
Parameters
Expand All @@ -62,18 +62,12 @@ def apply(self, func, inplace=False, band=None):
inplace : boolean, optional
whether to perform operation in place rather than returning a new
grid instance (default False)
band : int, optional
if provided, only apply *func* to a specific band
Returns
-------
instance of type(self)
"""
msk = self.data_mask_full
if band is not None:
if not isinstance(band, int) or not (0 <= band < self.nbands):
raise ValueError("band must be an integer in [0, nbands)")
msk *= np.array([i == band for i in range(self.nbands)])

if inplace:
self[msk] = func(self[msk])
Expand Down

0 comments on commit e56ccbe

Please sign in to comment.