Skip to content

Commit

Permalink
add bandindexer shape tests
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 9e5188a commit 2be2f54
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion karta/raster/band.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def shape(self):
elif len(self.bands) == 1:
return self.bands[0].size
else:
return (len(self.bands), self.bands[0].size[0], self.bands.size[1])
return (len(self.bands), self.bands[0].size[0], self.bands[0].size[1])

@property
def dtype(self):
Expand Down
28 changes: 28 additions & 0 deletions tests/band_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,33 @@ def test_set_multibanded_masked(self):
self.assertEqual(np.sum(indexer[:,:]), 336)
return

def test_set_multibanded_masked_array(self):
values = np.ones([16, 16])
bands = [CompressedBand((16, 16), np.float32),
CompressedBand((16, 16), np.float32),
CompressedBand((16, 16), np.float32)]

mask = np.zeros([16, 16], dtype=np.bool)
mask[8:, 2:] = True

indexer = BandIndexer(bands)
indexer[:,:] = np.zeros([16, 16])
indexer[mask] = np.ones(8*14)

self.assertEqual(np.sum(indexer[:,:]), 336)
return

def test_shape(self):
bands = [CompressedBand((16, 16), np.float32),
CompressedBand((16, 16), np.float32),
CompressedBand((16, 16), np.float32)]

indexer1 = BandIndexer([bands[0]])
self.assertEqual(indexer1.shape, (16, 16))

indexer3 = BandIndexer(bands)
self.assertEqual(indexer3.shape, (3, 16, 16))
return

if __name__ == "__main__":
unittest.main()

0 comments on commit 2be2f54

Please sign in to comment.