Skip to content

Commit

Permalink
Fix truncation in unit conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
siiptuo committed Apr 17, 2024
1 parent 2e542d6 commit 976b0d2
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions cloudnetpy/instruments/disdrometer/common.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Module for reading / converting disdrometer data."""

from typing import Literal

import numpy as np

from cloudnetpy.cloudnetarray import CloudnetArray
Expand All @@ -15,15 +17,24 @@ def add_meta(self) -> None:
if name in valid_keys:
self.data[name] = CloudnetArray(float(value), name)

def _convert_data(self, keys: tuple, value: float, method: str = "divide") -> None:
def _convert_data(
self,
keys: tuple[str, ...],
value: float,
method: Literal["divide", "add"] = "divide",
) -> None:
for key in keys:
if key in self.data:
if method == "divide":
self.data[key].data = self.data[key].data / value
elif method == "add":
self.data[key].data = self.data[key].data + value
else:
raise ValueError
if key not in self.data:
continue
variable = self.data[key]
if method == "divide":
variable.data = variable.data.astype("f4") / value
variable.data_type = "f4"
elif method == "add":
variable.data = variable.data.astype("f4") + value
variable.data_type = "f4"
else:
raise ValueError

def store_vectors(
self,
Expand Down

0 comments on commit 976b0d2

Please sign in to comment.