-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'next' into release-0.08
- Loading branch information
Showing
10 changed files
with
219 additions
and
54 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
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 |
---|---|---|
@@ -1,23 +1,40 @@ | ||
from collections import OrderedDict | ||
from ocgis.conv.numpy_ import NumpyConverter | ||
from ocgis.test.base import TestBase | ||
import ocgis | ||
from ocgis.api.subset import SubsetOperation | ||
from ocgis.api.collection import SpatialCollection | ||
import itertools | ||
from ocgis.test.test_ocgis.test_api.test_parms.test_definition import TestGeom | ||
from ocgis.util.logging_ocgis import ProgressOcgOperations | ||
|
||
|
||
class Test(TestBase): | ||
class TestSubsetOperation(TestBase): | ||
|
||
def get_operations(self): | ||
rd = self.test_data.get_rd('cancm4_tas') | ||
slc = [None,[0,100],None,[0,10],[0,10]] | ||
ops = ocgis.OcgOperations(dataset=rd,slice=slc) | ||
return(ops) | ||
|
||
def test_constructor(self): | ||
for rb,p in itertools.product([True,False],[None,ProgressOcgOperations()]): | ||
sub = SubsetOperation(self.get_operations(),request_base_size_only=rb, | ||
progress=p) | ||
for ii,coll in enumerate(sub): | ||
self.assertIsInstance(coll,SpatialCollection) | ||
self.assertEqual(ii,0) | ||
slc = [None, [0, 100], None, [0, 10], [0, 10]] | ||
ops = ocgis.OcgOperations(dataset=rd, slice=slc) | ||
return ops | ||
|
||
def get_subset_operation(self): | ||
geom = TestGeom.get_geometry_dictionaries() | ||
rd = self.test_data.get_rd('cancm4_tas') | ||
ops = ocgis.OcgOperations(dataset=rd, geom=geom, select_nearest=True) | ||
subset = SubsetOperation(ops) | ||
return subset | ||
|
||
def test_init(self): | ||
for rb, p in itertools.product([True, False], [None, ProgressOcgOperations()]): | ||
sub = SubsetOperation(self.get_operations(), request_base_size_only=rb, progress=p) | ||
for ii, coll in enumerate(sub): | ||
self.assertIsInstance(coll, SpatialCollection) | ||
self.assertEqual(ii, 0) | ||
|
||
def test_geometry_dictionary(self): | ||
"""Test geometry dictionaries come out properly as collections.""" | ||
|
||
subset = self.get_subset_operation() | ||
conv = NumpyConverter(subset, None, None) | ||
coll = conv.write() | ||
self.assertEqual(coll.properties, OrderedDict([(1, {'COUNTRY': 'France', 'UGID': 1}), (2, {'COUNTRY': 'Germany', 'UGID': 2}), (3, {'COUNTRY': 'Italy', 'UGID': 3})])) |
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,42 @@ | ||
from collections import OrderedDict | ||
import os | ||
import fiona | ||
import ocgis | ||
from ocgis.api.subset import SubsetOperation | ||
from ocgis.conv.fiona_ import ShpConverter | ||
from ocgis.test.base import TestBase | ||
from ocgis.test.test_ocgis.test_api.test_parms.test_definition import TestGeom | ||
|
||
|
||
class TestShpConverter(TestBase): | ||
|
||
def get_subset_operation(self): | ||
geom = TestGeom.get_geometry_dictionaries() | ||
rd = self.test_data.get_rd('cancm4_tas') | ||
ops = ocgis.OcgOperations(dataset=rd, geom=geom, select_nearest=True, snippet=True) | ||
subset = SubsetOperation(ops) | ||
return subset | ||
|
||
def test_attributes_copied(self): | ||
"""Test attributes in geometry dictionaries are properly accounted for in the converter.""" | ||
|
||
subset = self.get_subset_operation() | ||
conv = ShpConverter(subset, self._test_dir, prefix='shpconv') | ||
ret = conv.write() | ||
|
||
path_ugid = os.path.join(self._test_dir, conv.prefix+'_ugid.shp') | ||
|
||
with fiona.open(path_ugid) as source: | ||
self.assertEqual(source.schema['properties'], OrderedDict([(u'COUNTRY', 'str'), (u'UGID', 'int:10')])) | ||
|
||
def test_none_geom(self): | ||
"""Test a NoneType geometry will pass through the Fiona converter.""" | ||
|
||
rd = self.test_data.get_rd('cancm4_tas') | ||
slc = [None, 0, None, [10, 20], [10, 20]] | ||
ops = ocgis.OcgOperations(dataset=rd, slice=slc) | ||
subset = SubsetOperation(ops) | ||
conv = ShpConverter(subset, self._test_dir, prefix='shpconv') | ||
ret = conv.write() | ||
contents = os.listdir(self._test_dir) | ||
self.assertEqual(len(contents), 5) |
Oops, something went wrong.