Operating system: Windows 11 Home
Slicer version: 5.8.1 r33241 / 11eaf62
Expected behavior: reference model warps around PCs
Actual behavior: Critical error TypeError: unsupported operand type(s) for -: ‘str’ and ‘int’
Hello,
My 3DSlicer and SlicerMorph are up to date. The full error log is
Traceback (most recent call last):
File “C:/Users/corre/AppData/Local/slicer.org/Slicer 5.8.1/slicer.org/Extensions-33241/SlicerMorph/lib/Slicer-5.8/qt-scripted-modules/GPA.py”, line 1777, in onSelect
indexToRemove.append(self.LMExclusionList[i]-1)
TypeError: unsupported operand type(s) for -: ‘str’ and ‘int’
For context, my workflow is: place landmarks on 3Dslicer, export as .mrk.json, import into R using SlicerMorphR::read.markups.json()
, convert into into an array 3D (code below in case that’s the source), estimate missing landmarks using geomorph::estimate.missing()
, conduct GPA using geomorph::gpagen()
and PCA using geomorph::gm.prcomp()
on aligned coordinates, and export using SlicerMorphR::geomorph2slicermorph2()
, and import into 3D slicer using the Load previous analysis. The subjects load and I can ExploreData/Results normally, and the output from geomorph2slicermorph2()
looks “normal” to me.
I’m following this tutorial, except for the transformation to array (because mine is differently sized and I made it in a more intuitive way for me). ChatGPT suggested I mess with the Python file (GPA.py
), by “casting the string to int before subtracting”, but I don’t know Python and I thought I’d try here first.
Very recent user of 3DSlicer and my first time posting. Thankful for any help.
My code for creating the array3d:
json_paths ← list.files(raw_dir, pattern = “\.json$”, full.names = TRUE)
specimen_ids ← tools::file_path_sans_ext(basename(json_paths))
4) Read JSON into numeric matrices
read_lmk_matrix ← function(path) {
m ← SlicerMorphR::read.markups.json(path)
m ← as.matrix(m)
m ← apply(m, 2, as.numeric)
if (is.null(colnames(m))) colnames(m) ← c(“X”, “Y”, “Z”)
m
}
landmark_list ← purrr::map(json_paths, read_lmk_matrix) |> purrr::set_names(specimen_ids)
5) Build array3d
p ← nrow(landmark_list[[1]])
k ← 3
n ← length(landmark_list)
array3d ← array(
NA_real_,dim = c(p, k, n),
dimnames = list(
landmark = seq_len(p),
coord = c(“X”, “Y”, “Z”),
specimen = names(landmark_list)
)
)
for (i in seq_along(landmark_list)) array3d[, , i] ← landmark_list[[i]]
storage.mode(array3d) ← “double”
This produces an object like this
str(array3d)
num [1:21, 1:3, 1:11] 25.4 23.3 22.6 23.1 25.5 ...
- attr(*, "dimnames")=List of 3
..$ landmark: chr [1:21] "1" "2" "3" "4" ...
..$ coord : chr [1:3] "X" "Y" "Z"
..$ specimen: chr [1:11] "ILH_Zvejnieki_34.107.217.mrk" "ILH_Zvejnieki_34.115.228.mrk" "ILH_Zvejnieki_34.116.229.mrk" "ILH_Zvejnieki_34.118.328.mrk" ...