Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
thorbjoernl committed Sep 5, 2024
1 parent b77ab63 commit c55c3ad
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/pyaro/timeseries/Filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,8 @@ def __init__(self, topo_file: str | None = None, topo_var: str = "topography", r
Note:
-----
Stations will be kept if abs(altobs-altmod) <= rdiff
- Stations will be kept if abs(altobs-altmod) <= rdiff.
- Stations will not be kept if station altitude is NaN.
"""
self._topo_file = topo_file
self._topo_var = topo_var
Expand Down Expand Up @@ -929,11 +930,11 @@ def _find_lat_lon_variables(self):
continue

self._time = "time"
# TODO: Time does not have a unit. Decide what to do about it.
# TODO: Time does not have a unit that is parsed by cfunits. Decide what to do about it.
if any(x is None for x in [self._time, self._lat, self._lon]):
raise ValueError(f"Required variable names for lat, lon dimensions could not be found in file '{self._topo_file}")

def _model_altitude_from_lat_lon(self, lat: float, lon: float) -> float:
def _gridded_altitude_from_lat_lon(self, lat: float, lon: float) -> float:
# TODO: Include a tolerance?
data = self._topography.sel({self._lat: lat, self._lon: lon}, method="nearest")

Expand Down Expand Up @@ -970,16 +971,16 @@ def filter_stations(self, stations: dict[str, Station]) -> dict[str, Station]:
if self._topography is None:
return stations

new_stations = dict()
filtered_stations = dict()

for name, station in stations.items():
lat = station["latitude"]
lon = station["longitude"]

altobs = station["altitude"]
altmod = self._model_altitude_from_lat_lon(lat, lon)
topo = self._gridded_altitude_from_lat_lon(lat, lon)

if self._is_close(altmod, altobs):
new_stations[name] = station
if not math.isnan(altobs) and self._is_close(topo, altobs):
filtered_stations[name] = station

return new_stations
return filtered_stations

0 comments on commit c55c3ad

Please sign in to comment.