Skip to content

Commit

Permalink
work on integrating vector data cubes
Browse files Browse the repository at this point in the history
  • Loading branch information
TonioF committed Nov 18, 2024
1 parent e490dd9 commit 969f1c4
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
11 changes: 11 additions & 0 deletions test/core/store/fs/impl/test_vectordatacube.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,22 @@

from xcube.core.new import new_vector_data_cube

from xcube.core.store import new_data_store
from xcube.core.store.datatype import VECTOR_DATA_CUBE_TYPE
from xcube.core.store.fs.impl.vectordatacube import VectorDataCubeZarrFsDataAccessor
from xcube.core.store.fs.impl.vectordatacube import VectorDataCubeNetcdfFsDataAccessor


class VectorDataCubeStoreTest(unittest.TestCase):

def test_write_to_and_read_from_store(self):
store = new_data_store("file")
vdc = new_vector_data_cube()
data_id = store.write_data(
vdc, data_id="vdc_test.zarr"
)
self.assertIsNotNone(data_id)

class VectorDataCubeZarrFsDataAccessorTest(unittest.TestCase):

@classmethod
Expand Down
19 changes: 19 additions & 0 deletions xcube/core/mldataset/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from collections.abc import Sequence

import xarray as xr
import xvec

from xcube.core.gridmapping import GridMapping
from xcube.core.tilingscheme import TilingScheme
Expand Down Expand Up @@ -148,3 +149,21 @@ def get_level_for_resolution(self, xy_res: ScalarOrPair[float]) -> int:
if x_res > given_x_res and y_res > given_y_res:
return max(0, level - 1)
return self.num_levels - 1


class VectorDataCube(xr.Dataset):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
for coord_name, coord_values in self.coords.items():
if isinstance(coord_values.to_index(), xvec.GeometryIndex):
return
raise ValueError(f"Dataset has no Coordinate with an xvec.GeometryIndex.")

@classmethod
def from_dataset(cls, dataset):
return cls(
data_vars=dataset.data_vars,
coords=dataset.coords,
attrs=dataset.attrs
)
2 changes: 2 additions & 0 deletions xcube/core/store/datatype.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ def register_default_data_types():
MULTI_LEVEL_DATASET_ITERATOR_TYPE,
GEO_DATA_FRAME_TYPE,
GEO_DATA_FRAME_ITERATOR_TYPE,
VECTOR_DATA_CUBE_TYPE,
VECTOR_DATA_CUBE_ITERATOR_TYPE,
]:
DataType.register_data_type(data_type)

Expand Down
6 changes: 5 additions & 1 deletion xcube/core/store/fs/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
from ..datatype import DataTypeLike
from ..datatype import GEO_DATA_FRAME_TYPE
from ..datatype import MULTI_LEVEL_DATASET_TYPE
from ..datatype import VECTOR_DATA_CUBE_TYPE
from ..descriptor import DataDescriptor
from ..descriptor import new_data_descriptor
from ..error import DataStoreError
Expand Down Expand Up @@ -443,7 +444,10 @@ def _guess_writer_id(self, data, data_id: str = None):
data_type = accessor_id_parts[0]
format_id = accessor_id_parts[1]
if isinstance(data, xr.Dataset):
data_type = DATASET_TYPE.alias
if len(data.xvec.geom_coords) > 0:
data_type = VECTOR_DATA_CUBE_TYPE.alias
else:
data_type = DATASET_TYPE.alias
format_id = format_id or "zarr"
elif isinstance(data, MultiLevelDataset):
data_type = MULTI_LEVEL_DATASET_TYPE.alias
Expand Down

0 comments on commit 969f1c4

Please sign in to comment.