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 """