Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addressing #420 (for CCI Toolbox) #51

Merged
merged 4 commits into from
Mar 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Changes in 0.8.0 (in development)

* Provided xcube data store framework interface compatibility with
breaking changes in xcube 0.8.0 (see https://github.com/dcs4cop/xcube/issues/420).

## Changes in 0.7.0

* Fixed a bug that occurred when writing datasets obtained from Sentinel Hub to NetCDF file.
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
@@ -5,6 +5,6 @@ channels:
- defaults

dependencies:
- xcube >= 0.6.2
- xcube >=0.8.0
- oauthlib >=3.0
- requests-oauthlib >=1.3
22 changes: 18 additions & 4 deletions test/test_store.py
Original file line number Diff line number Diff line change
@@ -87,15 +87,29 @@ def test_get_data_opener_ids(self):

def test_get_data_ids(self):
store = new_data_store(SH_DATA_STORE_ID)
expected_set = {('S1GRD', 'Sentinel 1 GRD'),
('S2L1C', 'Sentinel 2 L1C'),
('S2L2A', 'Sentinel 2 L2A'),
('DEM', 'Digital Elevation Model'),}
expected_set = {'S1GRD',
'S2L1C',
'S2L2A',
'DEM'}
self.assertEqual(expected_set, set(store.get_data_ids()))
self.assertEqual(expected_set, set(store.get_data_ids(type_specifier='dataset')))
self.assertEqual(expected_set, set(store.get_data_ids(type_specifier='dataset[cube]')))
self.assertEqual(set(), set(store.get_data_ids(type_specifier='geodataframe')))

def test_get_data_ids_with_titles(self):
store = new_data_store(SH_DATA_STORE_ID)
expected_set = {('S1GRD', {'title': 'Sentinel 1 GRD'}),
('S2L1C', {'title': 'Sentinel 2 L1C'}),
('S2L2A', {'title': 'Sentinel 2 L2A'}),
('DEM', {'title': 'Digital Elevation Model'})}
self.assertEqual(expected_set, set(store.get_data_ids()))
self.assertEqual(expected_set, set(store.get_data_ids(type_specifier='dataset',
include_attrs=['title'])))
self.assertEqual(expected_set, set(store.get_data_ids(type_specifier='dataset[cube]',
include_attrs=['title'])))
self.assertEqual(set(), set(store.get_data_ids(type_specifier='geodataframe',
include_attrs=['title'])))

def test_get_open_data_params_schema(self):
store = new_data_store(SH_DATA_STORE_ID)
schema = store.get_open_data_params_schema('S2L2A')
26 changes: 22 additions & 4 deletions xcube_sh/store.py
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from typing import Iterator, Tuple, Optional, Dict, Any
from typing import Iterator, Tuple, Optional, Dict, Any, Union, Container

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

def get_data_ids(self, type_specifier: str = None, include_titles=True) -> Iterator[Tuple[str, Optional[str]]]:
def get_data_ids(self,
type_specifier: str = None,
include_attrs: Container[str] = None) -> \
Union[Iterator[str], Iterator[Tuple[str, Dict[str, Any]]]]:
return_tuples = include_attrs is not None
# TODO: respect names other than "title" in include_attrs
include_titles = return_tuples and 'title' in include_attrs
if self._is_supported_type_specifier(type_specifier):
if self._sentinel_hub is not None:
metadata = SentinelHubMetadata()
@@ -356,11 +362,23 @@ def get_data_ids(self, type_specifier: str = None, include_titles=True) -> Itera
if collection_dataset is not None:
dataset_name = collection_dataset.get('dataset_name')
if dataset_name is not None:
yield dataset_name, collection_title
if return_tuples:
if include_titles:
yield dataset_name, {'title': collection_title}
else:
yield dataset_name, {}
else:
yield dataset_name
else:
datasets = SentinelHubMetadata().datasets
for dataset_name, dataset_metadata in datasets.items():
yield dataset_name, dataset_metadata.get('title') if include_titles else None
if return_tuples:
if include_titles:
yield dataset_name, {'title': dataset_metadata.get('title')}
else:
yield dataset_name, {}
else:
yield dataset_name

def has_data(self, data_id: str, type_specifier: str = None) -> bool:
if self._is_supported_type_specifier(type_specifier):
2 changes: 1 addition & 1 deletion xcube_sh/version.py
Original file line number Diff line number Diff line change
@@ -19,4 +19,4 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

version = '0.7.0'
version = '0.8.0.dev0'