Skip to content

cortex.webgl.make_static throws b'CTM_INVALID_MESH' #569

Open
@rgiulia

Description

@rgiulia

Hi,

I'm encountering an error when trying to use cortex.webgl.make_static with my subject data, although the same code works perfectly with fsaverage.
This is my code:

sub = "sub-05"
cortex_dir = f'{derivatives_pth}/pycortex/db/{sub}'
temp_dir = f'{derivatives_pth}/temp_data/{sub}_rand_ds'
os.makedirs(temp_dir,exist_ok=True)
cortex.freesurfer.import_subj(freesurfer_subject = sub, pycortex_subject = sub, freesurfer_subject_dir = setup['fsPath'], whitematter_surf = 'smoothwm')

surfs = [cortex.polyutils.Surface(*d) for d in cortex.db.get_surf(sub, "fiducials")]
num_verts = surfs[0].pts.shape[0] + surfs[1].pts.shape[0]
rand_data = np.random.randn(num_verts)
vertex_data = cortex.Vertex(rand_data, sub)
ds = cortex.Dataset(rand=vertex_data)
cortex.webgl.make_static(outpath=temp_dir, data=ds,recache=True)

I get this error:

Generating new ctm file...
wm
wm
inflated
inflated
/opt/anaconda3/envs/nilearnenv/lib/python3.13/site-packages/cortex/brainctm.py:113: RuntimeWarning: invalid value encountered in cast
self.left.aux[:,1] = npz.left
/opt/anaconda3/envs/nilearnenv/lib/python3.13/site-packages/cortex/brainctm.py:114: RuntimeWarning: invalid value encountered in cast
self.right.aux[:,1] = npz.right

Exception Traceback (most recent call last)
Cell In[463], line 7
5 vertex_data = cortex.Vertex(rand_data, sub)
6 ds = cortex.Dataset(rand=vertex_data)
----> 7 cortex.webgl.make_static(outpath=temp_dir, data=ds,recache=True)

File /opt/anaconda3/envs/nilearnenv/lib/python3.13/site-packages/cortex/utils.py:40, in DocLoader.call(self, *args, **kwargs)
39 def call(self, *args, **kwargs):
---> 40 return self._load()(*args, **kwargs)

File /opt/anaconda3/envs/nilearnenv/lib/python3.13/site-packages/cortex/webgl/view.py:162, in make_static(outpath, data, recache, template, anonymize, overlays_available, overlays_visible, labels_visible, types, html_embed, copy_ctmfiles, title, layout, overlay_file, curvature_brightness, curvature_contrast, curvature_smoothness, surface_specularity, **kwargs)
153 subjects = list(package.subjects)
155 ctmargs = dict(
156 method="mg2",
157 level=9,
(...)
160 overlays_available=overlays_available,
161 )
--> 162 ctms = dict((subj, utils.get_ctmpack(subj, types, **ctmargs)) for subj in subjects)
163 package.reorder(ctms)
165 db.auxfile = None

File /opt/anaconda3/envs/nilearnenv/lib/python3.13/site-packages/cortex/webgl/view.py:162, in (.0)
153 subjects = list(package.subjects)
155 ctmargs = dict(
156 method="mg2",
157 level=9,
(...)
160 overlays_available=overlays_available,
161 )
--> 162 ctms = dict((subj, utils.get_ctmpack(subj, types, **ctmargs)) for subj in subjects)
163 package.reorder(ctms)
165 db.auxfile = None

File /opt/anaconda3/envs/nilearnenv/lib/python3.13/site-packages/cortex/utils.py:105, in get_ctmpack(subject, types, method, level, recache, decimate, external_svg, overlays_available)
103 print("Generating new ctm file...")
104 from . import brainctm
--> 105 ptmap = brainctm.make_pack(ctmfile,
106 subject,
107 types=types,
108 method=method,
109 level=level,
110 decimate=decimate,
111 external_svg=external_svg,
112 overlays_available=overlays_available)
113 return ctmfile

File /opt/anaconda3/envs/nilearnenv/lib/python3.13/site-packages/cortex/brainctm.py:292, in make_pack(outfile, subj, types, method, level, decimate, disp_layers, external_svg, overlays_available)
290 if not os.path.exists(os.path.split(outfile)[0]):
291 os.makedirs(os.path.split(outfile)[0])
--> 292 return ctm.save(os.path.splitext(outfile)[0],
293 method=method,
294 level=level,
295 external_svg=external_svg,
296 overlays_available=overlays_available)

File /opt/anaconda3/envs/nilearnenv/lib/python3.13/site-packages/cortex/brainctm.py:139, in BrainCTM.save(self, path, method, external_svg, overlays_available, **kwargs)
136 mapname = path + ".npz"
138 # Save CTM concatenation
--> 139 (lpts, _, _), lbin = self.left.save(method=method, **kwargs)
140 (rpts, _, _), rbin = self.right.save(method=method, **kwargs)
142 offsets = [0]

File /opt/anaconda3/envs/nilearnenv/lib/python3.13/site-packages/cortex/brainctm.py:237, in Hemi.save(self, **kwargs)
235 def save(self, **kwargs):
236 self.ctm.addAttrib(self.aux, 'auxdat')
--> 237 self.ctm.save(**kwargs)
238 ctm = CTMfile(self.tf.name)
239 return ctm.getMesh(), self.tf.read()

File /opt/anaconda3/envs/nilearnenv/lib/python3.13/site-packages/cortex/openctm.pyx:213, in cortex.openctm.CTMfile.save()

Exception: b'CTM_INVALID_MESH'.


I confirmed that the .gii surfaces loaded to pycrotex look visually normal in fsleyes (No NaNs; All polygons within bounds; No degenerate triangles).

Would really appreciate any insight!

Thanks in advance 🙏
Giulia

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions