Commit 775e8e14 authored by Burkhardt Rockel's avatar Burkhardt Rockel

*Changed functions:*

@plotmap.R@ -- Introduced new paramenter "pollonshift" to account for pollat=90, pollon=180 (TRUE, default)
               and pollat=90, pollon=0 (FALSE) representing rotated == geographical grid

@geo2rot.R@ —- Introduced new paramenter "pollonshift" to account for pollat=90, pollon=180 (TRUE, default)
               and pollat=90, pollon=0 (FALSE) representing rotated == geographical grid.
               Corrected error in case pollat=90, pollon /= 0., pollonshift=FALSE
parent beecd970
ncdf4Utils version 0.5-3
-------------------------
*Changed functions:*
@plotmap.R@ -- Introduced new paramenter "pollonshift" to account for pollat=90, pollon=180 (TRUE, default)
and pollat=90, pollon=0 (FALSE) representing rotated == geographical grid
@geo2rot.R@ —- Introduced new paramenter "pollonshift" to account for pollat=90, pollon=180 (TRUE, default)
and pollat=90, pollon=0 (FALSE) representing rotated == geographical grid.
Corrected error in case pollat=90, pollon /= 0., pollonshift=FALSE
ncdf4Utils version 0.5-2
-------------------------
......
Package: ncdf4Utils
Type: Package
Title: provides plot functions to use with NetCDF data
Version: 0.5-2
Date: 2014-04-10
Version: 0.5-3
Date: 2014-04-15
Author: Jonas Bhend <jonas.bhend@env.ethz.ch>, with contributions
from Burkhardt Rockel <burkhardt.rockel@hzg.de>
Maintainer: Jonas Bhend <jonas.bhend@env.ethz.ch>
......@@ -15,4 +15,4 @@ Description: This package contains numerous functions to plot
License: GPL
LazyLoad: yes
LazyData: true
Packaged: Thu April 10 17:49:000 2014; rockel
Packaged: Thu April 15 18:29:000 2014; rockel
File added
......@@ -36,7 +36,7 @@
##########################################################
.phirot2phi <- function(phirot, rlarot, polphi, pollam, polgam=0){
.phirot2phi <- function(phirot, rlarot, polphi, pollam, polgam=0, pollonshift=TRUE){
# Description:
# This function converts phi from one rotated system to phi in another
# system. If the optional argument polgam is present, the other system
......@@ -49,8 +49,7 @@
# Transformation formulas for converting between these two systems.
#
if (polphi == 90) {
if (polphi == 90 & !pollonshift) {
phirot2phi = phirot
} else {
......@@ -84,7 +83,7 @@
##########################################################
.phi2phirot <- function(phi, rla, polphi, pollam){
.phi2phirot <- function(phi, rla, polphi, pollam, pollonshift=TRUE){
#------------------------------------------------------------------------------
# Description:
......@@ -96,7 +95,7 @@
#
#------------------------------------------------------------------------------
if (polphi == 90) {
if (polphi == 90 & !pollonshift) {
phi2phirot = phi
......@@ -122,7 +121,7 @@
##########################################################
.rlarot2rla <- function(phirot, rlarot, polphi, pollam, polgam=0){
.rlarot2rla <- function(phirot, rlarot, polphi, pollam, polgam=0, pollonshift=TRUE){
# Description:
# This function converts lambda from one rotated system to lambda in another
......@@ -136,9 +135,9 @@
# Transformation formulas for converting between these two systems.
#
if (polphi == 90) {
if (polphi == 90 & !pollonshift) {
rlarot2rla = rlarot - pollam - polgam
rlarot2rla = rlarot + pollam - polgam
} else {
......@@ -186,7 +185,7 @@
##########################################################
.rla2rlarot <- function(phi, rla, polphi, pollam, polgam=0) {
.rla2rlarot <- function(phi, rla, polphi, pollam, polgam=0, pollonshift=TRUE) {
#------------------------------------------------------------------------------
#
......@@ -198,11 +197,9 @@
# Transformation formulas for converting between these two systems.
#
#------------------------------------------------------------------------------
if (polphi == 90 & !pollonshift) {
if (polphi == 90) {
rla2rlarot= rla + pollam + polgam
rla2rlarot= rla - pollam + polgam
} else {
zpir18 <- pi/180
......@@ -228,12 +225,12 @@
if (polgam != 0) {
rla2rlarot <- polgam + rla2rlarot
}
ind <- rla2rlarot > 180 & !is.na(rla2rlarot)
rla2rlarot[ind] <- rla2rlarot[ind] - 360
}
}
ind <- rla2rlarot > 180 & !is.na(rla2rlarot)
rla2rlarot[ind] <- rla2rlarot[ind] - 360
rla2rlarot
}
......@@ -241,10 +238,10 @@
##########################################################
geo2rot <- function(pollon, pollat, lon, lat, polgam=0){
geo2rot <- function(pollon, pollat, lon, lat, polgam=0, pollonshift=TRUE){
rlon <- .rla2rlarot(lat, lon, pollat, pollon, polgam)
rlat <- .phi2phirot(lat, lon, pollat, pollon)
rlon <- .rla2rlarot(lat, lon, pollat, pollon, polgam, pollonshift)
rlat <- .phi2phirot(lat, lon, pollat, pollon, pollonshift)
out <- list(x=rlon, y=rlat)
out
......@@ -252,24 +249,12 @@ geo2rot <- function(pollon, pollat, lon, lat, polgam=0){
##########################################################
rot2geo <- function(pollon, pollat, rlon, rlat, polgam=0){
rot2geo <- function(pollon, pollat, rlon, rlat, polgam=0, pollonshift=TRUE){
lon <- .rlarot2rla(rlat, rlon, pollat, pollon, polgam)
lat <- .phirot2phi(rlat, rlon, pollat, pollon, polgam)
lon <- .rlarot2rla(rlat, rlon, pollat, pollon, polgam, pollonshift)
lat <- .phirot2phi(rlat, rlon, pollat, pollon, polgam, pollonshift)
out <- list(x=lon, y=lat)
out
}
......@@ -9,7 +9,7 @@ function(file, file.small=NULL, sponge=8, sponge.small=15,
cex.axis=1, cex.lab=1, cex.main=1, cex.txt=1,
main="", xlab="", ylab="", add=FALSE,
colourplot=TRUE, hires=FALSE, interior=FALSE, alt.poli=TRUE,
nlongrid=10, nlatgrid=5, lon.ind, lat.ind){
nlongrid=10, nlatgrid=5, lon.ind, lat.ind, pollonshift=TRUE){
nc <- nc_open(file)
if ( !is.null(nc$var$rotated_pole$id) ) {
......@@ -26,7 +26,7 @@ function(file, file.small=NULL, sponge=8, sponge.small=15,
cex.axis=cex.axis, cex.lab=cex.lab, cex.main=cex.main, cex.txt=cex.txt,
main=main, xlab=xlab, ylab=ylab, add=add,
colourplot=colourplot, hires=hires, interior=interior, alt.poli=alt.poli,
nlongrid=nlongrid, nlatgrid=nlatgrid, lon.ind, lat.ind)
nlongrid=nlongrid, nlatgrid=nlatgrid, lon.ind, lat.ind, pollonshift=pollonshift)
} else if ( !is.null(nc$var$multiple_rotated_pole$id) ) {
......@@ -494,7 +494,7 @@ function(file, file.small=NULL, sponge=8, sponge.small=15,
cex.axis=1, cex.lab=1, cex.main=1, cex.txt=1,
main="", xlab="", ylab="", add=FALSE,
colourplot=TRUE, hires=FALSE, interior=FALSE, alt.poli=TRUE,
nlongrid=10, nlatgrid=5, lon.ind, lat.ind){
nlongrid=10, nlatgrid=5, lon.ind, lat.ind, pollonshift=TRUE){
# load hi-resolution map-data only when hires is set
# in order to avoid complications on a system without
......@@ -558,7 +558,7 @@ function(file, file.small=NULL, sponge=8, sponge.small=15,
lon <- ncvar_get(nc, "lon")
lat <- ncvar_get(nc, "lat")
} else {
tmp <- rot2geo(pollon, pollat, rep(rlon, nlat), rep(rlat, each=nlon), polgam)
tmp <- rot2geo(pollon, pollat, rep(rlon, nlat), rep(rlat, each=nlon), polgam, pollonshift)
lon <- array(tmp$x, c(nlon,nlat))
lat <- array(tmp$y, c(nlon,nlat))
}
......@@ -741,11 +741,11 @@ function(file, file.small=NULL, sponge=8, sponge.small=15,
world$x[ind.i] <- NA
world$y[ind.i] <- NA
}
world.rot <- geo2rot(pollon,pollat,world$x, world$y, polgam)
world.rot <- geo2rot(pollon,pollat,world$x, world$y, polgam, pollonshift)
if (rivers){
riv.dat <- map('rivers', plot=F)
rivers.rot <- geo2rot(pollon,pollat, riv.dat$x, riv.dat$y, polgam)
rivers.rot <- geo2rot(pollon,pollat, riv.dat$x, riv.dat$y, polgam, pollonshift)
}
data.tmp <- data
......@@ -830,7 +830,7 @@ function(file, file.small=NULL, sponge=8, sponge.small=15,
# some cities
data(world.cities)
# compute rotated coordinates
coords <- geo2rot(pollon,pollat,world.cities$long,world.cities$lat,polgam)
coords <- geo2rot(pollon,pollat,world.cities$long,world.cities$lat,polgam, pollonshift)
world.cities$rlon <- coords$x
world.cities$rlat <- coords$y
......@@ -886,7 +886,7 @@ function(file, file.small=NULL, sponge=8, sponge.small=15,
lon.txt <- paste(abs(lon.ind2), '*degree', c('~ W', '', '~ E')[sign(lon.ind2) + 2])
lab.w <- strwidth(parse(text=lon.txt), cex=cex.axis)
lon.i <- apply(as.matrix(lon.ind), 1, function(x) if (x > min(lon[,1]) & x < max(lon[,1])) which.min((lon[,1]-x)**2) else NA)
lon.at <- geo2rot(pollon, pollat, lon[lon.i,1], lat[lon.i,1], polgam)$x
lon.at <- geo2rot(pollon, pollat, lon[lon.i,1], lat[lon.i,1], polgam, pollonshift)$x
for (i in (min(which(!is.na(lon.at)))+1):max(which(!is.na(lon.at)))){
lo.i <- max(which(!is.na(lon.at[1:(i-1)])))
dist <- lon.at[i] - lon.at[lo.i]
......@@ -894,7 +894,7 @@ function(file, file.small=NULL, sponge=8, sponge.small=15,
}
if (grid.txt[1]) axis(1, at=lon.at, labels=parse(text=lon.txt), tick=F, line=-0.5, cex.axis=cex.axis)
lon.i <- apply(as.matrix(lon.ind), 1, function(x) if (x > min(lon[,ncol(lon)]) & x < max(lon[,ncol(lon)])) which.min((lon[,ncol(lon)]-x)**2) else NA)
lon.at <- geo2rot(pollon, pollat, lon[lon.i,ncol(lon)], lat[lon.i,ncol(lon)], polgam)$x
lon.at <- geo2rot(pollon, pollat, lon[lon.i,ncol(lon)], lat[lon.i,ncol(lon)], polgam, pollonshift)$x
for (i in (min(which(!is.na(lon.at)))+1):max(which(!is.na(lon.at)))){
lo.i <- max(which(!is.na(lon.at[1:(i-1)])))
dist <- lon.at[i] - lon.at[lo.i]
......@@ -905,7 +905,7 @@ function(file, file.small=NULL, sponge=8, sponge.small=15,
lat.txt <- paste(abs(lat.ind), '*degree', c('~ S', '', '~ N')[sign(lat.ind) + 2])
lab.w <- strheight(parse(text=lat.txt), cex=cex.axis)
lat.i <- apply(as.matrix(lat.ind), 1, function(x) if (x > min(lat[,1]) & x < max(lat[1,])) which.min((lat[1,]-x)**2) else NA)
lat.at <- geo2rot(pollon, pollat, lon[1,lat.i], lat[1,lat.i], polgam)$y
lat.at <- geo2rot(pollon, pollat, lon[1,lat.i], lat[1,lat.i], polgam, pollonshift)$y
for (i in (min(which(!is.na(lat.at)))+1):max(which(!is.na(lat.at)))){
lo.i <- max(which(!is.na(lat.at[1:(i-1)])))
dist <- lat.at[i] - lat.at[lo.i]
......@@ -913,7 +913,7 @@ function(file, file.small=NULL, sponge=8, sponge.small=15,
}
if (grid.txt[2]) axis(2, at=lat.at, labels=parse(text=lat.txt), tick=F, line=-0.5, cex.axis=cex.axis, las=1)
lat.i <- apply(as.matrix(lat.ind), 1, function(x) if (x > min(lat[nrow(lat),]) & x < max(lat[nrow(lat),])) which.min((lat[nrow(lat),]-x)**2) else NA)
lat.at <- geo2rot(pollon, pollat, lon[nrow(lat),lat.i], lat[nrow(lat),lat.i], polgam)$y
lat.at <- geo2rot(pollon, pollat, lon[nrow(lat),lat.i], lat[nrow(lat),lat.i], polgam, pollonshift)$y
for (i in (min(which(!is.na(lat.at)))+1):max(which(!is.na(lat.at)))){
lo.i <- max(which(!is.na(lat.at[1:(i-1)])))
dist <- lat.at[i] - lat.at[lo.i]
......
......@@ -18,7 +18,7 @@ plotmap(file, file.small = NULL, sponge = 8,
cex.txt = 1, main = "", xlab = "", ylab = "",
colourplot = TRUE, hires = FALSE, interior = FALSE,
alt.poli=TRUE, add=TRUE, nlongrid=10, nlatgrid=5,
lon.ind, lat.ind)
lon.ind, lat.ind, pollonshift = TRUE)
}
%- maybe also 'usage' for other objects documented here.
\arguments{
......@@ -57,6 +57,7 @@ plotmap(file, file.small = NULL, sponge = 8,
\item{add}{Should plot be added to existing plot}
\item{nlongrid, nlatgrid}{Approximate number of longitude and latitude grid lines}
\item{lon.ind, lat.ind}{Sequence of longitudes (latitudes) at which to draw grid lines. Has to be increasing. Longitudes greater than 180 are converted.}
\item{pollonshift}{Effects only special cases where pollat=90. in rotated coordinates. For example for rotated==geographic coordinate system pollon=0., pollat=90.. However, due to a bug in nearly all existing conversion routines, this is mostly defined as pollon=180., pollat=90. or pollon=0., pollat=90., polgam=180.. In the latter case set pollonshift=T}
}
\value{
A List of class "plotmap" containing the following objects:
......
......@@ -7,8 +7,6 @@
}
\usage{
set_position(x, y, size = 0.1, bg = NULL)
}
\usage{
reset_position()
}
\arguments{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment