Skip to content

Commit

Permalink
addressing #88
Browse files Browse the repository at this point in the history
  • Loading branch information
forman committed Dec 6, 2022
1 parent e0fbaae commit 4d1b794
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Changes in 0.9.6 (in development)

* Implemented performance optimizations for use of datasets
in xcube server. (#88)
* The open parameter `variable_names` in the `sentinelhub` data store
is now optional.
* Fixed some import statements to be compatible with Python 3.10.
Expand Down
18 changes: 15 additions & 3 deletions test/test_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

import collections.abc
import unittest

import numpy as np
Expand Down Expand Up @@ -106,17 +107,28 @@ class CubeTest(unittest.TestCase):
def test_open_cube(self):
cube = open_cube(cube_config=cube_config)
self.assertIsInstance(cube, xr.Dataset)
self.assert_has_zarr_store(cube)

def test_time_max_none(self):
cube = open_cube(cube_config=cube_config_t1_none)
self.assertIsInstance(cube, xr.Dataset)
self.assertEqual(np.datetime64('today', 'D'), np.datetime64(cube.time.values[-1], 'D')) # self.assertEqual()
self.assertEqual(np.datetime64('today', 'D'),
np.datetime64(cube.time.values[-1], 'D'))
self.assert_has_zarr_store(cube)

def test_time_none(self):
cube = open_cube(cube_config=cube_config_t_none)
self.assertIsInstance(cube, xr.Dataset)
self.assertEqual(np.datetime64('2021-02-16'), np.datetime64(cube.time.values[-1], 'D')) # self.assertEqual()
self.assertEqual(np.datetime64('2015-06-27'), np.datetime64(cube.time.values[0], 'D')) # self.assertEqual()
self.assertEqual(np.datetime64('2021-02-16'),
np.datetime64(cube.time.values[-1], 'D'))
self.assertEqual(np.datetime64('2015-06-27'),
np.datetime64(cube.time.values[0], 'D'))
self.assert_has_zarr_store(cube)

def assert_has_zarr_store(self, cube):
if hasattr(cube, 'zarr_store'):
self.assertIsInstance(cube.zarr_store.get(),
collections.abc.Mapping)


@unittest.skipUnless(HAS_SH_CREDENTIALS, REQUIRE_SH_CREDENTIALS)
Expand Down
7 changes: 6 additions & 1 deletion xcube_sh/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,9 @@ def open_cube(cube_config: CubeConfig,
trace_store_calls=trace_store_calls)
if max_cache_size:
cube_store = zarr.LRUStoreCache(cube_store, max_cache_size)
return xr.open_zarr(cube_store)

cube = xr.open_zarr(cube_store)
if hasattr(cube, 'zarr_store'):
cube.zarr_store.set(cube_store)

return cube
7 changes: 6 additions & 1 deletion xcube_sh/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,12 @@ def open_data(self, data_id: str, **open_params) -> xr.Dataset:
if max_cache_size:
chunk_store = zarr.LRUStoreCache(chunk_store,
max_size=max_cache_size)
return xr.open_zarr(chunk_store, **open_params)
cube = xr.open_zarr(chunk_store, **open_params)

if hasattr(cube, 'zarr_store'):
cube.zarr_store.set(chunk_store)

return cube

##########################################################################
# Implementation helpers
Expand Down

0 comments on commit 4d1b794

Please sign in to comment.