Skip to content

Commit

Permalink
fix setting a partial stack of bands and add test
Browse files Browse the repository at this point in the history
backport to 0.7.x
  • Loading branch information
njwilson23 committed Oct 8, 2016
1 parent 9f05696 commit 9e5188a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions karta/raster/band.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ def __setitem__(self, key, value):
sb = slice(None, None, None) if len(key) == 2 else key[2]
if isinstance(sb, slice):
if len(value.shape) == 3:
for i in range(len(self.bands)):
self.bands[i][sr,sc] = value[:,:,i]
for ival, iband in enumerate(range(*sb.indices(len(self.bands)))):
self.bands[iband][sr,sc] = value[:,:,ival]
else:
for b in self.bands[sb]:
b[sr,sc] = value
Expand Down
5 changes: 5 additions & 0 deletions tests/band_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ def test_set_multibanded(self):
self.assertTrue(np.all(bands[0][:,:] == 1.0))
self.assertTrue(np.all(bands[1][:,:] == 2.0))
self.assertTrue(np.all(bands[2][:,:] == 2.0))

indexer[:,:,1:] = np.dstack([2*values, 3*values])

self.assertTrue(np.all(bands[1][:,:] == 2.0))
self.assertTrue(np.all(bands[2][:,:] == 3.0))
return

def test_set_multibanded_masked(self):
Expand Down

0 comments on commit 9e5188a

Please sign in to comment.