Skip to content

Commit 32c4b82

Browse files
Merge pull request #188 from AnthonyAndroulakis/dims_fix
fix volume.dims setting, update hdr
2 parents 114650e + 1cf5e74 commit 32c4b82

File tree

6 files changed

+60
-40
lines changed

6 files changed

+60
-40
lines changed

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ channels:
44
dependencies:
55
- pip
66
- pip:
7-
- ipyniivue==2.3.3
7+
- ipyniivue==2.4.0
88
- requests
99
- anywidget
1010
- nibabel

js/volume.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,6 @@ async function create_volume(
247247
if (volume.hdr !== null) {
248248
vmodel.set("hdr", getNIFTIData(volume.hdr));
249249
}
250-
if (volume.dims) {
251-
vmodel.set("dims", volume.dims);
252-
}
253250
vmodel.save_changes();
254251
if (volume.img) {
255252
const dataType = lib.getArrayType(volume.img);

js/widget.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ function attachNiivueEventHandlers(nv: niivue.Niivue, model: Model) {
286286
event: "image_loaded",
287287
data: {
288288
id: volume.id,
289+
dims: volume.dims || null,
289290
},
290291
});
291292
};

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ name = "ipyniivue"
77
license = { text = "BSD-2-Clause" }
88
dynamic = ["version"]
99
description = "A Jupyter Widget for Niivue based on anywidget."
10-
dependencies = ["anywidget", "requests", "numpy"]
10+
dependencies = ["anywidget", "requests", "numpy>=2.0.2"]
1111
readme = "README.md"
1212
requires-python = ">=3.9"
1313
classifiers = [

src/ipyniivue/traits.py

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -313,41 +313,41 @@ class NIFTI1Hdr(t.HasTraits):
313313
Extensions flag.
314314
"""
315315

316-
littleEndian = t.Bool().tag(sync=True)
317-
dim_info = t.Int().tag(sync=True)
318-
dims = t.List(t.Int()).tag(sync=True) # image dimensions
319-
intent_p1 = t.Float().tag(sync=True)
320-
intent_p2 = t.Float().tag(sync=True)
321-
intent_p3 = t.Float().tag(sync=True)
322-
intent_code = t.Int().tag(sync=True)
323-
datatypeCode = t.Int().tag(sync=True)
324-
numBitsPerVoxel = t.Int().tag(sync=True)
325-
slice_start = t.Int().tag(sync=True)
326-
slice_end = t.Int().tag(sync=True)
327-
slice_code = t.Int().tag(sync=True)
328-
pixDims = t.List(t.Float()).tag(sync=True) # voxel dimensions
329-
vox_offset = t.Float().tag(sync=True)
330-
scl_slope = t.Float().tag(sync=True)
331-
scl_inter = t.Float().tag(sync=True)
332-
xyzt_units = t.Int().tag(sync=True)
333-
cal_max = t.Float().tag(sync=True)
334-
cal_min = t.Float().tag(sync=True)
335-
slice_duration = t.Float().tag(sync=True)
336-
toffset = t.Float().tag(sync=True)
337-
description = t.Unicode().tag(sync=True)
338-
aux_file = t.Unicode().tag(sync=True)
339-
intent_name = t.Unicode().tag(sync=True)
340-
qform_code = t.Int().tag(sync=True)
341-
sform_code = t.Int().tag(sync=True)
342-
quatern_b = t.Float().tag(sync=True)
343-
quatern_c = t.Float().tag(sync=True)
344-
quatern_d = t.Float().tag(sync=True)
345-
qoffset_x = t.Float().tag(sync=True)
346-
qoffset_y = t.Float().tag(sync=True)
347-
qoffset_z = t.Float().tag(sync=True)
348-
affine = t.List(t.List(t.Float())).tag(sync=True)
349-
magic = t.Unicode().tag(sync=True)
350-
extensionFlag = t.List(t.Int()).tag(sync=True)
316+
littleEndian = t.Bool().tag(sync=False)
317+
dim_info = t.Int().tag(sync=False)
318+
dims = t.List(t.Int()).tag(sync=False) # image dimensions
319+
intent_p1 = t.Float().tag(sync=False)
320+
intent_p2 = t.Float().tag(sync=False)
321+
intent_p3 = t.Float().tag(sync=False)
322+
intent_code = t.Int().tag(sync=False)
323+
datatypeCode = t.Int().tag(sync=False)
324+
numBitsPerVoxel = t.Int().tag(sync=False)
325+
slice_start = t.Int().tag(sync=False)
326+
slice_end = t.Int().tag(sync=False)
327+
slice_code = t.Int().tag(sync=False)
328+
pixDims = t.List(t.Float()).tag(sync=False) # voxel dimensions
329+
vox_offset = t.Float().tag(sync=False)
330+
scl_slope = t.Float().tag(sync=False)
331+
scl_inter = t.Float().tag(sync=False)
332+
xyzt_units = t.Int().tag(sync=False)
333+
cal_max = t.Float().tag(sync=False)
334+
cal_min = t.Float().tag(sync=False)
335+
slice_duration = t.Float().tag(sync=False)
336+
toffset = t.Float().tag(sync=False)
337+
description = t.Unicode().tag(sync=False)
338+
aux_file = t.Unicode().tag(sync=False)
339+
intent_name = t.Unicode().tag(sync=False)
340+
qform_code = t.Int().tag(sync=False)
341+
sform_code = t.Int().tag(sync=False)
342+
quatern_b = t.Float().tag(sync=False)
343+
quatern_c = t.Float().tag(sync=False)
344+
quatern_d = t.Float().tag(sync=False)
345+
qoffset_x = t.Float().tag(sync=False)
346+
qoffset_y = t.Float().tag(sync=False)
347+
qoffset_z = t.Float().tag(sync=False)
348+
affine = t.List(t.List(t.Float())).tag(sync=False)
349+
magic = t.Unicode().tag(sync=False)
350+
extensionFlag = t.List(t.Int()).tag(sync=False)
351351

352352

353353
CAMEL_TO_SNAKE_GRAPH = {

src/ipyniivue/widget.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,17 @@ def _handle_custom_msg(self, content, buffers):
774774
idx = self.get_volume_index_by_id(data["id"])
775775
if idx != -1:
776776
volume = self.volumes[idx]
777+
778+
# set other traits available on-loaded
779+
for key, value in data.items():
780+
if (
781+
key != "id"
782+
and not key.startswith("_")
783+
and key in volume.trait_names()
784+
):
785+
volume.set_trait(key, value)
786+
787+
# only fire loaded event once certain traits are defined
777788
if volume.img is not None and volume.hdr is not None:
778789
handler(volume)
779790
else:
@@ -790,6 +801,17 @@ def check_ready(change):
790801
idx = self.get_mesh_index_by_id(data["id"])
791802
if idx != -1:
792803
mesh = self.meshes[idx]
804+
805+
# set other traits available on-loaded
806+
for key, value in data.items():
807+
if (
808+
key != "id"
809+
and not key.startswith("_")
810+
and key in mesh.trait_names()
811+
):
812+
mesh.set_trait(key, value)
813+
814+
# only fire loaded event once certain traits are defined
793815
if mesh.pts is not None and mesh.tris is not None:
794816
handler(mesh)
795817
else:

0 commit comments

Comments
 (0)