CDJellen / ndbc-api

A Python API for retrieving meteorological and oceanographic data from the National Data Buoy Center (NDBC).
MIT License
11 stars 3 forks source link

`api.nearest_station()` returning different results when using floats or strings #48

Closed ks905383 closed 16 hours ago

ks905383 commented 19 hours ago

I tried grabbing a buoy close to NYC, and it seems like the nearest_station function returns different results when specifying lat/lon as floats instead of as strings.

from ndbc_api import NdbcApi

api = NdbcApi()

# Testing closest buoy to NYC
# Using string representation (returns Station 44025 on Long Island, correctly) 
print(api.station(station_id=api.nearest_station(lat='40N',lon='73W')))

# Using float representation (both return Station 46070 in the Bering Sea, incorrectly)
print(api.station(station_id=api.nearest_station(lat=40,lon=-73)))
print(api.station(station_id=api.nearest_station(lat=40,lon=180+(180-73))))

(I believe a similar issue happens in the example notebook, with the station by 38.88N, 76.43W identified as tplm2 when using strings, 23226 when using floats)

This is related to JOSS review https://github.com/openjournals/joss-reviews/issues/7406

CDJellen commented 18 hours ago

Thank you for opening this issue @ks905383 ; I will validate the handling of float-valued latitudes and longitudes shortly. This is likely a failure to properly handle East West conventions when querying the NDBC data service.

I'll work to have a fix in place and a new release up over the next few days.

ks905383 commented 16 hours ago

Apologies, this actually seems to have been fixed with the latest version.

I had python==3.13.0 in the environment I was testing this in, so pip and conda installed an older version instead.