Skip to content

Commit

Permalink
fix: raise error when product / tilt does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
CyanideCN committed Jan 7, 2025
1 parent fcba093 commit dd1d74b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions cinrad/io/level2.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,12 @@ def get_raw(
"""
# The scan number is set to zero in RHI mode.
self.tilt = tilt if self.scan_type == "PPI" else 0
if tilt not in self.data:
raise RadarDecodeError("Tilt {} does not exist.".format(tilt))
if dtype not in self.data[tilt]:
raise RadarDecodeError(
"Product {} does not exist in tilt {}".format(dtype, tilt)
)
if self.scan_type == "RHI":
max_range = self.scan_config[0].max_range1 / 1000
if drange > max_range:
Expand All @@ -774,10 +780,7 @@ def get_raw(
reso = self.scan_config[tilt].dop_reso / 1000
else:
reso = self.scan_config[tilt].log_reso / 1000
try:
raw = np.array(self.data[tilt][dtype])
except KeyError:
raise RadarDecodeError("Invalid product name")
raw = np.array(self.data[tilt][dtype])
ngates = int(drange // reso)
if raw.size == 0:
warnings.warn("Empty data", RuntimeWarning)
Expand Down Expand Up @@ -820,11 +823,11 @@ def get_data(self, tilt: int, drange: Number_T, dtype: str) -> xr.Dataset:
Returns:
xarray.Dataset: Data.
"""
ret = self.get_raw(tilt, drange, dtype)
if dtype in ["VEL", "SW", "VELSZ"]:
reso = self.scan_config[tilt].dop_reso / 1000
else:
reso = self.scan_config[tilt].log_reso / 1000
ret = self.get_raw(tilt, drange, dtype)
shape = ret[0].shape[1] if isinstance(ret, tuple) else ret.shape[1]
if self.scan_type == "PPI":
x, y, z, d, a = self.projection(reso)
Expand Down

0 comments on commit dd1d74b

Please sign in to comment.