Skip to content

Commit

Permalink
coastline docs: in line with s4
Browse files Browse the repository at this point in the history
  • Loading branch information
dankelley committed Oct 21, 2011
1 parent 0bcfaa8 commit 89cf654
Show file tree
Hide file tree
Showing 16 changed files with 213 additions and 78 deletions.
44 changes: 23 additions & 21 deletions R/adp.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ setMethod(f="initialize",
if (!missing(u)) .Object@data$u <- u
if (!missing(a)) .Object@data$a <- a
if (!missing(q)) .Object@data$q <- q
## FIXME: more here
## names(adp$data)
## [1] "v" "a" "q" "bottomRange" "bottomVelocity" "distance" "time"
## [8] "pressure" "temperature" "salinity" "depth" "heading" "pitch" "roll"
.Object@metadata$filename <- if (missing(filename)) "" else filename
.Object@processingLog$time=c(.Object@processingLog$time, Sys.time())
.Object@processingLog$value=c(.Object@processingLog$value, "create 'ctd' object")
Expand All @@ -19,10 +15,8 @@ setMethod(f="initialize",
setMethod(f="[[",
signature="adp",
definition=function(x, i, j, drop) {
## 'j' can be for times, as in OCE
##if (!missing(j)) cat("j=", j, "*****\n")
i <- match.arg(i, c("u1", "u2", "u3","u4","latitude","longitude"))
if (i == "u1") return(x@data$v[,,1])
if (i == "filename") return(x@metadata$filename)
else if (i == "u1") return(x@data$v[,,1])
else if (i == "u2") return(x@data$v[,,2])
else if (i == "u3") return(x@data$v[,,3])
else if (i == "u4") return(x@data$v[,,4])
Expand All @@ -35,19 +29,27 @@ setMethod(f="[[",
else stop("cannot access \"", i, "\"") # cannot get here
})

##setMethod(f="[[",
## signature="adp",
## definition=function(x, i, j, drop) {
## ## 'j' can be for times, as in OCE
## ##if (!missing(j)) cat("j=", j, "*****\n")
## i <- match.arg(i, c("time", "u1", "u2", "u3"))
## if (i == "time") return(x@data$time)
## else if (i == "u1") return(x@data$v[,1])
## else if (i == "u2") return(x@data$v[,2])
## else if (i == "u3") return(x@data$v[,3])
## else stop("cannot access \"", i, "\"") # cannot get here
## })

setMethod(f="show",
signature="adp",
definition=function(object) {
filename <- object[["filename"]]
if (is.null(filename) || filename == "")
cat("ADP has column data\n", sep="")
else
cat("ADP from file '", object[["filename"]], "' has column data\n", sep="")
names <- names(object@data)
ncol <- length(names)
for (i in 1:ncol) {
cat(vectorShow(object@data[[i]], paste(" ", names[i])))
dim <- dim(object@data[[i]])
if (!is.null(dim)) {
if (length(dim) == 2)
cat(" (actually, the above is a matrix of dimension ", dim[1], " by ", dim[2], ")\n", sep="")
else if (length(dim) == 3)
cat(" (actually, the above is a matrix of dimension ", dim[1], " by ", dim[2], " by ", dim[3], ")\n", sep="")
}
}
})


head.adp <- function(x, n = 6L, ...)
Expand Down
29 changes: 24 additions & 5 deletions R/adv.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ setMethod(f="initialize",
setMethod(f="[[",
signature="adv",
definition=function(x, i, j, drop) {
## 'j' can be for times, as in OCE
##if (!missing(j)) cat("j=", j, "*****\n")
print(i)
i <- match.arg(i, c("time", "u1", "u2", "u3", "heading", "pitch", "roll"))
if (i == "time") return(x@data$time)
if (i == "filename") return(x@metadata$filename)
else if (i == "time") return(x@data$time)
else if (i == "u1") return(x@data$v[,1])
else if (i == "u2") return(x@data$v[,2])
else if (i == "u3") return(x@data$v[,3])
Expand All @@ -39,6 +36,28 @@ setMethod(f="[[",
} else stop("cannot access \"", i, "\"") # cannot get here
})

setMethod(f="show",
signature="adv",
definition=function(object) {
filename <- object[["filename"]]
if (is.null(filename) || filename == "")
cat("ADV has column data\n", sep="")
else
cat("ADV from file '", object[["filename"]], "' has column data\n", sep="")
names <- names(object@data)
ncol <- length(names)
for (i in 1:ncol) {
cat(vectorShow(object@data[[i]], paste(" ", names[i])))
dim <- dim(object@data[[i]])
if (!is.null(dim)) {
if (length(dim) == 2)
cat(" (actually, the above is a matrix of dimension ", dim[1], " by ", dim[2], ")\n", sep="")
else if (length(dim) == 3)
cat(" (actually, the above is a matrix of dimension ", dim[1], " by ", dim[2], " by ", dim[3], ")\n", sep="")
}
}
})

read.adv <- function(file, from=1, to, by=1, tz=getOption("oceTz"),
type=c("nortek", "sontek", "sontek.adr", "sontek.text"),
header=TRUE,
Expand Down
42 changes: 42 additions & 0 deletions R/cm.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,48 @@ setMethod(f="initialize",
return(.Object)
})

setMethod(f="[[",
signature="cm",
definition=function(x, i, j, drop) {
if (i %in% names(x@metadata)) return(x@metadata[[i]])
else if (i %in% names(x@data)) return(x@data[[i]])
else stop("cannot access \"", i, "\"")
})

setMethod(f="[[<-",
signature="cm",
definition=function(x, i, j, value) { # FIXME: use j for e.g. times
if (i %in% names(x@metadata)) x@metadata[[i]] <- value
else if (i %in% names(x@data)) x@data[[i]] <- value
else stop("there is no item named \"", i, "\" in this cm object")
##validObject(x)
invisible(x)
})

setMethod(f="show",
signature="cm",
definition=function(object) {
filename <- object[["filename"]]
if (is.null(filename) || filename == "")
cat("CM has column data\n", sep="")
else
cat("CM from file '", object[["filename"]], "' has column data\n", sep="")
names <- names(object@data)
ncol <- length(names)
for (i in 1:ncol) {
cat(vectorShow(object@data[[i]], paste(" ", names[i])))
dim <- dim(object@data[[i]])
if (!is.null(dim)) {
if (length(dim) == 2)
cat(" (actually, the above is a matrix of dimension ", dim[1], " by ", dim[2], ")\n", sep="")
else if (length(dim) == 3)
cat(" (actually, the above is a matrix of dimension ", dim[1], " by ", dim[2], " by ", dim[3], ")\n", sep="")
}
}
})




## cm.R current-meter support (interocean S4)
read.cm <- function(file, from=1, to, by=1, tz=getOption("oceTz"),
Expand Down
49 changes: 44 additions & 5 deletions R/coastline.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,54 @@ setMethod(f="initialize",
setMethod(f="[[",
signature="coastline",
definition=function(x, i, j, drop) {
## 'j' can be for times, as in OCE
##if (!missing(j)) cat("j=", j, "*****\n")
i <- match.arg(i, c("latitude", "longitude"))
if (i == "latitude") x@data$latitude
else if (i == "longitude") x@data$longitude
else if (i == "filename") x@metadata$filename
else NULL
})
#
#

setMethod(f="[[<-",
signature="coastline",
definition=function(x, i, j, value) { # FIXME: use j for e.g. times
if (i %in% names(x@metadata)) x@metadata[[i]] <- value
else if (i %in% names(x@data)) x@data[[i]] <- value
else stop("there is no item named \"", i, "\" in this coastline object")
validObject(x)
invisible(x)
})

setValidity("coastline",
function(object) {
if (inherits(object, "coastline")) {
ndata <- length(object@data)
lengths <- vector("numeric", ndata)
for (i in 1:ndata)
lengths[i] <- length(object@data[[i]])
if (var(lengths) != 0) {
cat("lengths of data elements are unequal\n")
return(FALSE)
} else
return(TRUE)
}
})



setMethod(f="show",
signature="coastline",
definition=function(object) {
filename <- object[["filename"]]
if (is.null(filename) || filename == "")
cat("Coastline has column data\n", sep="")
else
cat("Coastline from file '", object[["filename"]], "' has column data\n", sep="")
names <- names(object@data)
ncol <- length(names)
for (i in 1:ncol) {
cat(vectorShow(object@data[[i]], paste(" ", names[i])))
}
})

as.coastline <- function(latitude, longitude)
{
n <- length(latitude)
Expand Down
10 changes: 5 additions & 5 deletions R/misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -307,15 +307,15 @@ vectorShow <- function(v, msg, digits=5)
paste(msg, "(empty vector)\n")
} else {
if (is.numeric(v)) {
if (n > 6) {
vv <- format(v[c(1, 2, 3, n-2, n-1, n)], digits=digits)
paste(msg, ": ", vv[1], ", ", vv[2], ", ", vv[3], ", ..., ", vv[4], ", ", vv[5], ", ", vv[6], " (length ", n, ")\n", sep="")
if (n > 4) {
vv <- format(v[c(1, 2, n-1, n)], digits=digits)
paste(msg, ": ", vv[1], ", ", vv[2], ", ..., ", vv[3], ", ", vv[4], " (length ", n, ")\n", sep="")
} else {
paste(msg, ": ", paste(format(v, digits=digits), collapse=", "), "\n", sep="")
}
} else {
if (n > 6) {
paste(msg, ": ", v[1], ", ", v[2], ", ", v[3], ", ..., ", v[n-2], ", ", v[n-1], ", ", v[n], " (length ", n, ")\n", sep="")
if (n > 4) {
paste(msg, ": ", v[1], ", ", v[2], ", ..., ", v[n-1], ", ", v[n], " (length ", n, ")\n", sep="")
} else {
paste(msg, ": ", paste(v, collapse=", "), "\n", sep="")
}
Expand Down
9 changes: 4 additions & 5 deletions man/as.coastline.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ the data have been manipulated.

\value{An object of \code{\link[base]{class}} \code{"coastline"} (for details, see \code{\link{read.coastline}}).}

\seealso{
You may also use \code{\link{read.coastline}} to read a coastline file.
Plotting is typically done with \code{\link{plot.coastline}}, although
it is sufficient to just use \code{plot} for coastline objects.
}
\seealso{The documentation for \code{\link{coastline-class}} explains the
structure of coastline objects, and also outlines the other functions
dealing with them.}

\examples{
\dontrun{
d<-read.table("bbasin.dat",header=FALSE) # dataset not provided with oce
Expand Down
2 changes: 2 additions & 0 deletions man/cm-class.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

\alias{cm-class}
\alias{[[,cm-method}
\alias{[[<-,cm-method}
\alias{show,cm-method}

\title{Class to store current meter data}

Expand Down
16 changes: 14 additions & 2 deletions man/coastline-class.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,27 @@

\alias{coastline-class}
\alias{[[,coastline-method}
\alias{[[<-,coastline-method}
\alias{show,coastline-method}

\title{Class to store coastline data}

\description{Class to store coastline data, with standard slots \code{metadata}
(containing \code{fillable} and \code{filename}), \code{data} (containing
\code{latitude} and \code{longitude}) and \code{processingLog}.}

\section{Methods}{Data may be accessed as e.g. \code{coastline[["latitude"]]}
or \code{coastline[["longitude"]]}.}
\section{Methods}{
\subsection{Extracting values}{Data may be accessed as e.g.
\code{ctd[["latitude"]]} or
\code{ctd[["longitude"]]}.}

\subsection{Assigning values}{Latitude may be changed with e.g.
\code{ctd[["latitude"]] <- value}, and of course the same can be done
for \code{longitude}.}

\subsection{Overview of contents}{The \code{show} method (e.g.
\code{show(coastline)}) displays information about the object.}
}

\author{Dan Kelley}
\keyword{classes}
Expand Down
16 changes: 11 additions & 5 deletions man/coastlineHalifax.Rd
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
\name{coastlineHalifax}

\docType{data}

\alias{coastlineHalifax}

\title{Coastline data set, showing Halifax Harbour}

\description{A sample coastline dataset, showing Halifax Harbour.
The little island at about 44.64N is visible outside the author's window.}
\usage{data(coastlineHalifax)}
\references{\url{http://www.ngdc.noaa.gov/mgg_coastline/}}
\seealso{Coastlines may be read with
\code{\link{read.coastline}}, or created with
\code{\link{as.coastline}}. Another
sample coastline file is \code{\link{coastlineMaritimes}}; see these for details of the data format. Other coastline datasets provided with
oce are \code{\link{coastlineMaritimes}} and \code{\link{coastlineWorld}}.}
\seealso{The documentation for \code{\link{coastline-class}} explains the
structure of coastline objects, and also outlines the other functions
dealing with them.}
\author{Dan Kelley}
\keyword{datasets}
26 changes: 17 additions & 9 deletions man/coastlineMaritimes.Rd
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
\name{coastlineMaritimes}

\docType{data}

\alias{coastlineMaritimes}

\title{Coastline data set, showing Maritime provinces of Canada}
\description{A sample coastline dataset, showing Nova Scotia,
Prince Edward Island, and part of New Brunswick.
This is the oce author's stomping ground, and so he feels compelled
to apologize for the error at the Strait of Canso.}

\description{A sample coastline dataset, showing Nova Scotia, Prince Edward
Island, and part of New Brunswick. This is the oce author's stomping
ground, and so he feels compelled to apologize for the error at the Strait
of Canso.}
\usage{data(coastlineMaritimes)}
\source{The data were extracted from the the 1:2,000,000 ``World Data Bank II''
dataset at the NOAA site.}
dataset at the NOAA site.}
\references{\url{http://www.ngdc.noaa.gov/mgg_coastline/index.jsp?llat=43.0&ulat=47.2&llon=-66.8&rlon=-59.5}}
\seealso{Coastlines may be read with
\code{\link{read.coastline}}, or created with
\code{\link{as.coastline}}; see these for details of the data format. Other coastline datasets provided with
oce are \code{\link{coastlineHalifax}} and \code{\link{coastlineWorld}}.}
\seealso{The documentation for \code{\link{coastline-class}} explains the
structure of coastline objects, and also outlines the other functions
dealing with them.}
\author{Dan Kelley}
\keyword{datasets}
17 changes: 13 additions & 4 deletions man/coastlineSLE.Rd
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
\name{coastlineSLE}

\docType{data}

\alias{coastlineSLE}

\title{Coastline of St Lawrence Estuary}

\description{A sample coastline dataset, showing the St Lawrence Estuary.}

\usage{data(coastlineSLE)}

\source{The data were extracted from the the 1:250,000 ``World Vector Shoreline''
dataset at the NOAA site.}

\references{\url{http://www.ngdc.noaa.gov/mgg_coastline}}
\seealso{Coastlines may be read with
\code{\link{read.coastline}}, or created with
\code{\link{as.coastline}}; see these for details of the data format. Other coastline datasets provided with
oce are \code{\link{coastlineHalifax}} and \code{\link{coastlineWorld}}.}

\seealso{The documentation for \code{\link{coastline-class}} explains the
structure of coastline objects, and also outlines the other functions
dealing with them.}

\author{Dan Kelley}

\keyword{datasets}
7 changes: 3 additions & 4 deletions man/coastlineWorld.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@
Creative Commons license
(\url{http://creativecommons.org/licenses/by-sa/3.0/}).}

\seealso{Coastlines may be read with
\code{\link{read.coastline}}, or created with
\code{\link{as.coastline}}; see these for details of the data format. Other coastline datasets provided with
oce are \code{\link{coastlineHalifax}} and \code{\link{coastlineMaritimes}}.}
\seealso{The documentation for \code{\link{coastline-class}} explains the
structure of coastline objects, and also outlines the other functions
dealing with them.}

\author{Dan Kelley}

Expand Down
Loading

0 comments on commit 89cf654

Please sign in to comment.