Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX avoid using jQuery for getting numpy arrays #544

Merged
merged 2 commits into from
Jul 4, 2024

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
9 checks passed
@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