Skip to content

Commit

Permalink
Merge branch 'main' into syedhamidali-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
syedhamidali committed Sep 19, 2024
2 parents 0196aaa + 71ebcc6 commit 51afe2b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
8 changes: 6 additions & 2 deletions docs/history.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
16 changes: 8 additions & 8 deletions tests/io/test_datamet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
24 changes: 10 additions & 14 deletions xradar/io/backends/datamet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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, {})
Expand Down

0 comments on commit 51afe2b

Please sign in to comment.