Dear David,

when you do many operations in Amira or Avizo for a bug the landmarkAscii file 
is converted in a 2setlandmarkAscii file, in fact a second empty matrix will be 
added…


I report two functions to convert a landmarkAscii file or a folder containing 
the amira/avizo Landmark files in an array k*3*n, where k=number of landmarks 
and n=number of specimens. 

My functions read only the matrix between the @1 and @2. 



Let me know if it works or not…


Best,

Antonio


#' read.amira.set
#'
#' This function convert a file landmark set of Amira in a array
#' @param name.file character: path of landamrkascii file
#' @param nland numeric: number of landmark sampled in Amira, if is set on 
"auto" will be automatically recognized the landmark number
#' @return array.set numeric: an array with landmark coordinates (kxdxn)
#' @author Antonio Profico
#' @export
#' 


read.amira.set=function(name.file,nland){
A <- readLines(name.file, n = 100)
end <- which(A == "@1")
end_2 <- which(A == "@2")
if(length(end_2!=0)){
print(paste("file named",name.file, "contains a second matrix of 000"))
B_junk=read.table(name.file,skip=end,nrows=(end_2-end-2))
if(nland!="auto"){
if (dim(B_junk)[1] != nland){
print(paste("nland is different from dim(matrix)[1]: 
",paste("nland=",nland,",",sep=""),
  paste("dim(matrix)[1]=", dim(B_junk)[1],sep="")))  
B=matrix(NA,ncol=3,nrow=nland)}
if(dim(B_junk)[1]==nland){
B=B_junk  
}}
if(nland=="auto"){
B=read.table(name.file,skip=end,nrows=(end_2-end-2))
}}
if(length(end_2)==0){
B_junk=read.table(name.file,skip=end)
if(nland!="auto"){
if (dim(B_junk)[1] != nland){
print(paste("nland is different from dim(matrix)[1]: 
",paste("nland=",nland,",",sep=""),
paste("dim(matrix)[1]=", dim(B_junk)[1],sep="")))
B=matrix(NA,ncol=3,nrow=nland)}
if(dim(B_junk)[1]==nland){
B=B_junk  
}}
if(nland=="auto"){
B=B_junk}}
array.set=array(as.matrix(B),dim=c(dim(B)[1],3,1))
dimnames(array.set)[[3]]=list(name.file)
return(array.set)}






#' read.amira.dir
#'
#' This function read and store in array the coordinated allocated in a folder 
in separate files (format
#' @param path.dir character: path of the folder
#' @param nland numeric: number of landmark sampled in Amira
#' @return array.set numeric: a kxdxn array with landmark coordinates
#' @author Antonio Profico
#' @export


read.amira.dir=function(path.dir,nland){
names=list.files(path.dir)
if(nland=="auto"){
dims=c()
for(i in 1:length(names)){
dims[i]=dim(read.amira.set(paste(path.dir,"/",names[i],sep=""),"auto"))[1]}
array.amira=array(NA,dim=c(as.numeric(names(sort(-table(dims)))[1]),3,length(names)))}
else{array.amira=array(NA,dim=c(nland,3,length(names)))}
for(i in 1:length(names)){
array.amira[,,i]=read.amira.set(paste(path.dir,"/",names[i],sep=""),nland) 
}
if(length(names)==1){
dimnames(array.amira)[[3]]=list(names)}
if(length(names)!=1){
dimnames(array.amira)[[3]]=names}
return(array.amira)
}








______________________________________

Antonio Profico
PhD student
Department of Environmental Biology – Dipartimento di Biologia Ambientale
SAPIENZA Università di Roma

Lab.  06 4991 2690
Mob. 3293440766






Da: David Katz
Data invio: ‎mercoledì‎ ‎20‎ ‎gennaio‎ ‎2016 ‎06‎:‎49
A: Emma Sherratt
Cc: MORPHMET





I won't get back to my office, and the hard drive where the files are stored, 
for about a week. I'll send something along then. 



Thanks, Emma.

David



On Wed, Jan 20, 2016 at 12:08 AM, Emma Sherratt <[email protected]> wrote:



Hi David,




Not sure what the file actually looks like since you’ve not included a sample 
here. However I suggest taking a look at the readland functions in geomorph R 
package to see how we tackle the different types. If you want, send it through 
to us and we can take a look. If there’s a lot of people using AVIZO for 
digitising, we can include a function in geomorph.




Regarding a read function writing? Nope, never heard of that.




Em



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Emma Sherratt, PhD.


Lecturer in Zoology,

Zoology Division, School of Environmental and Rural Science, 

Room L112 Bldg C02, 

University of New England, 

Armidale, NSW, Australia, 2351

Tel: +61 2 6773 5041

email: [email protected]

Twitter: @DrEmSherratt



Caecilians are legless amphibians...
                      __
    (\   .-.   .-.   /_")
     \\_//^\\_//^\\_//
      `"`   `"`   `"`
learn more about them here: www.emmasherratt.com/caecilians




On 20 January 2016 at 14:50:38, David Katz ([email protected]) wrote:







Hi everyone,  



I've collected 3D landmarks on a series of cranial surface models in Avizo. 
Avizo's landmark editor outputs .landmarkAscii files, which I would like to 
read into R. The way I've done the reading has the following very unexpected 
effect: sometimes, it writes additional data to my .landmarkAscii files. I'd 
like to understand why, but am mostly interested in finding a solution.




To read in the landmark files for a specimen...





# Below, avz.file is the filepath for the .landmarkAscii  

# file for a single specimen.

# The code reads the .landmarkAscii file with read.csv. 

# This is useful because the object created lays out 

# the informational data that precedes the coordinate data 

# predictably. This makes it easy to lop off the 

# informational data. 

  read.lms <- read.csv(avz.file, header=FALSE)[,1]




  # The last row of informational data will contain the 

  # text "@1" and nothing else. 

  lm.start <- which(read.lms=="@1")+1




  # Now it is possible to create an object with landmark 

  # data only. R interprets each landmark (all three 

  # coordinates together) as a factor. I convert the factor 

  # vector to a character vector.

  lm.char <-

     as.character(droplevels(

         read.lms[(lm.start):length(read.lms)]))





  # Then I create an empty matrix for the landmark data    


  lm.mat <- matrix(NA, nrow=length(lm.char), ncol=3)




  # Then fill lm.mat with the landmark data. As mentioned, 

  # lm.char is a vector. Each element of that vector 

  # contains the X, Y, and Z coordinate for a landmark.

  # The coordinates are separated by spaces 

  # (or maybe tabs)


  for(i in 1:nrow(lm.mat)) 
     {lm.mat[i,] <- 

         as.numeric(unlist(strsplit(ctlm.char[i], " ")))}

 

That's it. The code above will read in the data and make a landmark matrix. 
Unfortunately, it sometimes also writes additional lines to the .landmarkAscii 
file. The first added element is "@2." Thereafter, the landmark file adds as 
many three-coordinate triplets as there are landmarks in the original data 
file. The values of these triplets are 0,0,1 (or maybe 1,0,0).




This is really strange behavior. A read function shouldn't write. 




My issue may be better suited to an R forum, but I am hoping someone here has 
reliable code for reading Avizo landmarks into R.




Thanks in advance. 

David






--





David Katz
University of California, Davis

--
MORPHMET may be accessed via its webpage at http://www.morphometrics.org
---
You received this message because you are subscribed to the Google Groups 
"MORPHMET" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].

-- 
MORPHMET may be accessed via its webpage at http://www.morphometrics.org
--- 
You received this message because you are subscribed to the Google Groups 
"MORPHMET" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].





-- 





David Katz
Doctoral Candidate
Evolutionary Anthropology
University of California, Davis
Young Hall 204


ResearchGate profile


-- 
MORPHMET may be accessed via its webpage at http://www.morphometrics.org
--- 
You received this message because you are subscribed to the Google Groups 
"MORPHMET" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].

-- 
MORPHMET may be accessed via its webpage at http://www.morphometrics.org
--- 
You received this message because you are subscribed to the Google Groups 
"MORPHMET" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].

Reply via email to