Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix 0 elevation bug in relalt filter #75

Merged
merged 2 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/pyaro/timeseries/Filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1315,14 +1315,22 @@ def _calculate_relative_altitude(
# At most one degree of latitude (at equator) is roughly 111km.
# Subsetting to based on this value with safety margin makes the
# distance calculation MUCH more efficient.
s = 0.1 + (radius / 1000) / 100
topo = topo.sel(lon=slice(lon - s, lon + s), lat=slice(lat - s, lat + s))
if radius < 100_000:
margin = 0.1 + (radius / 1_000) / 100
if lat >= 88 or lat <= -88:
# Include 360deg longitude near poles because poles are weird.
topo = topo.sel(lat=slice(lat - margin, lat + margin))
else:
topo = topo.sel(
lon=slice(lon - margin, lon + margin),
lat=slice(lat - margin, lat + margin),
)

distances = haversine(topo["lon"], topo["lat"], lon, lat)
within_radius = distances <= radius

values_within_radius = topo[self._topo_var].where(
within_radius, other=False, drop=True
within_radius, other=np.nan, drop=True
)

min_value = float(values_within_radius.min(skipna=True))
Expand Down
2 changes: 1 addition & 1 deletion tests/test_CSVTimeSeriesReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ def test_valley_floor_filter(self):
"flag": "0",
},
) as ts:
self.assertEqual(len(ts.stations()), 1)
self.assertEqual(len(ts.stations()), 3)


if __name__ == "__main__":
Expand Down
Loading