Skip to content

Commit f60acd2

Browse files
committed
Add elevation angle filter to HATPRO harmonizer
1 parent f4046a2 commit f60acd2

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

src/processing/harmonizer/hatpro.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class HatproNc(core.Level1Nc):
4949
def copy_file(self, all_keys: bool = False) -> None:
5050
"""Copies essential fields only."""
5151
valid_ind = self._get_valid_timestamps()
52+
valid_ind = self._filter_zenith_observations(valid_ind)
5253
if all_keys is True:
5354
possible_keys = None
5455
else:
@@ -98,6 +99,20 @@ def check_time_reference(self) -> None:
9899
if self.nc_raw.variables[key][:] != 1: # not UTC
99100
raise ValueError("Local time is not supported")
100101

102+
def _filter_zenith_observations(self, time_ind: list) -> list:
103+
"""Keeps only timestamps where elevation angle is close to 90°."""
104+
key = _find_elevation_angle_key(self.nc_raw)
105+
if key is None:
106+
return time_ind
107+
elevation = self.nc_raw.variables[key][time_ind]
108+
tolerance = 5.0
109+
mask = np.abs(elevation - 90.0) < tolerance
110+
filtered = np.array(time_ind)[mask].tolist()
111+
if not filtered:
112+
msg = "No valid timestamps with zenith observations found, check the elevation angle data"
113+
raise cloudnetpy.exceptions.ValidTimeStampError(msg)
114+
return filtered
115+
101116
def _get_valid_timestamps(self) -> list:
102117
time_stamps = self.nc_raw.variables["time"][:]
103118
epoch = _get_epoch(self.nc_raw.variables["time"].units)
@@ -109,7 +124,8 @@ def _get_valid_timestamps(self) -> list:
109124
):
110125
valid_ind.append(t_ind)
111126
if not valid_ind:
112-
raise cloudnetpy.exceptions.ValidTimeStampError
127+
msg = "No valid timestamps found, check the time data"
128+
raise cloudnetpy.exceptions.ValidTimeStampError(msg)
113129
_, ind = np.unique(time_stamps[valid_ind], return_index=True)
114130
return list(np.array(valid_ind)[ind])
115131

@@ -138,6 +154,13 @@ def _copy_hatpro_file_contents(
138154
self._copy_global_attributes()
139155

140156

157+
def _find_elevation_angle_key(nc: netCDF4.Dataset) -> str | None:
158+
for key in ("elevation_angle", "ElAng", "ele"):
159+
if key in nc.variables:
160+
return key
161+
return None
162+
163+
141164
def _get_epoch(units: str) -> datetime.datetime:
142165
fallback = datetime.datetime(2001, 1, 1, tzinfo=datetime.timezone.utc)
143166
try:

0 commit comments

Comments
 (0)