[R-sig-Geo] problem in reading NC file and plot it
tony333
tony333_6 at hotmail.com
Wed Jan 4 15:05:16 CET 2012
at first i use NCEP/NCAR Reanalysis Monthly Means of Sea level pressure
my script
#rm(list=ls())
library(ncdf)
library(maps)
library(fields)
### directory that contains slp data
datadir = '/home/tony/slp.mon.mean.nc'
### get lat-lon coordinates from first file, then close the file
slp.nc = open.ncdf(datadir)
lonall = get.var.ncdf(slp.nc,'lon')
latall = get.var.ncdf(slp.nc,'lat')
timall = get.var.ncdf(slp.nc,'time')
close(slp.nc)
#### specify domain
lonmin = 0
lonmax = 357.5
latmin = -90
latmax = 90
piclon = lonmin <= lonall & lonall <= lonmax
piclat = latmin <= latall & latall <= latmax
lon = lonall[piclon]
lat = latall[piclat]
nlon = length(lon)
nlat = length(lat)
# if extra months exist, only take months that account for entire year
slp.nmonths = floor(length(timall)/12)*12
slp.nyrs = slp.nmonths/12
slp.clim <- array(NA,dim=c(nlon,nlat,12))
################## read data #################################
slp.nc = open.ncdf(datadir)
dum = get.var.ncdf(slp.nc,"slp")
slp.all = dum[piclon,piclat,1:slp.nmonths]
dim(slp.all) = c(nlon,nlat,12,slp.nyrs)
close(slp.nc)
dim(slp.all) = c(nlon*nlat,12,slp.nyrs)
dim(slp.clim) = c(nlon*nlat,12)
for (month in 1:12) {
slp.clim[,month] = rowMeans(slp.all[,month,])
slp.all[,month,] = slp.all[,month,] - slp.clim[,month]
}
dim(slp.all) = c(nlon,nlat,12,slp.nyrs)
dim(slp.clim) = c(nlon,nlat,12)
##########################################################
############## plot slp anamoly shaded #############################
image.plot(lon,lat,slp.all[,,5,1])
map('world2',interior=FALSE,add=T)
############################################
that is the script i use the error is (Error in image.default(..., add =
add, col = col) :
increasing 'x' and 'y' values expected)
and if i use image.plot(lon,-lat,slp.all[,,5,1])
with negative sign in frant of lat it plot but inverse figure the lat is
arranged from +90 to -90 and i do not know if that
due to sequence in R from negative to positive or not thanks alot for help
--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/problem-in-reading-NC-file-and-plot-it-tp7150538p7150538.html
Sent from the R-sig-geo mailing list archive at Nabble.com.
More information about the R-sig-Geo
mailing list