Permalink
Browse files

imported source for r-cran-catools

  • Loading branch information...
1 parent 6c1e1bf commit 4fe8f019f0ceed3f64eb392e882b14420d777aab @sakoht sakoht committed Apr 11, 2012
Showing with 5,585 additions and 0 deletions.
  1. +90 −0 CHANGES
  2. +17 −0 DESCRIPTION
  3. +113 −0 R/ENVI.R
  4. +179 −0 R/GIF.R
  5. +201 −0 R/LogitBoost.R
  6. +133 −0 R/base64.R
  7. +115 −0 R/colAUC.R
  8. +31 −0 R/combs.R
  9. +275 −0 R/runfunc.R
  10. +50 −0 R/sample.split.R
  11. +28 −0 R/sumexact.R
  12. +12 −0 R/trapz.R
  13. +9 −0 R/zzz.R
  14. +7 −0 debian/changelog
  15. +22 −0 debian/control
  16. +18 −0 debian/copyright
  17. +3 −0 debian/rules
  18. +115 −0 man/ENVI.Rd
  19. +255 −0 man/GIF.Rd
  20. +97 −0 man/LogitBoost.Rd
  21. +118 −0 man/base64.Rd
  22. +51 −0 man/caTools-internal.Rd
  23. +73 −0 man/caTools-package.Rd
  24. +191 −0 man/colAUC.Rd
  25. +40 −0 man/combs.Rd
  26. +40 −0 man/predict.LogitBoost.Rd
  27. +196 −0 man/runmad.Rd
  28. +265 −0 man/runmean.Rd
  29. +228 −0 man/runminmax.Rd
  30. +253 −0 man/runquantile.Rd
  31. +165 −0 man/runsd.Rd
  32. +88 −0 man/sample.split.Rd
  33. +85 −0 man/sumexact.Rd
  34. +53 −0 man/trapz.Rd
  35. +62 −0 src/Gif2R.cpp
  36. +807 −0 src/GifTools.cpp
  37. +26 −0 src/GifTools.h
  38. +1,074 −0 src/runfunc.c
View
90 CHANGES
@@ -0,0 +1,90 @@
+Changes:
+1) caMassClass-1.0 to caTools-1.0 - caTools created after splitting caMassClass
+ package:
+ - bin2raw and raw2bin files: endian variable was added
+ - raw2bin: additional error checking
+ - runmean, runmax, runmin, runquantile, runmad: additional error checking and
+ corrected error checking
+ - EndRule: added error checking
+ - runmean, runmax, runmin: additional parameter "alg" was added
+ - runmean - new C code can survive round-off errors
+2) caTools-1.1 (7/15/2005)
+ - read.GIF and write.GIF files were added.
+ - bin2raw and raw2bin files: much faster raw to numeric conversion
+ - sum.exact, cumsum.exact and runsum.exact functions were added for
+ under-flow safe addition.
+3) caTools-1.2 (8/8/2005)
+ - minor changes to .Rd files to fix problems found by new 'checkDocFiles'
+ function.
+4) caTools-1.3 (9/23/2005)
+ - changes to colAUC function. Parameters: plotROC and alg were added.
+ Parameter 'p.val' was removed, since it gave wrong results in case of data
+ with ties. And it was too complicated to fix.
+ - added much better testing of "colAUC" in Example section.
+4) caTools-1.4 (9/28/2005)
+ - a small change in 1.3 that used call to 'max' instead of 'pmax' made
+ 'colAUC' return wrong numbers in case of multi-feature data.
+5) caTools-1.5 (11/10/2005)
+ - several new examples
+ - functions raw2bin and bin2raw still work but return warnings. They will be
+ retired in the next version, since they parallel new capabilities of
+ readBin and writeBin.
+ - Argument 'col' of function 'write.gif' was changed to allow several other
+ ways to define a color palette.
+ - base64encode and base64decode now use readBin and writeBin instead
+ raw2bin and bin2raw.
+ 6) caTools-1.6 (04/11/2006)
+ - functions raw2bin and bin2raw were retired, since they parallel new
+ (as of R-2.2.0) capabilities of readBin and writeBin.
+ - Bug in plotting in colAUC function was fixed, after it was reported by Tom
+ Wright.
+ - Documentation of colAUC was updated and some examples modified in order to
+ reduce dependency on external libraries.
+ - GifTools.cc was split into GifTools.cpp and GifTools.cc. The first file
+ contains GIF encoding/decoding algorithm and second is a shell that
+ comunicates with R.
+ 7) caTools-1.7 (Jan 31 2007)
+ - Added 4th variable in 'rgb' function (line 174).
+ 8) caTools-1.8 (Oct. 9 2007)
+ - Major changes to moving window statistics functions:
+ * use fast C code to process array edges
+ * added suport for NaN's
+ * added suport for even size windows
+ * split help file into 5 new help files
+ * added much more examples and self-tests
+ - Followed Prof. Brian Ripley request to move R header files out of extern "C"
+ blocks in C++ files.
+ - Changed licence to GPL
+ 9) caTools-1.9 (July 7 2008)
+ - No code changes
+ - Corrected inconsistent licence information
+ 10) caTools-1.10 (Oct 08 2009)
+ - Fixed runmax to handle correctly negative numbers
+ - Added align argument to moving window statistics functions: runmean, runmax,
+ runmin, runsd, runmad and runquintile functions. It allows left and right
+ alligned window in addition to centered window.
+ - Added support for 2D arrays to be passed to moving window statistics
+ functions: runmean, runmax, runmin, runsd, runmad and runquintile functions.
+ If input array is a 2D matrix than the operations are performed for each
+ column separately. This change was mostly handled by EndRule function. Speed
+ for 2D array input is expected to be slower than for vectors since
+ calculations for beggining and end of arrays if handled in R instead of C.
+ is expected to be
+ - Changed "if(!require(LIB)) warning(..." to ""library(LIB)" to get rid or
+ warnings by RCMD CHECK
+ 11) caTools-1.11 (Dec 2010)
+ - Changed EndRule function used by all run... functions to fix handling of
+ different endrules when for non-central aligments and for k=2.
+ - Fully retired runsum.exact, which was not working for a while, use runmean
+ with "exact" option instead.
+ - Removed references to several no-longer-existing packages and functions from
+ Rd files.
+ - changed documentation of predict.LogitBoost to follow S3 mathod syntax.
+ - renamed sum.exact and cumsum.exact to sumexact and cumsumexact to avoid
+ package build errors. those functions were confused with S3 mathods.
+====================================================\==========================
+ Jarek Tuszynski, PhD. o / \
+ Science Applications International Corporation <\__,|
+ Jaroslaw.W.Tuszynski@saic.com "> \
+ ` \
+
View
@@ -0,0 +1,17 @@
+Package: caTools
+Version: 1.11
+Date: December 6, 2010
+Title: Tools: moving window statistics, GIF, Base64, ROC AUC, etc.
+Author: Jarek Tuszynski <jaroslaw.w.tuszynski@saic.com>
+Maintainer: Jarek Tuszynski <jaroslaw.w.tuszynski@saic.com>
+Depends: R (>= 2.2.0), bitops
+Suggests: MASS, rpart
+Description: Contains several basic utility functions including: moving
+ (rolling, running) window statistic functions, read/write for
+ GIF and ENVI binary files, fast calculation of AUC, LogitBoost
+ classifier, base64 encoder/decoder, round-off error free sum
+ and cumsum, etc.
+License: GPL-3
+Repository: CRAN
+Date/Publication: 2010-12-17 07:35:29
+Packaged: 2010-12-16 17:17:05 UTC; tuszynskij
View
113 R/ENVI.R
@@ -0,0 +1,113 @@
+#===========================================================================#
+# caTools - R library #
+# Copyright (C) 2005 Jarek Tuszynski #
+# Distributed under GNU General Public License version 3 #
+#===========================================================================#
+
+write.ENVI = function(X, filename, interleave=c("bsq", "bil", "bip") )
+{ # write matrix or data cube to binary ENVI file
+ if (is.vector(X)) {
+ nCol = length(X)
+ nRow <- nBand <- 1
+ } else {
+ d = dim(X)
+ nRow = d[1]
+ nCol = d[2]
+ nBand = prod(d)/(nRow*nCol)
+ }
+ dim(X) = c(nRow, nCol, nBand) # make it into 3D array in case it was not
+
+ # check data type
+ data.type = 0
+ if (is.double (X)) data.type = 5 # 64-bit double
+ if (is.integer(X)) data.type = 3 # 32-bit int
+ if (is.complex(X)) data.type = 9 # 2x64-bit complex<double>
+ if (data.type == 0) { # do not know what is it -> make it a double
+ X = as.double(X)
+ data.type = 5
+ }
+
+ # change interleave and store tha data
+ interleave = match.arg(interleave)
+ if (interleave=="bil") X=aperm(X, c(2,3,1)) # R's [row,col,band] -> bil [col,band,row]
+ else if (interleave=="bip") X=aperm(X, c(3,2,1)) # R's [row,col,band] -> bip [band,col,row]
+ else if (interleave=="bsq") X=aperm(X, c(2,1,3)) # R's [row,col,band] -> bsq [col,row,band]
+ writeBin(as.vector(X), filename) # write Envi file
+
+ # write header file
+ out = "ENVI\ndescription = { R-language data }\n"
+ out = paste(out, "samples = ", nCol, "\n", sep="")
+ out = paste(out, "lines = ", nRow, "\n", sep="")
+ out = paste(out, "bands = ", nBand, "\n", sep="")
+ out = paste(out, "data type = ",data.type,"\n", sep="")
+ out = paste(out, "header offset = 0\n", sep="")
+ out = paste(out, "interleave = ",interleave,"\n", sep="") # interleave is assumed to be bsq - in case of 1 band images all 3 formats are the same
+ ieee = if(.Platform$endian=="big") 1 else 0 # does this machine uses ieee (UNIX) format? or is it intel format?
+ out = paste(out, "byte order = ", ieee, "\n", sep="")
+ cat(out, file=paste(filename, ".hdr", sep=""))
+ invisible(NULL)
+}
+
+# =======================================================================================
+
+read.ENVI = function(filename, headerfile=paste(filename, ".hdr", sep=""))
+{ # read matrix or data cube from binary ENVI file
+
+ # parse header file
+ nCol <- nRow <- nBand <- data.type <- header.offset <- byte.order <- (-1)
+ interleave = "bsq"
+ if (!file.exists(headerfile)) stop("read.ENVI: Could not open input header file: ", headerfile)
+ Lines = read.table(headerfile, sep="=", strip.white=TRUE, row.names = NULL, as.is=TRUE, fill=TRUE)
+ Fields = c("samples", "lines", "bands", "data type", "header offset", "interleave", "byte order")
+ for (i in 1:nrow(Lines)) {
+ Lab = tolower(Lines[i,1])
+ Lab = gsub("[ ]+", " ", Lab) # Replace all multiple spaces with a single space
+ j = match(Lab, Fields)
+ Val = Lines[i,2]
+ if (length(j) == 1)
+ switch( j,
+ nCol <- as.integer(Val),
+ nRow <- as.integer(Val),
+ nBand <- as.integer(Val),
+ data.type <- as.integer(Val),
+ header.offset <- as.integer(Val),
+ interleave <- gsub(" ", "", Val),
+ byte.order <- as.integer(Val)
+ )
+ }
+
+ if (nCol <= 0 | nRow <= 0 | nBand <= 0)
+ stop("read.ENVI: Error in input header file ", headerfile, " data sizes missing or incorrect", nRow, nCol, nBand)
+ if (! ( data.type %in% c(1,2,3,4,5,9,12) ) )
+ stop("read.ENVI: Error in input header file ", headerfile, " data type is missing, incorrect or unsupported ")
+
+ # read the data binary file
+ ieee = if(.Platform$endian=="big") 1 else 0 # does this machine uses ieee (UNIX) format? or is it intel format?
+ endian = if(ieee==byte.order | byte.order<0) .Platform$endian else "swap"
+ size = nRow*nCol*nBand
+ if (!file.exists(filename)) stop("read.ENVI: Could not open input file: ", filename)
+ f = file(filename, "rb")
+ if (header.offset>0) readBin(f, raw(), n=header.offset)
+ switch( data.type,
+ X <- readBin(f, integer(), n=size, size=1, signed=FALSE), # data.type==1 -> 1-byte unsigned integer (char)
+ X <- readBin(f, integer(), n=size, size=2, endian=endian), # data.type==2 -> 2-byte short
+ X <- readBin(f, integer(), n=size, endian=endian), # data.type==3 -> 4-byte int
+ X <- readBin(f, double() , n=size, size=4, endian=endian), # data.type==4 -> 4-byte float
+ X <- readBin(f, double() , n=size, endian=endian), , , , # data.type==5 -> 8-byte double
+ X <- readBin(f, complex(), n=size, endian=endian), , , # data.type==9 -> 2x8-byte complex<double>
+ X <- readBin(f, integer(), n=size, size=2, endian=endian, signed=FALSE) # data.type==12 -> 2-byte unsigned short integer
+ )
+ close(f)
+
+ Fields = c("bil", "bip", "bsq")
+ j = match(interleave, Fields)
+ if (length(j)==0) stop("read.ENVI: Error in input header file ", headerfile, " incorrect interleave type")
+ switch(j,
+ { dim(X)<-c(nCol,nBand,nRow); X<-aperm(X, c(3,1,2)); }, # bil [col,band,row] -> R's [row,col,band]
+ { dim(X)<-c(nBand,nCol,nRow); X<-aperm(X, c(3,2,1)); }, # bip [band,col,row] -> R's [row,col,band]
+ { dim(X)<-c(nCol,nRow,nBand); X<-aperm(X, c(2,1,3)); } # bsq [col,row,band] -> R's [row,col,band]
+ )
+ if (nBand==1) dim(X)=c(nRow, nCol)
+ return(X)
+}
+
Oops, something went wrong.

0 comments on commit 4fe8f01

Please sign in to comment.