11from  wkcuber .export_wkw_as_tiff  import  run , wkw_name_and_bbox_to_tiff_name 
2+ from  wkcuber .api .bounding_box  import  BoundingBox 
23import  os 
34from  PIL  import  Image 
45from  wkcuber .mag  import  Mag 
56import  wkw 
67import  numpy  as  np 
78from  math  import  ceil 
89
10+ ds_name  =  "simple_wk_dataset" 
11+ source_path  =  os .path .join ("testdata" , ds_name )
12+ 
913
1014def  test_export_tiff_stack ():
11-     destination_path  =  os .path .join ("testoutput" , "WT1_wkw" )
15+     destination_path  =  os .path .join ("testoutput" , ds_name  +  "_tiff" )
16+     bbox  =  BoundingBox ((100 , 100 , 10 ), (100 , 500 , 50 ))
17+     bbox_dict  =  bbox .as_config ()
1218    args_list  =  [
1319        "--source_path" ,
14-         os . path . join ( "testdata" ,  "WT1_wkw" ) ,
20+         source_path ,
1521        "--destination_path" ,
1622        destination_path ,
1723        "--layer_name" ,
1824        "color" ,
1925        "--name" ,
2026        "test_export" ,
2127        "--bbox" ,
22-         "0,0,0,100,100,5" ,
28+         bbox . as_csv () ,
2329        "--mag" ,
2430        "1" ,
2531    ]
2632
27-     bbox  =  {"topleft" : [0 , 0 , 0 ], "size" : [100 , 100 , 5 ]}
28- 
2933    run (args_list )
3034
31-     test_wkw_file_path  =  os .path .join (
32-         "testdata" , "WT1_wkw" , "color" , Mag (1 ).to_layer_name ()
33-     )
35+     test_wkw_file_path  =  os .path .join (source_path , "color" , Mag (1 ).to_layer_name ())
3436    with  wkw .Dataset .open (test_wkw_file_path ) as  dataset :
35-         slice_bbox  =  bbox 
37+         slice_bbox  =  bbox_dict 
3638        slice_bbox ["size" ] =  [slice_bbox ["size" ][0 ], slice_bbox ["size" ][1 ], 1 ]
37-         for  data_slice_index  in  range (1 , bbox ["size" ][2 ] +  1 ):
39+         for  data_slice_index  in  range (1 , bbox_dict ["size" ][2 ] +  1 ):
3840            slice_bbox ["topleft" ] =  [
3941                slice_bbox ["topleft" ][0 ],
4042                slice_bbox ["topleft" ][1 ],
41-                 bbox ["topleft" ][2 ] +  data_slice_index ,
43+                 bbox_dict ["topleft" ][2 ] +  data_slice_index ,
4244            ]
4345            tiff_path  =  os .path .join (
4446                destination_path ,
@@ -49,8 +51,7 @@ def test_export_tiff_stack():
4951                tiff_path 
5052            ), f"Expected a tiff to be written at: { tiff_path }  ." 
5153
52-             test_image  =  np .array (Image .open (tiff_path ))
53-             test_image .transpose ((1 , 0 ))
54+             test_image  =  np .array (Image .open (tiff_path )).T 
5455
5556            correct_image  =  dataset .read (
5657                off = slice_bbox ["topleft" ], shape = slice_bbox ["size" ]
@@ -64,10 +65,10 @@ def test_export_tiff_stack():
6465
6566
6667def  test_export_tiff_stack_tile_size ():
67-     destination_path  =  os .path .join ("testoutput" , "WT1_wkw_tile_size " )
68+     destination_path  =  os .path .join ("testoutput" , ds_name   +   "_tile_size " )
6869    args_list  =  [
6970        "--source_path" ,
70-         os . path . join ( "testdata" ,  "WT1_wkw" ) ,
71+         source_path ,
7172        "--destination_path" ,
7273        destination_path ,
7374        "--layer_name" ,
@@ -87,9 +88,7 @@ def test_export_tiff_stack_tile_size():
8788    run (args_list )
8889
8990    tile_bbox  =  {"topleft" : bbox ["topleft" ], "size" : [30 , 30 , 1 ]}
90-     test_wkw_file_path  =  os .path .join (
91-         "testdata" , "WT1_wkw" , "color" , Mag (1 ).to_layer_name ()
92-     )
91+     test_wkw_file_path  =  os .path .join (source_path , "color" , Mag (1 ).to_layer_name ())
9392    with  wkw .Dataset .open (test_wkw_file_path ) as  dataset :
9493        slice_bbox  =  {"topleft" : bbox ["topleft" ], "size" : bbox ["size" ]}
9594        slice_bbox ["size" ] =  [slice_bbox ["size" ][0 ], slice_bbox ["size" ][1 ], 1 ]
@@ -108,8 +107,7 @@ def test_export_tiff_stack_tile_size():
108107                        tiff_path 
109108                    ), f"Expected a tiff to be written at: { tiff_path }  ." 
110109
111-                     test_image  =  np .array (Image .open (tiff_path ))
112-                     test_image .transpose ((1 , 0 ))
110+                     test_image  =  np .array (Image .open (tiff_path )).T 
113111
114112                    correct_image  =  dataset .read (
115113                        off = [
@@ -131,10 +129,10 @@ def test_export_tiff_stack_tile_size():
131129
132130
133131def  test_export_tiff_stack_tiles_per_dimension ():
134-     destination_path  =  os .path .join ("testoutput" , "WT1_wkw_tiles_per_dimension " )
132+     destination_path  =  os .path .join ("testoutput" , ds_name   +   "_tiles_per_dimension " )
135133    args_list  =  [
136134        "--source_path" ,
137-         os . path . join ( "testdata" ,  "WT1_wkw" ) ,
135+         source_path ,
138136        "--destination_path" ,
139137        destination_path ,
140138        "--layer_name" ,
@@ -154,9 +152,7 @@ def test_export_tiff_stack_tiles_per_dimension():
154152    run (args_list )
155153
156154    tile_bbox  =  {"topleft" : bbox ["topleft" ], "size" : [17 , 17 , 1 ]}
157-     test_wkw_file_path  =  os .path .join (
158-         "testdata" , "WT1_wkw" , "color" , Mag (1 ).to_layer_name ()
159-     )
155+     test_wkw_file_path  =  os .path .join (source_path , "color" , Mag (1 ).to_layer_name ())
160156    with  wkw .Dataset .open (test_wkw_file_path ) as  dataset :
161157        slice_bbox  =  bbox 
162158        slice_bbox ["size" ] =  [slice_bbox ["size" ][0 ], slice_bbox ["size" ][1 ], 1 ]
@@ -177,8 +173,7 @@ def test_export_tiff_stack_tiles_per_dimension():
177173                        tiff_path 
178174                    ), f"Expected a tiff to be written at: { tiff_path }  ." 
179175
180-                     test_image  =  np .array (Image .open (tiff_path ))
181-                     test_image .transpose ((1 , 0 ))
176+                     test_image  =  np .array (Image .open (tiff_path )).T 
182177
183178                    correct_image  =  dataset .read (
184179                        off = [
@@ -200,4 +195,6 @@ def test_export_tiff_stack_tiles_per_dimension():
200195
201196
202197if  __name__  ==  "__main__" :
198+     test_export_tiff_stack ()
203199    test_export_tiff_stack_tile_size ()
200+     test_export_tiff_stack_tiles_per_dimension ()
0 commit comments