R/cca.R

Defines functions cca ccaM

Documented in cca

cca <- function(data, s=1, mode=3, count.cells=FALSE, count.max=ncol(data)*3, res.x=NULL, res.y=NULL, cell.class=1, unit="", compare=""){
	if(is(data, "RasterLayer") | is(data, "data.frame")){
    if(unit=="m"){
      ccaRm(data=data, d=s,res.x=res.x, res.y=res.y, cell.class=cell.class, compare)
    } else {
      ccaRd(data=data, d=s, cell.class=cell.class, compare)
    }
	} else {
		ccaM(data=data, s=s,mode=mode, count.cells=count.cells, count.max=count.max)
	}

}
ccaM <- function(data, s=1, mode=3, count.cells=FALSE, count.max=ncol(data)*3){
	#do checks
	stopifnot(is.numeric(data))
	stopifnot(is(data, "matrix"))
	stopifnot(is.numeric(s))
	stopifnot(mode==1 | mode==2 | mode==3)
	the.data <- as.integer(t(data))
	clu <- as.integer(rep(0, ncol(data)*nrow(data)))
        count.max <- as.integer(count.max)
	count <- as.integer(rep(0, count.max))
	if(count.cells==TRUE){
	  out <- .C("callburn_count",  s=as.integer(s), xmax=nrow(data), ymax=ncol(data), mode=as.integer(mode)[1], data=the.data, clu=clu, count=count, count.max=count.max,CLASSES=c("integer", "integer", "integer", "integer", "integer","integer"))
	  return(list(clusters=matrix(out$clu, ncol=ncol(data), byrow=TRUE), cluster.count=out$count[1:max(out$clu)]))
	  }
	if(count.cells==FALSE){
	  out <- .C("callburn",  s=as.integer(s), xmax=nrow(data), ymax=ncol(data), mode=as.integer(mode)[1], data=the.data, clu=clu, count=count, count.max=count.max,CLASSES=c("integer", "integer", "integer", "integer", "integer","integer"))
	  return(clusters=matrix(out$clu, ncol=ncol(data), byrow=TRUE))
	  }
}

Try the osc package in your browser

Any scripts or data that you put into this service are public.

osc documentation built on Dec. 19, 2019, 5:06 p.m.