Skip to content

Commit

Permalink
Merge pull request #774 from dcs4cop/forman-xxx-allow_computing_mldat…
Browse files Browse the repository at this point in the history
…aset

xcube Server to allow for custom Multi-Level Datasets, Part 2
  • Loading branch information
forman authored Dec 14, 2022
2 parents 5a217bd + 8e04dde commit 1d4d9c2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
6 changes: 5 additions & 1 deletion test/core/mldataset/test_computed.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,12 @@ def assert_computed_ml_dataset_ok(
self,
computed_ml_ds: ComputedMultiLevelDataset
):
# assert output is same as input
self.assertEqual(3, computed_ml_ds.num_levels)
self.assertEqual(1, computed_ml_ds.num_inputs)
self.assertEqual(computed_ml_ds.grid_mapping,
computed_ml_ds.get_input_dataset(0).grid_mapping)

# assert output is same as input
base_dataset = computed_ml_ds.get_dataset(0)
self.assertEqual({'lon', 'lat',
'lat_bnds', 'lon_bnds',
Expand Down
19 changes: 16 additions & 3 deletions xcube/core/mldataset/computed.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

from xcube.core.byoa import CodeConfig
from xcube.core.byoa import FileSet
from xcube.core.gridmapping import GridMapping
from xcube.util.assertions import assert_given
from xcube.util.assertions import assert_instance
from xcube.util.assertions import assert_true
Expand Down Expand Up @@ -137,11 +138,23 @@ def get_callable(

return callable_ref, callable_obj

@property
def num_inputs(self) -> int:
return len(self._input_ml_dataset_ids)

def get_input_dataset(self, index: int) -> MultiLevelDataset:
return self._input_ml_dataset_getter(
self._input_ml_dataset_ids[index]
)

def _get_num_levels_lazily(self) -> int:
ds_0 = self._input_ml_dataset_getter(self._input_ml_dataset_ids[0])
return ds_0.num_levels
return self.get_input_dataset(0).num_levels

def _get_grid_mapping_lazily(self) -> GridMapping:
return self.get_input_dataset(0).grid_mapping

def _get_dataset_lazily(self, index: int,
def _get_dataset_lazily(self,
index: int,
parameters: Dict[str, Any]) -> xr.Dataset:
input_datasets = [
self._input_ml_dataset_getter(ds_id).get_dataset(index)
Expand Down

0 comments on commit 1d4d9c2

Please sign in to comment.