Trying to apply the R tutorial for subsetting projected data from Polarwatch using the associated latitutde and long grid. Rather than selecting a circle of data over the pole, I'm tyring to select a "donut" of data around Antarctica. The first two problems are encountered in the code below. First, the line to create indices by subsetting the latitude range fails to subset based on latitude NORTH (e.g., > -75) of a particular latitude (it will work if you select for data SOUTH of a particular latitude (e..g, < -75)). Second, the resulting rowrange and colrange produce invalid ranges when the url is passed to ERDDAP in a browser window. The ERDDAP error for the url call is:
Error {
code=400;
message="Bad Request: Query error: For variable=seaice_conc_monthly_cdr axis#1=ygrid Constraint=\"[1:1:332]\": Stop=\"332\" is invalid. It must be an integer between 0 and 331.";
}
CODE
url <- 'https://polarwatch.noaa.gov/erddap/griddap/'
grid_id <- 'nsidcCDRice_sh_grid'
grid_urlcall <- paste0(url,grid_id,'.nc?longitude[(4337500.0):1:(-3937500.0)][(-3937500.0):1:(3937500.0)],latitude[(4337500.0):1:(-3937500.0)][(-3937500.0):1:(3937500.0)]')
sh_grid <- httr::GET(grid_urlcall, httr::write_disk("sh_grid.nc", overwrite=TRUE))
# Read the grid file
gridFid <- nc_open('sh_grid.nc')
ygrid <- ncvar_get(gridFid, varid="ygrid")
xgrid <- ncvar_get(gridFid, varid="xgrid")
longitude <- ncvar_get(gridFid, varid="longitude")
latitude <- ncvar_get(gridFid, varid="latitude")
nc_close(gridFid)
inds = which(latitude > -75, arr.ind=TRUE) # greater than -75 to limit southern extent of data
rowrange <- range(inds[,1])
colrange <- range(inds[,2])
#rowrange<-c(1,315) # indices calculated above exceed range of data on polarwatch
#colrange<-c(1, 331) # indices calculated above exceed range of data on polarwatch
dataid <- 'nsidcCDRiceSQshmday'
varnames <- c('seaice_conc_monthly_cdr','goddard_merged_seaice_conc_monthly')
datestring <- '[(2017-01-16T00:00:00Z):1:(2017-12-16T00:00:00Z)]'
coordstring <- paste0('[',colrange[1],':1:',colrange[2],'][',rowrange[1],':1:',rowrange[2],']')
for (i in 1:length(varnames)) {
if (i == 1) {
urlcall <- paste0(url,dataid,'.nc?',varnames[i],datestring,coordstring)
}
else {
urlcall <- paste0(urlcall,',',varnames[i],datestring,coordstring)
}
}
# urlcall is invalid for ERDDAP