|
| 1 | +from collections import OrderedDict |
| 2 | +from ocgis.conv.numpy_ import NumpyConverter |
1 | 3 | from ocgis.test.base import TestBase
|
2 | 4 | import ocgis
|
3 | 5 | from ocgis.api.subset import SubsetOperation
|
4 | 6 | from ocgis.api.collection import SpatialCollection
|
5 | 7 | import itertools
|
| 8 | +from ocgis.test.test_ocgis.test_api.test_parms.test_definition import TestGeom |
6 | 9 | from ocgis.util.logging_ocgis import ProgressOcgOperations
|
7 | 10 |
|
8 | 11 |
|
9 |
| -class Test(TestBase): |
10 |
| - |
| 12 | +class TestSubsetOperation(TestBase): |
| 13 | + |
11 | 14 | def get_operations(self):
|
12 | 15 | rd = self.test_data.get_rd('cancm4_tas')
|
13 |
| - slc = [None,[0,100],None,[0,10],[0,10]] |
14 |
| - ops = ocgis.OcgOperations(dataset=rd,slice=slc) |
15 |
| - return(ops) |
16 |
| - |
17 |
| - def test_constructor(self): |
18 |
| - for rb,p in itertools.product([True,False],[None,ProgressOcgOperations()]): |
19 |
| - sub = SubsetOperation(self.get_operations(),request_base_size_only=rb, |
20 |
| - progress=p) |
21 |
| - for ii,coll in enumerate(sub): |
22 |
| - self.assertIsInstance(coll,SpatialCollection) |
23 |
| - self.assertEqual(ii,0) |
| 16 | + slc = [None, [0, 100], None, [0, 10], [0, 10]] |
| 17 | + ops = ocgis.OcgOperations(dataset=rd, slice=slc) |
| 18 | + return ops |
| 19 | + |
| 20 | + def get_subset_operation(self): |
| 21 | + geom = TestGeom.get_geometry_dictionaries() |
| 22 | + rd = self.test_data.get_rd('cancm4_tas') |
| 23 | + ops = ocgis.OcgOperations(dataset=rd, geom=geom, select_nearest=True) |
| 24 | + subset = SubsetOperation(ops) |
| 25 | + return subset |
| 26 | + |
| 27 | + def test_init(self): |
| 28 | + for rb, p in itertools.product([True, False], [None, ProgressOcgOperations()]): |
| 29 | + sub = SubsetOperation(self.get_operations(), request_base_size_only=rb, progress=p) |
| 30 | + for ii, coll in enumerate(sub): |
| 31 | + self.assertIsInstance(coll, SpatialCollection) |
| 32 | + self.assertEqual(ii, 0) |
| 33 | + |
| 34 | + def test_geometry_dictionary(self): |
| 35 | + """Test geometry dictionaries come out properly as collections.""" |
| 36 | + |
| 37 | + subset = self.get_subset_operation() |
| 38 | + conv = NumpyConverter(subset, None, None) |
| 39 | + coll = conv.write() |
| 40 | + self.assertEqual(coll.properties, OrderedDict([(1, {'COUNTRY': 'France', 'UGID': 1}), (2, {'COUNTRY': 'Germany', 'UGID': 2}), (3, {'COUNTRY': 'Italy', 'UGID': 3})])) |
0 commit comments