Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
#301 get spatial coverage from meta_info
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzysztof (Chris) Bernat committed Sep 19, 2017
1 parent 11f74b5 commit a9b9562
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
8 changes: 8 additions & 0 deletions cate/ds/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,14 @@ def temporal_coverage(self, monitor: Monitor = Monitor.NONE) -> Optional[TimeRan
return self._temporal_coverage

def spatial_coverage(self):
if not self._spatial_coverage and \
set(self._meta_info.keys()).issuperset({'bbox_minx', 'bbox_miny', 'bbox_maxx', 'bbox_maxy'}):
self._spatial_coverage = PolygonLike.convert(",".join([
self._meta_info.get('bbox_minx'),
self._meta_info.get('bbox_miny'),
self._meta_info.get('bbox_maxx'),
self._meta_info.get('bbox_maxy')])
)
return self._spatial_coverage

@property
Expand Down
24 changes: 19 additions & 5 deletions test/ds/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def test_load_old_datasource_from_json_dict(self):
'type': "FILE_PATTERN",
'data_store': 'local',
'temporal_coverage': "2001-01-01 00:00:00,2001-01-31 23:59:59",
'spatial_coverage': "0,10,20,30",
'spatial_coverage': "-180,-90,180,90",
'variables': ['var_test_1', 'var_test_2'],
'source': 'local.previous_test',
'last_update': None
Expand All @@ -95,20 +95,25 @@ def test_load_old_datasource_from_json_dict(self):
self.assertIsNotNone(data_source)
self.assertEqual(data_source.temporal_coverage(),
TimeRangeLike.convert(test_data.get('meta_data').get('temporal_coverage')))
self.assertEqual(data_source.spatial_coverage(),
PolygonLike.convert(test_data.get('meta_data').get('spatial_coverage')))
self.assertListEqual([var.get('name') for var in data_source.variables_info],
test_data.get('meta_data').get('variables'))

def test_load_datasource_from_json_dict(self):
test_data = { # noqa
test_data = {
'name': 'local.test_name2',
'meta_data': {
'type': "FILE_PATTERN",
'data_store': 'local',
'spatial_coverage': "0,10,20,30",
},
"meta_info": {
"temporal_coverage_start": "2001-01-01T00:00:00",
"temporal_coverage_end": "2001-01-31T23:59:59",
"bbox_maxx": "180.0",
"bbox_maxy": "90.0",
"bbox_minx": "-180.0",
"bbox_miny": "-90.0",
"variables": [
{
"name": "var_1",
Expand All @@ -130,8 +135,17 @@ def test_load_datasource_from_json_dict(self):
data_source = LocalDataSource.from_json_dict(json_dict=test_data, data_store=self.data_store)
self.assertIsNotNone(data_source)
self.assertEqual(data_source.temporal_coverage(),
TimeRangeLike.convert("{},{}".format(test_data.get('meta_info').get('temporal_coverage_start'),
test_data.get('meta_info').get('temporal_coverage_end'))))
TimeRangeLike.convert("{},{}".format(
test_data.get('meta_info').get('temporal_coverage_start'),
test_data.get('meta_info').get('temporal_coverage_end'))
))
self.assertEqual(data_source.spatial_coverage(),
PolygonLike.convert(",".join([
test_data.get('meta_info').get('bbox_minx'),
test_data.get('meta_info').get('bbox_miny'),
test_data.get('meta_info').get('bbox_maxx'),
test_data.get('meta_info').get('bbox_maxy'),
])))
self.assertListEqual(data_source.variables_info, test_data.get('meta_info').get('variables'))


Expand Down

0 comments on commit a9b9562

Please sign in to comment.