From 4c05966432666997e048fba87f87f90a34cfa1e8 Mon Sep 17 00:00:00 2001 From: Baudouin Raoult Date: Thu, 22 Feb 2024 18:47:35 +0000 Subject: [PATCH 1/3] update --- climetlab/readers/netcdf/field.py | 4 +++- climetlab/readers/netcdf/fieldset.py | 20 ++++++-------------- tests/readers/test_netcdf_reader.py | 2 +- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/climetlab/readers/netcdf/field.py b/climetlab/readers/netcdf/field.py index 3ff3a46b..6c535cfb 100644 --- a/climetlab/readers/netcdf/field.py +++ b/climetlab/readers/netcdf/field.py @@ -95,7 +95,9 @@ def tidy(x): return x return tidy( - self.owner.xr_dataset[self.owner.xr_dataset[self.variable].grid_mapping].attrs + self.owner.xr_dataset[ + self.owner.xr_dataset[self.variable].grid_mapping + ].attrs ) # Compatibility to GRIb fields below diff --git a/climetlab/readers/netcdf/fieldset.py b/climetlab/readers/netcdf/fieldset.py index 8989b1da..1527caf6 100644 --- a/climetlab/readers/netcdf/fieldset.py +++ b/climetlab/readers/netcdf/fieldset.py @@ -181,6 +181,12 @@ class NetCDFFieldSetFromFileOrURL(NetCDFFieldSet): def __init__(self, path_or_url): self.path_or_url = path_or_url + @cached_property + def xr_dataset(self): + import xarray as xr + + return xr.open_dataset(self.path_or_url) + class NetCDFFieldSetFromFile(NetCDFFieldSetFromFileOrURL): def __init__(self, path): @@ -202,19 +208,12 @@ def __init__(self, url): def __repr__(self): return "NetCDFFieldSetFromURL(%s)" % (self.path_or_url,) - @cached_property - def xr_dataset(self): - import xarray as xr - - return xr.open_dataset(self.path_or_url) - class NetCDFMaskFieldSet(NetCDFFieldSet, MaskIndex): def __init__(self, *args, **kwargs): MaskIndex.__init__(self, *args, **kwargs) self.path = "" - @cached_property def fields(self): return list(self.index[i] for i in self.indices) @@ -240,13 +239,6 @@ def fields(self): result.extend(s.fields) return result - # @cached_property - # def dataset(self): - # return self.to_xarray(combine="by_coords") - - # def __iter__(self): - # return MultiIndex.__iter__(self) - def __len__(self): return MultiIndex.__len__(self) diff --git a/tests/readers/test_netcdf_reader.py b/tests/readers/test_netcdf_reader.py index 664af369..a8ddbfa8 100644 --- a/tests/readers/test_netcdf_reader.py +++ b/tests/readers/test_netcdf_reader.py @@ -27,7 +27,7 @@ def test_netcdf(): def test_dummy_netcdf_reader_1(): s = load_source("file", climetlab_file("docs/examples/test.nc")) r = s._reader - assert str(r).startswith("NetCDFReader"), r + assert str(r).startswith("NetCDFFieldSetFromFile"), r assert len(r) == 2 assert isinstance(r[1], NetCDFField), r From eb9d42871feb1384ab20b7a6e2fe6a497513b5b9 Mon Sep 17 00:00:00 2001 From: Florian Pinault Date: Fri, 23 Feb 2024 07:40:34 +0000 Subject: [PATCH 2/3] qa --- climetlab/readers/grib/output.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/climetlab/readers/grib/output.py b/climetlab/readers/grib/output.py index 2714f722..a2499f51 100644 --- a/climetlab/readers/grib/output.py +++ b/climetlab/readers/grib/output.py @@ -199,9 +199,9 @@ def update_metadata(self, handle, metadata, compulsary): if "number" in metadata: compulsary += ("numberOfForecastsInEnsemble",) productDefinitionTemplateNumber = {"tp": 11} - metadata[ - "productDefinitionTemplateNumber" - ] = productDefinitionTemplateNumber.get(handle.get("shortName"), 1) + metadata["productDefinitionTemplateNumber"] = ( + productDefinitionTemplateNumber.get(handle.get("shortName"), 1) + ) if metadata.get("type") in ("pf", "cf"): metadata.setdefault("typeOfGeneratingProcess", 4) From f5c0ebcd199264ef7d65de37b82b6b330b327847 Mon Sep 17 00:00:00 2001 From: Florian Pinault Date: Fri, 23 Feb 2024 07:41:22 +0000 Subject: [PATCH 3/3] Bump version 0.21.0 --- climetlab/version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/climetlab/version b/climetlab/version index c7f4ab0c..88541566 100644 --- a/climetlab/version +++ b/climetlab/version @@ -1 +1 @@ -0.20.15 +0.21.0