AustralianAntarcticDivision / ropenblog

Temp repo for rOpenSci blog article
2 stars 0 forks source link

rerddap alternative #4

Open mdsumner opened 5 years ago

mdsumner commented 5 years ago

I tried getting sea ice concentration with rerddap, here's the code for the OISST equivalent.

This just a placeholder for a possible comparison. I thought we might provide some equivalent alternatives, to highlight why we use the bb approach.

xinfo <- info("noaa_ncei_9bc6_2d0d_9403")

## use read = FALSE because it otherwise builds a data frame, 
## the temp .nc file name is available from the object
ice <- griddap(xinfo, fields = "ice", time =c("2018-10-06", "2018-10-07"), read = FALSE,    latitude = c(-70, -50), 
               longitude = c(100, 150))

xinfo 
#<ERDDAP info> noaa_ncei_9bc6_2d0d_9403 
# Dimensions (range):  
#     time: (1981-09-01T00:00:00Z, 2018-10-07T00:00:00Z) 
#     depth: (0.0, 0.0) 
#     latitude: (-89.875, 89.875) 
#     longitude: (0.125, 359.875) 
# Variables:  
#     anom: 
 #        Units: degree_C 
#    err: 
#         Units: degree_C 
#     ice: 
#         Units: percent 
#     sst: 
#         Units: degree_C 

That 7 October 2018 date is the most up to date for OISST, though there are many other candidates. The hardest thing is knowing which data set to go for.

I did a (messy) survey of the ice data available with

library(rerddap)
any_ice <- tibble::as_tibble(ed_search(query = "ice")$info)

subset(any_ice, grepl("Preliminary", title))
# A tibble: 4 x 3
  title                                                                                                                                                                      dataset_id               time_end            
  <chr>                                                                                                                                                                      <chr>                    <chr>               
1 SST, Daily Optimum Interpolation (OI), AVHRR Only, Version 2, Final+Preliminary, 1981-present, Lon+/-180                                                                   ncdcOisst2Agg_LonPM180   2018-10-07T00:00:00Z
2 SST, Daily Optimum Interpolation (OI), AVHRR Only, Version 2, Final+Preliminary, 1981-present                                                                              ncdcOisst2Agg            2018-10-07T00:00:00Z
3 OISST Preliminary Daily AVHRR-only Feature Collection, OISST Preliminary Daily AVHRR-only Feature Collection, Best Time Series [time], 2018-present                        noaa_ncei_e0da_f05c_ce3a 2018-07-11T00:00:00Z
4 OISST Preliminary Daily AVHRR-only Feature Collection, OISST Preliminary Daily AVHRR-only Feature Collection, Best Time Series [time][zlev][lat][lon], 0.25°, 2018-present noaa_ncei_bc65_340f_d832 2018-07-11T00:00:00Z

safe_info <- purrr::safely(rerddap::info)
ice_info <- purrr::map(any_ice$dataset_id, safe_info)

## extract out latest time available
fun <- function(x) {
  if (is.null(x$result)) return("NA")
  v <- x$result$alldata$NC_GLOBAL[x$result$alldata$NC_GLOBAL$attribute_name == "time_coverage_end", ]$value
  if (length(v) < 1) v <- NA_character_
  v
}
any_ice$time_end <- purrr::map_chr(ice_info, fun)
sckott commented 5 years ago

what is the "bb approach"?

mdsumner commented 5 years ago

bowerbird! (Oops sorry for using jargon)