Skip to content

Commit

Permalink
Handle invalid timestamps in CT25K
Browse files Browse the repository at this point in the history
  • Loading branch information
siiptuo committed Jan 29, 2025
1 parent 24c21c1 commit 3cc8a80
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions cloudnetpy/instruments/vaisala.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,23 @@ def _read_header_line_2(lines: list) -> dict:
values = [[line[0], line[1], line[3:20], line[21:].strip()] for line in lines]
return values_to_dict(fields, values)

def _sort_time(self) -> None:
"""Sorts timestamps and removes duplicates."""
time = np.copy(self.data["time"][:])
ind_sorted = np.argsort(time)
ind_valid: list[int] = []
for ind in ind_sorted:
if time[ind] not in time[ind_valid]:
ind_valid.append(ind)
n_time = len(time)
for key, array in self.data.items():
if not hasattr(array, "shape"):
continue
if array.ndim == 1 and array.shape[0] == n_time:
self.data[key] = self.data[key][ind_valid]
if array.ndim == 2 and array.shape[0] == n_time:
self.data[key] = self.data[key][ind_valid, :]


class ClCeilo(VaisalaCeilo):
"""Base class for Vaisala CL31/CL51 ceilometers."""
Expand Down Expand Up @@ -253,23 +270,6 @@ def read_ceilometer_file(self, calibration_factor: float | None = None) -> None:
self._store_ceilometer_info()
self._sort_time()

def _sort_time(self) -> None:
"""Sorts timestamps and removes duplicates."""
time = np.copy(self.data["time"][:])
ind_sorted = np.argsort(time)
ind_valid: list[int] = []
for ind in ind_sorted:
if time[ind] not in time[ind_valid]:
ind_valid.append(ind)
n_time = len(time)
for key, array in self.data.items():
if not hasattr(array, "shape"):
continue
if array.ndim == 1 and array.shape[0] == n_time:
self.data[key] = self.data[key][ind_valid]
if array.ndim == 2 and array.shape[0] == n_time:
self.data[key] = self.data[key][ind_valid, :]

def _store_ceilometer_info(self) -> None:
n_gates = self.data["beta_raw"].shape[1]
if n_gates < 1540:
Expand Down Expand Up @@ -335,6 +335,7 @@ def read_ceilometer_file(self, calibration_factor: float | None = None) -> None:
self.data["calibration_factor"] = calibration_factor or 1.0
self.data["beta_raw"] *= self.data["calibration_factor"]
self.data["zenith_angle"] = np.median(self.metadata["zenith_angle"])
self._sort_time()

@staticmethod
def _parse_hex_profiles(lines: list) -> list:
Expand Down

0 comments on commit 3cc8a80

Please sign in to comment.