Skip to content

Conversation

@mvdoc
Copy link
Contributor

@mvdoc mvdoc commented Jul 4, 2024

This was a nasty 🪲. To visualize a Vertex/VertexRGB object in a static viewer, the NParray.fromURL method in datamodel.js was using jQuery to fetch the numpy array with the data. However, jQuery by default serializes any type of data and so the binary buffer was automatically encoded as a string. This automatic serialization caused issues when a float32 array was saved (see below for an example.)

This PR completely rewrites the NParray.fromURL method to use an XMLHttpRequest instead of jQuery. In this way the buffer can be fetched as an arraybuffer, and all the portions of the buffer (header/data) can be decoded appropriately.

Example code

import cortex

vtx = cortex.Vertex.random("fsaverage")
cortex.webgl.make_static(
    outpath="test-viewer",
    data=vtx,
    recache=True,
)
python minimal-example-error.py && cd test-viewer && python -m http.server 23423

Before

image

After

image

@mvdoc mvdoc merged commit 6dbb7e0 into gallantlab:main Jul 4, 2024
@mvdoc mvdoc deleted the fix/JS_nparray branch July 4, 2024 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant