Skip to content

Commit

Permalink
add test for curves, fix traitlets deprecation warning
Browse files Browse the repository at this point in the history
  • Loading branch information
chrishavlin committed Jun 27, 2024
1 parent c4621d8 commit d28e083
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
2 changes: 1 addition & 1 deletion yt_idv/scene_annotations/grid_outlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class GridOutlines(SceneAnnotation):
name = "grid_outline"
data = traitlets.Instance(GridPositions)
box_width = traitlets.CFloat(0.25) # quarter of a dx
box_color = traitlets.Tuple((1.0, 1.0, 1.0), trait=traitlets.CFloat())
box_color = traitlets.Tuple((1.0, 1.0, 1.0)).tag(trait=traitlets.CFloat())
box_alpha = traitlets.CFloat(1.0)

def draw(self, scene, program):
Expand Down
4 changes: 2 additions & 2 deletions yt_idv/scene_components/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class BlockRendering(SceneComponent):
tf_min = traitlets.CFloat(0.0)
tf_max = traitlets.CFloat(1.0)
tf_log = traitlets.Bool(True)
slice_position = traitlets.Tuple((0.5, 0.5, 0.5), trait=traitlets.CFloat())
slice_normal = traitlets.Tuple((1.0, 0.0, 0.0), trait=traitlets.CFloat())
slice_position = traitlets.Tuple((0.5, 0.5, 0.5)).tag(trait=traitlets.CFloat())
slice_normal = traitlets.Tuple((1.0, 0.0, 0.0)).tag(trait=traitlets.CFloat())

priority = 10

Expand Down
2 changes: 1 addition & 1 deletion yt_idv/scene_components/curves.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CurveRendering(SceneComponent):
name = "curve_rendering"
data = traitlets.Instance(CurveData, help="The curve data.")
line_width = traitlets.CFloat(1.0)
curve_rgba = traitlets.Tuple((1.0, 1.0, 1.0, 1.0), trait=traitlets.CFloat())
curve_rgba = traitlets.Tuple((1.0, 1.0, 1.0, 1.0)).tag(trait=traitlets.CFloat())
priority = 10

def render_gui(self, imgui, renderer, scene):
Expand Down
30 changes: 30 additions & 0 deletions yt_idv/tests/test_yt_idv.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

import base64

import numpy as np
import pytest
import yt
import yt.testing
from pytest_html import extras

import yt_idv
from yt_idv.scene_components.curves import CurveCollectionRendering, CurveRendering
from yt_idv.scene_data.curve import CurveCollection, CurveData


@pytest.fixture(autouse=True)
Expand Down Expand Up @@ -116,3 +119,30 @@ def test_annotate_text(osmesa_empty, image_store):
def test_isocontour_functionality(osmesa_fake_amr, image_store):
osmesa_fake_amr.scene.components[0].render_method = "isocontours"
image_store(osmesa_fake_amr)


def test_curves(osmesa_fake_amr, image_store):
# add a single curve

curved = CurveData()
x1d = np.linspace(0, 1, 10)
xyz = np.column_stack([x1d, x1d, x1d])
curved.add_data(xyz)
curve_render = CurveRendering(data=curved, curve_rgba=(1.0, 0.0, 0.0, 1.0))
curve_render.display_name = "single streamline"
osmesa_fake_amr.scene.data_objects.append(curved)
osmesa_fake_amr.scene.components.append(curve_render)

curve_collection = CurveCollection()
curve_collection.add_curve(xyz * 2.0)
curve_collection.add_curve(xyz * 3.0)
curve_collection.add_data() # call add_data() after done adding curves

cc_render = CurveCollectionRendering(data=curve_collection)
cc_render.display_name = "multiple streamlines"
osmesa_fake_amr.scene.data_objects.append(curve_collection)
osmesa_fake_amr.scene.components.append(cc_render)

image_store(osmesa_fake_amr)

CurveCollection

0 comments on commit d28e083

Please sign in to comment.