Skip to content

Commit f879040

Browse files
authored
Merge pull request #51 from dcs4cop/forman-420-include_attrs
Addressing #420 (for CCI Toolbox)
2 parents 4032c4b + 56a783a commit f879040

File tree

5 files changed

+47
-10
lines changed

5 files changed

+47
-10
lines changed

CHANGES.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## Changes in 0.8.0 (in development)
2+
3+
* Provided xcube data store framework interface compatibility with
4+
breaking changes in xcube 0.8.0 (see https://github.com/dcs4cop/xcube/issues/420).
5+
16
## Changes in 0.7.0
27

38
* Fixed a bug that occurred when writing datasets obtained from Sentinel Hub to NetCDF file.

environment.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ channels:
55
- defaults
66

77
dependencies:
8-
- xcube >= 0.6.2
8+
- xcube >=0.8.0
99
- oauthlib >=3.0
1010
- requests-oauthlib >=1.3

test/test_store.py

+18-4
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,29 @@ def test_get_data_opener_ids(self):
8787

8888
def test_get_data_ids(self):
8989
store = new_data_store(SH_DATA_STORE_ID)
90-
expected_set = {('S1GRD', 'Sentinel 1 GRD'),
91-
('S2L1C', 'Sentinel 2 L1C'),
92-
('S2L2A', 'Sentinel 2 L2A'),
93-
('DEM', 'Digital Elevation Model'),}
90+
expected_set = {'S1GRD',
91+
'S2L1C',
92+
'S2L2A',
93+
'DEM'}
9494
self.assertEqual(expected_set, set(store.get_data_ids()))
9595
self.assertEqual(expected_set, set(store.get_data_ids(type_specifier='dataset')))
9696
self.assertEqual(expected_set, set(store.get_data_ids(type_specifier='dataset[cube]')))
9797
self.assertEqual(set(), set(store.get_data_ids(type_specifier='geodataframe')))
9898

99+
def test_get_data_ids_with_titles(self):
100+
store = new_data_store(SH_DATA_STORE_ID)
101+
expected_set = {('S1GRD', {'title': 'Sentinel 1 GRD'}),
102+
('S2L1C', {'title': 'Sentinel 2 L1C'}),
103+
('S2L2A', {'title': 'Sentinel 2 L2A'}),
104+
('DEM', {'title': 'Digital Elevation Model'})}
105+
self.assertEqual(expected_set, set(store.get_data_ids()))
106+
self.assertEqual(expected_set, set(store.get_data_ids(type_specifier='dataset',
107+
include_attrs=['title'])))
108+
self.assertEqual(expected_set, set(store.get_data_ids(type_specifier='dataset[cube]',
109+
include_attrs=['title'])))
110+
self.assertEqual(set(), set(store.get_data_ids(type_specifier='geodataframe',
111+
include_attrs=['title'])))
112+
99113
def test_get_open_data_params_schema(self):
100114
store = new_data_store(SH_DATA_STORE_ID)
101115
schema = store.get_open_data_params_schema('S2L2A')

xcube_sh/store.py

+22-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2020
# SOFTWARE.
2121

22-
from typing import Iterator, Tuple, Optional, Dict, Any
22+
from typing import Iterator, Tuple, Optional, Dict, Any, Union, Container
2323

2424
import xarray as xr
2525
import zarr
@@ -340,7 +340,13 @@ def get_type_specifiers_for_data(self, data_id: str) -> Tuple[str, ...]:
340340
self._get_dataset_and_collection_metadata(data_id)
341341
return self.get_type_specifiers()
342342

343-
def get_data_ids(self, type_specifier: str = None, include_titles=True) -> Iterator[Tuple[str, Optional[str]]]:
343+
def get_data_ids(self,
344+
type_specifier: str = None,
345+
include_attrs: Container[str] = None) -> \
346+
Union[Iterator[str], Iterator[Tuple[str, Dict[str, Any]]]]:
347+
return_tuples = include_attrs is not None
348+
# TODO: respect names other than "title" in include_attrs
349+
include_titles = return_tuples and 'title' in include_attrs
344350
if self._is_supported_type_specifier(type_specifier):
345351
if self._sentinel_hub is not None:
346352
metadata = SentinelHubMetadata()
@@ -356,11 +362,23 @@ def get_data_ids(self, type_specifier: str = None, include_titles=True) -> Itera
356362
if collection_dataset is not None:
357363
dataset_name = collection_dataset.get('dataset_name')
358364
if dataset_name is not None:
359-
yield dataset_name, collection_title
365+
if return_tuples:
366+
if include_titles:
367+
yield dataset_name, {'title': collection_title}
368+
else:
369+
yield dataset_name, {}
370+
else:
371+
yield dataset_name
360372
else:
361373
datasets = SentinelHubMetadata().datasets
362374
for dataset_name, dataset_metadata in datasets.items():
363-
yield dataset_name, dataset_metadata.get('title') if include_titles else None
375+
if return_tuples:
376+
if include_titles:
377+
yield dataset_name, {'title': dataset_metadata.get('title')}
378+
else:
379+
yield dataset_name, {}
380+
else:
381+
yield dataset_name
364382

365383
def has_data(self, data_id: str, type_specifier: str = None) -> bool:
366384
if self._is_supported_type_specifier(type_specifier):

xcube_sh/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2020
# SOFTWARE.
2121

22-
version = '0.7.0'
22+
version = '0.8.0.dev0'

0 commit comments

Comments
 (0)