diff --git a/docs/history.md b/docs/history.md index c8d17a3..142313f 100644 --- a/docs/history.md +++ b/docs/history.md @@ -1,8 +1,12 @@ # History -## 0.6.4 (2024-08-31) +## development version -ADD: Added `apply_to_sweeps` function for applying custom operations to all sweeps in a `DataTree` radar volume. This function allows users to apply a specified function to each sweep, with options for passing additional arguments and handling errors gracefully. Implemented by [@syedhamidali](https://github.com/syedhamidali), ({pull}`202`). +* FIX: do not apply scale/offset in datamet reader, leave it to xarray instead ({pull}`209`) by [@kmuehlbauer](https://github.com/kmuehlbauer). + +* ADD: Added `apply_to_sweeps` function for applying custom operations to all sweeps in a `DataTree` radar volume. +This function allows users to apply a specified function to each sweep, with options for passing additional arguments +and handling errors gracefully. Implemented by [@syedhamidali](https://github.com/syedhamidali), ({pull}`202`). ## 0.6.4 (2024-08-30) diff --git a/tests/io/test_datamet.py b/tests/io/test_datamet.py index 7a1a8f2..5b1838a 100644 --- a/tests/io/test_datamet.py +++ b/tests/io/test_datamet.py @@ -44,14 +44,14 @@ def test_moment_metadata(data): @pytest.mark.parametrize( "moment, expected_value", [ - ("UZ", -3.5), - ("CZ", -3.5), - ("V", 2.3344999999999985), - ("W", 16.0), - ("ZDR", 0.6859999999999999), - ("PHIDP", 94.06648), - ("RHOHV", 1.9243000000000001), - ("KDP", 0.5190000000000001), + ("UZ", 56), + ("CZ", 56), + ("V", 139), + ("W", 30), + ("ZDR", 137), + ("PHIDP", 16952), + ("RHOHV", 237), + ("KDP", 67), ], ) def test_moment_data(data, moment, expected_value): diff --git a/xradar/io/backends/datamet.py b/xradar/io/backends/datamet.py index 420bf73..23d4f9e 100644 --- a/xradar/io/backends/datamet.py +++ b/xradar/io/backends/datamet.py @@ -163,24 +163,13 @@ def get_moment(self, mom, sweep): mom_path = os.path.join(".", mom, str(sweep + 1)) mom_medata = self.get_mom_metadata(mom, sweep) - offset = float(mom_medata.get("offset") or 1.0) - slope = float(mom_medata.get("slope") or 1.0) - maxval = mom_medata.get("maxval") - - if maxval: - maxval = float(maxval) - top = 255 - bottom = float(mom_medata["bottom"]) - slope = (maxval - offset) / (top - bottom) - bitplanes = 16 if mom == "PHIDP" else int(mom_medata["bitplanes"] or 8) nazim = int(mom_medata.get("nlines")) nrange = int(mom_medata.get("ncols")) dtype = np.uint16 if bitplanes == 16 else np.uint8 data = self.extract_data(mom_path, dtype) - data = slope * np.reshape(data, (nazim, nrange)) + offset - data[data < offset + 1e-5] = np.nan + data = np.reshape(data, (nazim, nrange)) return data @@ -272,8 +261,15 @@ def open_store_variable(self, mom): encoding = {"group": self._group, "source": self._filename} mom_metadata = self.root.get_mom_metadata(mom, self._group) - add_offset = mom_metadata.get("offset") - scale_factor = mom_metadata.get("slope") + add_offset = float(mom_metadata.get("offset") or 0.0) + scale_factor = float(mom_metadata.get("slope") or 1.0) + maxval = mom_metadata.get("maxval", None) + + if maxval is not None: + maxval = float(maxval) + top = 255 + bottom = float(mom_metadata["bottom"]) + scale_factor = (maxval + add_offset) / (top - bottom) mname = datamet_mapping.get(mom, mom) mapping = sweep_vars_mapping.get(mname, {})