Web Content Display

Web Content Display (CoastWatch User Forum)

The NOAA CoastWatch Forum provides information in several categories.  The information is relevant to CoastWatch products and software (https://coastwatch.noaa.gov)  and vary in technical details.  For questions and issues not addressed here,  start a thread in the appropriate category or contact the CoastWatch HelpDesk (coastwatch.info@noaa.gov).  Please note our Privacy Policy (https://www.noaa.gov/privacy.html) and that this is a public forum.  All information is voluntarily and anonymous submissions are accepted pending review prior to posting. 

Forums

Back

application of tutorial code to southern hemisphere grids

JH
Jefferson Hinke, modified 3 Years ago.

application of tutorial code to southern hemisphere grids

Youngling Posts: 7 Join Date: 6/12/17 Recent Posts

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

U
Anonymous, modified 3 Years ago.

RE: application of tutorial code to southern hemisphere grids

The inds is doing what you want:

sum(latitude > -75) [1] 91496

str(inds)  int [1:91496] 1 2 3 4 5 6 7 8 9 10 ..

sum(latitude <= -75) [1] 13416

 

JS
Jennifer Sevadjian, modified 3 Years ago.

RE: application of tutorial code to southern hemisphere grids

Youngling Posts: 15 Join Date: 6/13/17 Recent Posts

It looks like it was the 0 vs 1 start index issue.

 

Changing the coord creation line to this should fix it for you:

coordstring <- paste0('[',colrange[1]-1,':1:',colrange[2]-1,'][',rowrange[1]-1,':1:',rowrange[2]-1,']')

We will update our arctic example and will create an antarctic one too.