From e56ccbece0ac98063beb7ad649b5ef7700c3f3c6 Mon Sep 17 00:00:00 2001 From: Nat Wilson Date: Mon, 24 Apr 2017 20:26:33 -0700 Subject: [PATCH] raise proper error when gdal read fails also remove incomplete band kwarg from apply --- karta/raster/_gdal.py | 2 ++ karta/raster/grid.py | 8 +------- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/karta/raster/_gdal.py b/karta/raster/_gdal.py index d245427..a3ce894 100644 --- a/karta/raster/_gdal.py +++ b/karta/raster/_gdal.py @@ -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] diff --git a/karta/raster/grid.py b/karta/raster/grid.py index fa0873c..9a44bf1 100644 --- a/karta/raster/grid.py +++ b/karta/raster/grid.py @@ -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 @@ -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])