@@ -42,18 +42,62 @@ def test_write():
42
42
tv .write , out_f , [],{'hdr_size' : 0 })
43
43
44
44
45
+ def test_write_scalars_props ():
46
+ # Test writing of scalar array with streamlines
47
+ N = 6
48
+ M = 2
49
+ P = 4
50
+ points = np .arange (N * 3 ).reshape ((N ,3 ))
51
+ scalars = np .arange (N * M ).reshape ((N ,M )) + 100
52
+ props = np .arange (P ) + 1000
53
+ # If scalars not same size for each point, error
54
+ out_f = StringIO ()
55
+ streams = [(points , None , None ),
56
+ (points , scalars , None )]
57
+ assert_raises (tv .DataError , tv .write , out_f , streams )
58
+ out_f .seek (0 )
59
+ streams = [(points , np .zeros ((N ,M + 1 )), None ),
60
+ (points , scalars , None )]
61
+ assert_raises (tv .DataError , tv .write , out_f , streams )
62
+ # Or if scalars different N compared to points
63
+ bad_scalars = np .zeros ((N + 1 ,M ))
64
+ out_f .seek (0 )
65
+ streams = [(points , bad_scalars , None ),
66
+ (points , bad_scalars , None )]
67
+ assert_raises (tv .DataError , tv .write , out_f , streams )
68
+ # Similarly properties must have the same length for each streamline
69
+ out_f .seek (0 )
70
+ streams = [(points , scalars , None ),
71
+ (points , scalars , props )]
72
+ assert_raises (tv .DataError , tv .write , out_f , streams )
73
+ out_f .seek (0 )
74
+ streams = [(points , scalars , np .zeros ((P + 1 ,))),
75
+ (points , scalars , props )]
76
+ assert_raises (tv .DataError , tv .write , out_f , streams )
77
+ # If all is OK, then we get back what we put in
78
+ out_f .seek (0 )
79
+ streams = [(points , scalars , props ),
80
+ (points , scalars , props )]
81
+ tv .write (out_f , streams )
82
+ out_f .seek (0 )
83
+ back_streams , hdr = tv .read (out_f )
84
+ for actual , expected in zip (streams , back_streams ):
85
+ for a_el , e_el in zip (actual , expected ):
86
+ assert_array_equal (a_el , e_el )
87
+
88
+
45
89
def streams_equal (stream1 , stream2 ):
46
- if not np .all (stream1 [0 ] == stream1 [0 ]):
90
+ if not np .all (stream1 [0 ] == stream2 [0 ]):
47
91
return False
48
92
if stream1 [1 ] is None :
49
93
if not stream2 [1 ] is None :
50
94
return False
51
95
if stream1 [2 ] is None :
52
96
if not stream2 [2 ] is None :
53
97
return False
54
- if not np .all (stream1 [1 ] == stream1 [1 ]):
98
+ if not np .all (stream1 [1 ] == stream2 [1 ]):
55
99
return False
56
- if not np .all (stream1 [2 ] == stream1 [2 ]):
100
+ if not np .all (stream1 [2 ] == stream2 [2 ]):
57
101
return False
58
102
return True
59
103
0 commit comments