From ba8b745823d1bb168b9ff4c700c62f299e5a1ef0 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Sun, 9 Apr 2023 23:09:52 +0200 Subject: [PATCH] Fix `nearest-station` with `--format=json` --- CHANGES.rst | 1 + phenodata/dwd/pheno.py | 16 +++------------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index a5b106e..436f2cc 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,7 @@ phenodata changelog development =========== +- Fix ``nearest-station`` with ``--format=json`` 2020-12-29 0.11.0 ================= diff --git a/phenodata/dwd/pheno.py b/phenodata/dwd/pheno.py index f4ffcc7..c845fbf 100644 --- a/phenodata/dwd/pheno.py +++ b/phenodata/dwd/pheno.py @@ -122,23 +122,13 @@ def get_stations(self, filter=None, all=False): def nearest_station(self, latitude, longitude, all=False): """ - Select most current stations datasets. - - Stolen from https://github.com/marians/dwd-weather + Select closest station. """ - closest = None - closest_distance = 99999999999 - for index, station in self.get_stations(all=all).iterrows(): - d = haversine_distance((longitude, latitude), - (station["geograph.Laenge"], station["geograph.Breite"])) - if d < closest_distance: - closest = station - closest_distance = d - return closest.to_frame() + return self.nearest_stations(latitude, longitude, all=all).head(1) def nearest_stations(self, latitude, longitude, all=False, limit=10): """ - Select most current stations datasets. + Select closest stations. Stolen from https://github.com/marians/dwd-weather """