Skip to content

Commit 1f6705d

Browse files
author
brasmus
committed
finor fix in map.station
1 parent 5220e2e commit 1f6705d

File tree

1 file changed

+52
-49
lines changed

1 file changed

+52
-49
lines changed

R/map.R

+52-49
Original file line numberDiff line numberDiff line change
@@ -149,55 +149,57 @@ map.default <- function(x,...,FUN='mean',it=NULL,is=NULL,new=FALSE,
149149
colbar= colbar,gridlines=gridlines,verbose=verbose,
150150
plot=plot,useRaster=useRaster,...)
151151
invisible(z)
152-
}
153-
par0 <- par(no.readonly = TRUE) # save default, for resetting...
154-
if (is.logical(colbar)) colbar <- NULL
155-
## If only a few items are provided in colbar - then set the rest to the default
156-
if (!is.null(colbar)) {
157-
colbar <- colbar.ini(x,FUN=FUN,colbar=colbar,verbose=FALSE)
158-
}
159-
x <- subset(x,it=it,is=is)
160-
X <- attr(x,'pattern')
161-
162-
## if zlim is specified, then mask data outside this range
163-
if (!is.null(zlim)) {
164-
d <- dim(X)
165-
mask <- (X < min(zlim)) | (X > max(zlim))
166-
X[mask] <- NA
167-
dim(X) <- d
168-
if (verbose) {print(zlim); print(dim(X)); print(sum(mask))}
169-
}
170-
attr(X,'longitude') <- lon(x)
171-
attr(X,'latitude') <- lat(x)
172-
attr(X,'variable') <- attr(x,'variable')
173-
attr(X,'unit') <- attr(x,'unit')[1]
174-
if (attr(X,'unit') =='%') attr(X,'unit') <- "'%'"
175-
attr(X,'source') <- attr(x,'source')
176-
attr(X,'variable') <- varid(x)
177-
if (inherits(X,'zoo')) {
178-
attr(X,'time') <- range(index(x))
179-
} else if (!is.null(attr(x,'time'))) {
180-
attr(X,'time') <- attr(x,'time')
181-
}
182-
if (plot) {
183-
if (projection=="lonlat") {
184-
z <- lonlatprojection(x=X,xlim=xlim,ylim=ylim,colbar=colbar,verbose=verbose,
185-
lab=lab,type=type,new=new,gridlines=gridlines,useRaster=useRaster,...)
186-
} else if (projection=="sphere") {
187-
z <- map2sphere(x=X,lonR=lonR,latR=latR,axiR=axiR,xlim=xlim,ylim=ylim,
188-
lab=lab,type=type,gridlines=gridlines,colbar=colbar,new=new,...)
189-
} else if (projection=="np") {
190-
z <- map2sphere(X,lonR=lonR,latR=90,axiR=axiR,xlim=xlim,ylim=ylim,
191-
lab=lab,type=type,gridlines=gridlines,colbar=colbar,new=new,...)
192-
} else if (projection=="sp") {
193-
z <- map2sphere(X,lonR=lonR,latR=-90,axiR=axiR,new=new,xlim=xlim,ylim=ylim,
194-
lab=lab,type=type,gridlines=gridlines,colbar=colbar,...)
195-
} else if (length(grep('moll|aea|utm|stere|robin',projection))>0) {
196-
z <- map.sf(X,projection=projection,xlim=xlim,ylim=ylim,type=type,
197-
gridlines=gridlines,colbar=colbar,...)
152+
} else {
153+
par0 <- par(no.readonly = TRUE) # save default, for resetting...
154+
if (is.logical(colbar)) colbar <- NULL
155+
## If only a few items are provided in colbar - then set the rest to the default
156+
if (!is.null(colbar)) {
157+
colbar <- colbar.ini(x,FUN=FUN,colbar=colbar,verbose=FALSE)
198158
}
199-
} else z <- X
200-
invisible(z)
159+
x <- subset(x,it=it,is=is)
160+
X <- attr(x,'pattern')
161+
162+
## if zlim is specified, then mask data outside this range
163+
if (!is.null(zlim)) {
164+
d <- dim(X)
165+
mask <- (X < min(zlim)) | (X > max(zlim))
166+
X[mask] <- NA
167+
dim(X) <- d
168+
if (verbose) {print(zlim); print(dim(X)); print(sum(mask))}
169+
}
170+
if (verbose) print('map.default: Copy metadata')
171+
attr(X,'longitude') <- lon(x)
172+
attr(X,'latitude') <- lat(x)
173+
attr(X,'variable') <- attr(x,'variable')
174+
attr(X,'unit') <- attr(x,'unit')[1]
175+
if (attr(X,'unit') =='%') attr(X,'unit') <- "'%'"
176+
attr(X,'source') <- attr(x,'source')
177+
attr(X,'variable') <- varid(x)
178+
if (inherits(X,'zoo')) {
179+
attr(X,'time') <- range(index(x))
180+
} else if (!is.null(attr(x,'time'))) {
181+
attr(X,'time') <- attr(x,'time')
182+
}
183+
if (plot) {
184+
if (projection=="lonlat") {
185+
z <- lonlatprojection(x=X,xlim=xlim,ylim=ylim,colbar=colbar,verbose=verbose,
186+
lab=lab,type=type,new=new,gridlines=gridlines,useRaster=useRaster,...)
187+
} else if (projection=="sphere") {
188+
z <- map2sphere(x=X,lonR=lonR,latR=latR,axiR=axiR,xlim=xlim,ylim=ylim,
189+
lab=lab,type=type,gridlines=gridlines,colbar=colbar,new=new,...)
190+
} else if (projection=="np") {
191+
z <- map2sphere(X,lonR=lonR,latR=90,axiR=axiR,xlim=xlim,ylim=ylim,
192+
lab=lab,type=type,gridlines=gridlines,colbar=colbar,new=new,...)
193+
} else if (projection=="sp") {
194+
z <- map2sphere(X,lonR=lonR,latR=-90,axiR=axiR,new=new,xlim=xlim,ylim=ylim,
195+
lab=lab,type=type,gridlines=gridlines,colbar=colbar,...)
196+
} else if (length(grep('moll|aea|utm|stere|robin',projection))>0) {
197+
z <- map.sf(X,projection=projection,xlim=xlim,ylim=ylim,type=type,
198+
gridlines=gridlines,colbar=colbar,...)
199+
}
200+
} else z <- X
201+
invisible(z)
202+
}
201203
}
202204

203205
#' @exportS3Method
@@ -781,7 +783,8 @@ map.pca <- function(x,...,it=NULL,is=NULL,ip=1,new=FALSE,projection="lonlat",
781783
X[mask] <- NA
782784
dim(X) <- d
783785
if (verbose) {print(zlim); print(dim(X)); print(sum(mask))}
784-
}
786+
}
787+
if (verbose) print('map.pca: copy metadata')
785788
attr(X,'longitude') <- lon(x)
786789
attr(X,'latitude') <- lat(x)
787790
attr(X,'mean') <- NULL

0 commit comments

Comments
 (0)