Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: 8bit/16bit, big-endian/little-endian in nexrad reader #231

Merged
merged 5 commits into from
Nov 2, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions xradar/io/backends/nexrad_level2.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,16 +594,15 @@
ngates = moments[name]["ngates"]
word_size = moments[name]["word_size"]
data_offset = moments[name]["data_offset"]
ws = {8: 1, 16: 2}
width = ws[word_size]
width = {8: 1, 16: 2}[word_size]
data = []
self.rh.pos += data_offset
data.append(self._rh.read(ngates, width=width).view(f"uint{word_size}"))
data.append(self._rh.read(ngates, width=width).view(f">u{width}"))
while self.init_next_record() and self.record_number <= stop:
if self.record_number in intermediate_records:
continue
self.rh.pos += data_offset
data.append(self._rh.read(ngates, width=width).view(f"uint{word_size}"))
data.append(self._rh.read(ngates, width=width).view(f">u{width}"))
moments[name].update(data=data)

def get_data_header(self):
Expand Down Expand Up @@ -1241,9 +1240,9 @@
- len(datastore.ds["intermediate_records"])
)
nbins = max([v["ngates"] for k, v in datastore.ds["sweep_data"].items()])
self.dtype = np.dtype("uint8")
if name == "PHI":
self.dtype = np.dtype("uint16")
word_size = datastore.ds["sweep_data"][name]["word_size"]
width = {8: 1, 16: 2}[word_size]
self.dtype = np.dtype(f">u{width}")
self.shape = (nrays, nbins)

def _getitem(self, key):
Expand All @@ -1253,8 +1252,11 @@
except KeyError:
self.datastore.root.get_data(self.group, self.name)
data = self.datastore.ds["sweep_data"][self.name]["data"]
# see 3.2.4.17.6 Table XVII-I Data Moment Characteristics and Conversion for Data Names
if self.name == "PHI":
kmuehlbauer marked this conversation as resolved.
Show resolved Hide resolved
x = np.uint16(0x3FF)
x = np.uint16(0x3FF) # 10 bit mask

Check warning on line 1257 in xradar/io/backends/nexrad_level2.py

View check run for this annotation

Codecov / codecov/patch

xradar/io/backends/nexrad_level2.py#L1257

Added line #L1257 was not covered by tests
elif self.name == "ZDR":
x = np.uint16(0x7FF) # 11 bit mask

Check warning on line 1259 in xradar/io/backends/nexrad_level2.py

View check run for this annotation

Codecov / codecov/patch

xradar/io/backends/nexrad_level2.py#L1259

Added line #L1259 was not covered by tests
else:
x = np.uint8(0xFF)
if len(data[0]) < self.shape[1]:
Expand Down