Skip to content

Commit

Permalink
Fix rain gauge problems
Browse files Browse the repository at this point in the history
  • Loading branch information
tukiains committed Jan 20, 2025
1 parent 0f6d8d0 commit 09473ed
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
8 changes: 5 additions & 3 deletions src/processing/harmonizer/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ def get_valid_time_indices(self) -> list:
"""Finds valid time indices."""
time = self.nc_raw.variables["time"]
time_stamps = time[:]
raw_time_stamps = time_stamps.copy()

if "seconds since" in time.units:
time_stamps = np.array(cloudnetpy.utils.seconds2hours(time_stamps))
Expand All @@ -175,12 +176,13 @@ def get_valid_time_indices(self) -> list:
valid_ind: list[int] = []
for ind, t in enumerate(time_stamps):
if 0 <= t < max_time:
if t < 0:
if t < 0 or raw_time_stamps[ind] < 0:
continue
if len(valid_ind) > 1 and t <= time_stamps[valid_ind[-1]]:
if len(valid_ind) > 0 and t <= time_stamps[valid_ind[-1]]:
continue
valid_ind.append(ind)
if not valid_ind:
# Skip files with only one valid time stamp
if len(valid_ind) < 2:
raise cloudnetpy.exceptions.ValidTimeStampError
return valid_ind

Expand Down
8 changes: 0 additions & 8 deletions src/processing/harmonizer/rain_gauge.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,9 @@ def _copy_variable(self, key: str, time_ind: list):
var_out = self.nc.createVariable(
key, dtype, "time", zlib=True, fill_value=fill_value
)
self._copy_variable_attributes(variable, var_out)
screened_data = self._screen_data(variable, time_ind)
var_out[:] = screened_data

@staticmethod
def _copy_variable_attributes(var_in: netCDF4.Variable, var_out: netCDF4.Variable):
skip = ("_FillValue", "_Fill_Value", "description", "comment")
for attr in var_in.ncattrs():
if attr not in skip:
setattr(var_out, attr, getattr(var_in, attr))

def fix_variable_names(self):
keymap = {
"rain_rate": "rainfall_rate",
Expand Down

0 comments on commit 09473ed

Please sign in to comment.