-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #144 from jamesmcclain/feature/lookup
Tile Lookup
- Loading branch information
Showing
5 changed files
with
122 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import os | ||
import unittest | ||
import numpy as np | ||
|
||
import pytest | ||
|
||
from geopyspark.geotrellis.constants import ZOOM | ||
from geopyspark.tests.base_test_class import BaseTestClass | ||
from geopyspark.geotrellis.rdd import TiledRasterRDD | ||
from geopyspark.geotrellis.constants import SPATIAL | ||
|
||
|
||
class LookupTest(BaseTestClass): | ||
data = np.array([[ | ||
[1.0, 1.0, 1.0, 1.0, 1.0], | ||
[1.0, 1.0, 1.0, 1.0, 1.0], | ||
[1.0, 1.0, 1.0, 1.0, 1.0], | ||
[1.0, 1.0, 1.0, 1.0, 1.0], | ||
[1.0, 1.0, 1.0, 1.0, 0.0]]]) | ||
|
||
layer = [({'row': 0, 'col': 0}, {'no_data_value': -1.0, 'data': data + 0}), | ||
({'row': 1, 'col': 0}, {'no_data_value': -1.0, 'data': data + 1}), | ||
({'row': 0, 'col': 1}, {'no_data_value': -1.0, 'data': data + 2}), | ||
({'row': 1, 'col': 1}, {'no_data_value': -1.0, 'data': data + 3})] | ||
rdd = BaseTestClass.geopysc.pysc.parallelize(layer) | ||
|
||
extent = {'xmin': 0.0, 'ymin': 0.0, 'xmax': 33.0, 'ymax': 33.0} | ||
layout = {'layoutCols': 2, 'layoutRows': 2, 'tileCols': 5, 'tileRows': 5} | ||
metadata = {'cellType': 'float32ud-1.0', | ||
'extent': extent, | ||
'crs': '+proj=longlat +datum=WGS84 +no_defs ', | ||
'bounds': { | ||
'minKey': {'col': 0, 'row': 0}, | ||
'maxKey': {'col': 1, 'row': 1}}, | ||
'layoutDefinition': { | ||
'extent': extent, | ||
'tileLayout': {'tileCols': 5, 'tileRows': 5, 'layoutCols': 2, 'layoutRows': 2}}} | ||
|
||
raster_rdd = TiledRasterRDD.from_numpy_rdd(BaseTestClass.geopysc, SPATIAL, rdd, metadata) | ||
|
||
@pytest.fixture(autouse=True) | ||
def tearDown(self): | ||
yield | ||
BaseTestClass.geopysc.pysc._gateway.close() | ||
|
||
def test_lookup_1(self): | ||
result = self.raster_rdd.lookup(0, 0)[0] | ||
n = np.sum(result['data']) | ||
self.assertEqual(n, 24 + 0*25) | ||
|
||
def test_lookup_2(self): | ||
result = self.raster_rdd.lookup(0, 1)[0] | ||
n = np.sum(result['data']) | ||
self.assertEqual(n, 24 + 1*25) | ||
|
||
def test_lookup_3(self): | ||
result = self.raster_rdd.lookup(1, 0)[0] | ||
n = np.sum(result['data']) | ||
self.assertEqual(n, 24 + 2*25) | ||
|
||
def test_lookup_4(self): | ||
result = self.raster_rdd.lookup(1, 1)[0] | ||
n = np.sum(result['data']) | ||
self.assertEqual(n, 24 + 3*25) | ||
|
||
def test_lookup_5(self): | ||
with pytest.raises(IndexError): | ||
result = self.raster_rdd.lookup(13, 33) | ||
|
||
if __name__ == "__main__": | ||
unittest.main() |