Hi Ondrej, I was hoping to write something similar to your supplylm function myself, but hadn't found a clean solution yet. Thank you!! Your tool is perfect for mirroring my dataset since the first half of my landmarks are in the YZ plane and the second half are in XZ and a few datasets have slightly different XYZ origins (not all at 0,0,0). I'll even be able to modify supplylm to estimate my midpoints when bilaterally symmetric landmarks are present on both sides.
Huge timesaver, thanks again, Katie On Tuesday, September 22, 2020 at 2:11:05 PM UTC-4 [email protected] wrote: > Hello, > you can try the code below, it works fine with my data. > Ondrej > > # functions > > mat2arr <- function(mat) aperm(array(t(mat), c(3, ncol(mat) / 3, > nrow(mat))), c(2,1,3)) > supplylm <- function(X, midplane, rightside, leftside) { > p <- nrow(X) > shift <- colMeans(X[midplane,]) > rrot <- eigen(var(X[midplane,]))$vectors > rrot[,3] <- sign(det(rrot)) * rrot[,3] > CX <- X - rep(1, p) %*% t(shift) > RX <- CX %*% rrot > rna <- which(is.na(RX[rightside,1])) > lna <- which(is.na(RX[leftside,1])) > if (length(rna) > 0) { > RX[rightside[rna],] <- RX[leftside[rna],] %*% diag(c(1,1,-1)) > } > if (length(lna) > 0) { > RX[leftside[lna],] <- RX[rightside[lna],] %*% diag(c(1,1,-1)) > } > CX <- RX %*% solve(rrot) > X <- CX + rep(1, p) %*% t(shift) > return(X) > } > > # create M, R, L = vectors with numbers of midplane, right side and left > side landmarks, respectively; corresponding right side and left side > landmarks have to be given in the same order > > # read in your data > A <- mat2arr(read.csv("fossilseeds.csv", row.names=1)) > > # supply missing landmarks > for (i in 1:dim(A)[3]) { > A[,,i] <- supplylm(A[,,i], midplane=M, rightside=R, leftside=L) > } > > > > On Monday, September 21, 2020 at 2:11:37 AM UTC+2 [email protected] > wrote: > >> Hi everyone, I'm new here! >> >> I have a landmark dataset created in Amira for seeds with bilateral >> symmetry. Some specimens are fossils with missing landmarks. I converted >> the Amira datasets to text files formatted like TPS 3D landmarks and as a >> csv file (see screenshots below). >> ->sample TPS formatted 3D landmark file (1 specimen) >> >> [image: sample_landmark.jpg] >> -> sample landmark csv file (4 specimens, landmarks 1-2) >> [image: sample_landmarkcsv.jpg] >> >> I successfully imported them into R geomorph, used estimate.missing with >> TPS, gpagen for Procrustes fit, and bilat.symmetry to look at the effects >> of size. However, I'm not happy with the precision of the landmark >> estimation (see screenshots of estimated landmarks-above and without >> estimated landmarks-below). >> >> [image: landmarks_procrustes_Page_2.jpg] >> [image: landmarks_procrustes_Page_3.jpg] >> I'd like to try Morpho for estimating landmarks considering bilaterial >> symmetry with fixLMmirror, but I'm not able to load my data into Morpho. >> ->When loading my TPS-formatted landmark file using readallTPS, I get the >> error: Error in if (nLM[i] > 0) { : missing value where TRUE/FALSE needed. >> ->When loading landmark csv file using readLandmarks.csv, I get the >> error: Error in dimnames(arr) <- list(rown, c("X", "Y", "Z")) : length of >> 'dimnames' [2] not equal to array extent. >> -->I assumed the 2nd error means that XYZ coordinates for each landmark >> should be combined in the csv file, so I reformatted the data (screenshot >> below) and tried again. >> [image: sample_landmarkcsv2.jpg] >> -->New error: Error in h(simpleError(msg, call)) : error in evaluating >> the argument 'x' in selecting a method for function 'as.matrix': undefined >> columns selected >> >> *Summary* >> I am not sure why my TPS-formatted landmark file isn't working with >> Morpho, because it looks like all examples I've seen and works in geomorph. >> I also haven't been able to find a sample landmark csv dataset to compare >> with. >> *->Does anyone have small sample datasets of either they could share with >> me or show me screenshots of?* >> >> PS I also tried LOST, but am having some problems with dependencies and >> my R version so I'd prefer to use Morpho. >> >> Thanks in advance, >> >> Katie >> > -- 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]. To view this discussion on the web visit https://groups.google.com/d/msgid/morphmet2/74661583-87ff-47ac-b73e-1c7fb9c2c091n%40googlegroups.com.
