Skip to content

Commit

Permalink
fixes for CompressedBand.__setitem__
Browse files Browse the repository at this point in the history
now setting slices with a scalar works, and fixes some slicing bugs

backport to 0.7.x
  • Loading branch information
njwilson23 committed Oct 11, 2016
1 parent 2be2f54 commit 2a36045
Showing 1 changed file with 7 additions and 24 deletions.
31 changes: 7 additions & 24 deletions karta/raster/band.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,18 +259,8 @@ def __setitem__(self, key, value):
sy = 1

elif isinstance(kr, slice):
if kr.start is None:
yoff = 0
else:
yoff = kr.start
if kr.stop is None:
ny = self.size[0]-yoff
else:
ny = kr.stop-yoff
if kr.step is None:
sy = 1
else:
sy = kr.step
yoff, _ystop, sy = kr.indices(self.size[0])
ny = _ystop - yoff

else:
raise IndexError("slicing with instances of '{0}' not "
Expand All @@ -282,23 +272,16 @@ def __setitem__(self, key, value):
sx = 1

elif isinstance(kc, slice):
if kc.start is None:
xoff = 0
else:
xoff = kc.start
if kc.stop is None:
nx = self.size[1]-xoff
else:
nx = kc.stop-xoff
if kc.step is None:
sx = 1
else:
sx = kc.step
xoff, _xstop, sx = kc.indices(self.size[1])
nx = _xstop - xoff

else:
raise IndexError("slicing with instances of '{0}' not "
"supported".format(type(kc)))

if not hasattr(value, "shape"):
value = value*np.ones((ny, nx))

vny, vnx = value.shape[:2]
if (ceil(float(ny)/sy) != vny) or (ceil(float(nx)/sx) != vnx):
raise IndexError("Cannot insert array with size ({vny}, {vnx}))"
Expand Down

0 comments on commit 2a36045

Please sign in to comment.