Skip to content

Commit

Permalink
Support custom truncated Thies LNM format
Browse files Browse the repository at this point in the history
  • Loading branch information
siiptuo committed Apr 18, 2024
1 parent 446acbd commit eb94fb7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
19 changes: 13 additions & 6 deletions cloudnetpy/instruments/disdrometer/thies.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,13 @@ def _append_data(self) -> None:

def _read_line(self, line: str, timestamp: datetime.datetime | None = None):
raw_values = line.split(";")
if len(raw_values) != 521:
# Support custom truncated format used in Leipzig LIM.
expected_columns = self.site_meta.get("truncate_columns", 521)
if len(raw_values) != expected_columns:
return
for i, key in TELEGRAM4:
if i >= expected_columns - 1:
break
value: Any
if key == "_date":
value = _parse_date(raw_values[i])
Expand Down Expand Up @@ -227,11 +231,12 @@ def _read_line(self, line: str, timestamp: datetime.datetime | None = None):
else:
value = int(raw_values[i])
self.raw_data[key].append(value)
self.raw_data["spectrum"].append(
np.array(list(map(int, raw_values[79:-2])), dtype="i2").reshape(
self.n_diameter, self.n_velocity
if expected_columns > 79:
self.raw_data["spectrum"].append(
np.array(list(map(int, raw_values[79:-2])), dtype="i2").reshape(
self.n_diameter, self.n_velocity
)
)
)
if timestamp is not None:
self.raw_data["time"].append(timestamp)
else:
Expand Down Expand Up @@ -266,7 +271,9 @@ def _create_diameter_vectors(self) -> None:

def _parse_date(date: str) -> datetime.date:
day, month, year = map(int, date.split("."))
return datetime.date(2000 + year, month, day)
if year < 100:
year += 2000
return datetime.date(year, month, day)


def _parse_time(time: str) -> datetime.time:
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/data/thies-lnm/2024041723-leipzig-lim.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
00;0747;2.50;17.04.2024;23:00:50;00;00;NP ;000.000;00;00;NP ;000.000;000.000;000.000;0087.76;99999;-9.9;100;0.0;0;0;
00;0747;2.50;17.04.2024;23:01:50;00;00;NP ;000.000;00;00;NP ;000.000;000.000;000.000;0087.76;99999;-9.9;100;0.0;0;0;
00;0747;2.50;17.04.2024;23:02:50;00;00;NP ;000.000;00;00;NP ;000.000;000.000;000.000;0087.76;99999;-9.9;100;0.0;0;0;
26 changes: 26 additions & 0 deletions tests/unit/test_disdrometer.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,32 @@ def test_processing(self):
)


class TestThies3(Check):
date = "2024-04-17"
temp_dir = TemporaryDirectory()
temp_path = temp_dir.name + "/test.nc"
filename = f"{SCRIPT_PATH}/data/thies-lnm/2024041723-leipzig-lim.txt"
site_meta = SITE_META
uuid = disdrometer.thies2nc(filename, temp_path, {**site_meta, "truncate_columns": 23}, date=date)

def test_processing(self):
assert self.nc.title == f'LNM disdrometer from {self.site_meta["name"]}'
assert self.nc.year == "2024"
assert self.nc.month == "04"
assert self.nc.day == "17"
assert self.nc.location == "Kumpula"
assert self.nc.cloudnet_file_type == "disdrometer"
assert self.nc.serial_number == "0747"
assert np.allclose(
self.nc["time"][:],
[
timedelta(hours=23, minutes=0, seconds=50) / timedelta(hours=1),
timedelta(hours=23, minutes=1, seconds=50) / timedelta(hours=1),
timedelta(hours=23, minutes=2, seconds=50) / timedelta(hours=1),
],
)


class TestInvalidCharacters(Check):
temp_dir = TemporaryDirectory()
temp_path = temp_dir.name + "/test.nc"
Expand Down

0 comments on commit eb94fb7

Please sign in to comment.