Splash1199
Splash1199

Reputation: 379

Trying to read NetCDF file as a raster but NA values change

I'm trying to read a NetCDF file as a raster in R. The data I'm working with is SST data from the NOAA Ocean Color Laboratory. I've opened the file in the program "SeaDAS", so I know the issue is not with the original file.

My code to read the file looks like this:

library(raster)
sst.nc<-raster("may2015_sst_monthly.nc")
proj4string(sst.nc)<-CRS("+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0")
plot(sst.nc)

For some reason the raster has assigned values to the landmasses (see picture), which should be "NA". Anyone know what I need to do to solve this problem? enter image description here

Upvotes: 0

Views: 351

Answers (1)

Justina Pinch
Justina Pinch

Reputation: 397

It's possible instead of NA it's flagged it as some very large number, say 67676 (or perhaps a very large negative number). Then you could just do:

sst.nc[sst.nc==67676]=NA

And if you can't figure out the exact number for whatever reason (sometimes it has decimal points going out to 16 digits) you could just pick a large number clearly out of range of your data:

sst.nc[sst.nc>60000]=NA

Upvotes: 3

Related Questions