3

I have a dataset:

ID       Time                Lat        Long   
a    2016-06-01 10:35:26    41.79925   -71.33052  
a    2016-06-01 10:35:57    41.80174   -71.33307
a    2016-06-01 10:37:30    41.79259   -71.31087 
a    2016-06-01 19:21:34    41.65239   -70.95343  
a    2016-06-01 19:22:36    41.65485   -70.97474  
a    2016-06-01 19:23:07    41.65504   -70.98545  

I want to get hourly temperature data(assume temperature remain the same during hour) for each point based on GPS and timestamp, since the data are consecutive vehicle trajectory data. The expected outcome would be:

ID       Time                Lat        Long       TempHourly
a    2016-06-01 10:35:26    41.79925   -71.33052     70
a    2016-06-01 10:35:57    41.80174   -71.33307     70
a    2016-06-01 10:37:30    41.79259   -71.31087     70 
a    2016-06-01 19:21:34    41.65239   -70.95343     65
a    2016-06-01 19:22:36    41.65485   -70.97474     65
a    2016-06-01 19:23:07    41.65504   -70.98545     65   

Is there any free APIs that I can get accessed to fetch the temperature data?

  • Please edit your question, it is unclear. What do you mean with hourly temperature data? How can the example you give return equal temperatures for different locations? – Jan Doggen Jan 1 '17 at 12:48
4

I recommend trying rnoaa https://cran.rstudio.com/web/packages/rnoaa/ - It's an interface to many different data sources from NOAA.

df <- data.frame(
  id = letters[1:6], 
  time = c("2016-06-01 10:35:26", "2016-06-01 10:35:57", "2016-06-01 10:37:30",
           "2016-06-01 19:21:34", "2016-06-01 19:22:36", "2016-06-01 19:23:07"),
  latitude = c(41.79925, 41.80174, 41.79259, 41.65239, 41.65485, 41.65504),
  longitude = c(-71.33052, -71.33307, -71.31087, -70.95343, -70.97474, -70.98545),
  stringsAsFactors = FALSE
)

Using rnoaa you can access data from Integrated Surface Data (ISD) which has hourly data, but not sub-hourly

library(rnoaa)

For each point you can do something like:

x <- isd_stations_search(lat = df$latitude[1], lon = df$longitude[1], radius = 10)
dat <- isd(usaf = x$usaf[1], wban = x$wban[1], year = 2016)

library(dplyr)
library(lubridate)
dat %>% 
  filter(date == "20160601", time == paste0(hour(df$time[1]), "00")) %>% 
  select(starts_with("temperature"))

#> # A tibble: 1 × 4
#> temperature temperature_quality temperature_dewpoint temperature_dewpoint_quality
#> <chr>               <chr>                <chr>                        <chr>
#> 1       +0197                   1                +9999                            9

ISD data is not cleaned up so e.g., temperature has to be divided by 10, so 197/10 = 19.7

  • Thanks for the help, wondering what's the quota limits, since I have quite a lot points to query. – Demo Jan 2 '17 at 18:54
  • rnoaa::isd() is pulling from an FTP server, so it's not an API, no limits. – sckott Jan 2 '17 at 19:05
  • Great to know, reading the package file now. Will try it soon. Thanks a lot! – Demo Jan 2 '17 at 19:25
  • I'd say, the date in variable dat is of form '2016-06-01". – Demo Jan 5 '17 at 19:04
  • for dat %>%>..., I get Error in UseMethod("filter_") : no applicable method for 'filter_' applied to an object of class "isd" – poitroae Jul 14 '17 at 13:59
1

Firstly, latitiude/longitude with resolution to 5 decimals places corresponds to 1.1 meter (reference). I would imagine that the first step would to to find the nearest weather station, based on each lat/long pairs. Unless your geo-locations are coincidentally weather stations, you can't get super-resolution weather measurements (without computational modeling).


As for an API with historical data, Wunderground is often suggested on this site (example). For limited requests there is a free quota. Here is documentation for that endpoint. Note that the historical weather measurement does have a timestamp but is not an timeseries with more than daily resolution. You have some other temperatures such as min/max that you can also use.

Another endpoint is (geolookup), which will:

Returns the city name, zip code / postal code, latitude-longitude coordinates and nearby personal weather stations.

The specific URI would look like this

http://api.wunderground.com/api/Your_Key/geolookup/q/37.776289,-122.395234.json

and the details are in this screenshot

enter image description here


R has a package called rwunderground.

Tools for getting historical weather information and forecasts from wunderground.com. Historical weather and forecast data includes, but is not limited to, temperature, humidity, windchill, wind speed, dew point, heat index. Additionally, the weather underground weather API also includes information on sunrise/sunset, tidal conditions, satellite/webcam imagery, weather alerts, hurricane alerts and historical record high/low temperatures.

Another is weatherData (pdf)

Functions that help in fetching weather data from websites. Given a location and a date range, these functions help fetch weather data (temperature, pressure etc.) for any weather related analysis.



Another option would be getting the data from Google Big Query and corresponding R-package bigrquery

  • Thank you so much for the information provided! Another question, how to get weather station ID based on GPS coordinates? – Demo Jan 1 '17 at 18:33
  • I added an updated (see above) – philshem Jan 2 '17 at 14:28
  • Thanks for pointing me to all those references and sources, it really saves me a lot of time searching. – Demo Jan 5 '17 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.