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

R, netcdf4 package: error trying to pull variable of interest from netcdf file

NP
Noah Pomeroy, modified 4 Years ago.

R, netcdf4 package: error trying to pull variable of interest from netcdf file

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

following the code in the R tutorial (which I've used successfully for other netcdf sources), I'm trying to pull SST from this MUR data set with the following code:

temp <- GET('https://coastwatch.pfeg.noaa.gov/erddap/griddap/jplMURSST41.nc?analysed_sst%5B(2015-02-01T09:00:00Z):1:(2016-10-01T09:00:00Z)%5D%5B(20.5):1:(21.5)%5D%5B(203):1:(204)%5D,analysis_error%5B(2015-02-01T09:00:00Z):1:(2016-10-01T09:00:00Z)%5D%5B(20.5):1:(21.5)%5D%5B(203):1:(204)%5D', write_disk("sst.nc", overwrite=TRUE))

#open downloaded file
nc <- nc_open('sst.nc')

#see variables included
names(nc$var)

#create object for variable of interest
v1 <- nc$var[[1]]

#pull data set of variable of interest
sst_mur <- ncvar_get(nc,v1)

----It seems to work until the last line, when I get the following error:

Error in R_nc4_inq_varndims: NetCDF: Not a valid ID Error in ncvar_ndims(ncid, varid) : error returned from C call

I

It seems like I'm not identifying the varid of the variable properly. I tried calling it by name unsuccessfully. I tried pulling the file into Panoply to clearly read the metadata of the file and I get an error in Panoply trying to open the file: "The file does not seem to be valid CDM."

Any idea what's up in either R or Panoply with this file?

CW
Cara Wilson, modified 4 Years ago.

RE: R, netcdf4 package: error trying to pull variable of interest from netcdf file

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

You are pulling for the WCN ERDDAP which does not have all datasets on 0-360 for longitude, and this dataset has longitude in -180/180 format.  If you put your URL in a browser you will get the following error which tells you that: 

Error { code=404; message="Not Found: Your query produced no matching results. Query error: For variable=analysed_sst axis#2=longitude Constraint=\"[(203):1:(204)]\": Start=\"203\" is greater than the axis maximum=180.0 (and even 180.005)."; }

 

So you need to change your longitude values to -157 and -156 

Cara 

NP
Noah Pomeroy, modified 4 Years ago.

RE: R, netcdf4 package: error trying to pull variable of interest from netcdf file

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

Awesome, that did it, thanks Cara! Now MUR joined my showdown of remotely sensed SST against in situ 5m temp at a Maui reef during the 2015 bleaching event in HI