From 7e2b5d06a8cb5fc75866a7e948c76e2b1d6b2048 Mon Sep 17 00:00:00 2001 From: Norman Fomferra Date: Wed, 14 Dec 2022 11:05:20 +0100 Subject: [PATCH] fixed grid_mapping of computed ml datasets --- test/core/mldataset/test_computed.py | 6 +++++- xcube/core/mldataset/computed.py | 19 ++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/test/core/mldataset/test_computed.py b/test/core/mldataset/test_computed.py index 4bddb1a6c..9cec68f3c 100644 --- a/test/core/mldataset/test_computed.py +++ b/test/core/mldataset/test_computed.py @@ -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', diff --git a/xcube/core/mldataset/computed.py b/xcube/core/mldataset/computed.py index d851afcc1..87b2779fa 100644 --- a/xcube/core/mldataset/computed.py +++ b/xcube/core/mldataset/computed.py @@ -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 @@ -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)