Slicer Morph GPA | Interactive 3D vizualization | Cannot warp around PCs

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" ...

I can’t replicate this error with SlicerMorph SampleData. Can you:

  1. Go to extension manager, click check for updates and see if there is a more recent SlicerMorph version and tr
  2. Share your data.

UPDATE: If I go to the analysis.json file and change“ExcludedLM”: "[]" to “ExcludedLM”: []and“SemiLandmarks”: "[]" to “SemiLandmarks”: [], it works.

yes, it’s up to date, following Extensions > Check for Updates.
Here is a link for my R directory backup, in the data folder, there’s some .mrk.json in raw and the geomorph2slicermorph2() output is in derived data. I’d share the GitHub, but it doesn’t have the raw data.

Thank you

I am sorry, I am a bit confused. Is this error coming during the GPA of original data in SlicerMorph or when you are trying to move results from geomorph to SlicerMorph using SlicerMorphR?

The error log is from SlicerMorph when setting up the interactive 3D visualization. So, I’ve already exported the GPA+PCA results from geomorph using SlicerMorphR, uploaded them into SlicerMorph, and I’m trying to visualise it, producing that error log.
However, the workaround above involves editing the analysis.json file produced via SlicerMorphR, by removing the ““ around the square brackets, before uploading the GPA+PCA into 3DSlicer/SlicerMorph.
It’s not ideal so you have any input, it’d be appreciated.

Here is a link for some .mrk.json data, and for the GitHub repo
(I had to break the previous link)

landmark configuration includes missing landmarks, so I can’t run them with GPA. I presume you used geomorph to estimate those. I am not sure why you are getting an extra set of ““ from the geomorph2slicermorph2 to function, as it doesn’t happen for me.

I am glad you figured out your work around.