|
5 | 5 | import warnings |
6 | 6 | from copy import deepcopy |
7 | 7 |
|
8 | | -import esmvalcore.dataset |
9 | | - |
10 | 8 | if typing.TYPE_CHECKING: |
11 | 9 | import esmvalcore |
12 | | - from esmvalcore.dataset import Dataset |
| 10 | + import esmvalcore.dataset |
13 | 11 | from esmvalcore.typing import FacetValue |
14 | 12 |
|
15 | 13 | import dask |
@@ -849,18 +847,18 @@ def to_dask(self, **kwargs) -> xr.Dataset: |
849 | 847 |
|
850 | 848 | def to_iris( |
851 | 849 | self, |
852 | | - facets: dict[FacetValue, str], |
| 850 | + facet_map: dict['FacetValue', str], |
853 | 851 | cmorizer: typing.Any | None = None, |
854 | 852 | **kwargs, |
855 | | - ) -> esmvalcore.dataset.Dataset: |
| 853 | + ) -> 'esmvalcore.dataset.Dataset': |
856 | 854 | """ |
857 | 855 | Convert result to an ESMValCore Dataset. |
858 | 856 |
|
859 | 857 | This is only possible if the search returned exactly one result. |
860 | 858 |
|
861 | 859 | Parameters |
862 | 860 | ---------- |
863 | | - facets: dict[FacetValue, str] |
| 861 | + facet_map: dict[FacetValue, str] |
864 | 862 | Mapping of ESMValCore Dataset facets to their corresponding esm_datastore |
865 | 863 | attributes. For example, the mapping for a dataset containing keys |
866 | 864 | 'activity_id', 'source_id', 'member_id', 'experiment_id' would look like: |
@@ -891,8 +889,15 @@ def to_iris( |
891 | 889 | raise ValueError( |
892 | 890 | f'Expected exactly one dataset. Received {len(self)} datasets. Please refine your search.' |
893 | 891 | ) |
| 892 | + else: |
| 893 | + from esmvalcore.dataset import Dataset |
| 894 | + |
| 895 | + ds = Dataset(**facet_map) |
894 | 896 |
|
895 | | - ds = Dataset(**facets) |
| 897 | + ds.files = self.unique().path |
| 898 | + ds.augment_facets() |
| 899 | + |
| 900 | + return ds |
896 | 901 |
|
897 | 902 | def _create_derived_variables(self, datasets, skip_on_error): |
898 | 903 | if len(self.derivedcat) > 0: |
|
0 commit comments