Skip to content

Commit

Permalink
Fix nearest-station with --format=json
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Apr 9, 2023
1 parent 8c9e684 commit ba8b745
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ phenodata changelog

development
===========
- Fix ``nearest-station`` with ``--format=json``

2020-12-29 0.11.0
=================
Expand Down
16 changes: 3 additions & 13 deletions phenodata/dwd/pheno.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down

0 comments on commit ba8b745

Please sign in to comment.