@@ -1146,3 +1146,52 @@ def test_tiled_tiff_dataset_get_or_create():
11461146 raise Exception (expected_error_msg )
11471147 except AssertionError :
11481148 pass
1149+
1150+
1151+ def test_changing_layer_bounding_box ():
1152+ delete_dir ("./testoutput/test_changing_layer_bounding_box/" )
1153+ copytree (
1154+ "./testdata/simple_tiff_dataset/" ,
1155+ "./testoutput/test_changing_layer_bounding_box/" ,
1156+ )
1157+
1158+ ds = TiffDataset ("./testoutput/test_changing_layer_bounding_box/" )
1159+ layer = ds .get_layer ("color" )
1160+ mag = layer .get_mag ("1" )
1161+
1162+ bbox_size = ds .properties .data_layers ["color" ].get_bounding_box_size ()
1163+ assert bbox_size == (265 , 265 , 10 )
1164+ original_data = mag .read (bbox_size )
1165+ assert original_data .shape == (1 , 265 , 265 , 10 )
1166+
1167+ layer .set_bounding_box_size ((100 , 100 , 10 )) # decrease boundingbox
1168+
1169+ bbox_size = ds .properties .data_layers ["color" ].get_bounding_box_size ()
1170+ assert bbox_size == (100 , 100 , 10 )
1171+ less_data = mag .read (bbox_size )
1172+ assert less_data .shape == (1 , 100 , 100 , 10 )
1173+ assert np .array_equal (original_data [:, :100 , :100 , :10 ], less_data )
1174+
1175+ layer .set_bounding_box_size ((300 , 300 , 10 )) # increase the boundingbox
1176+
1177+ bbox_size = ds .properties .data_layers ["color" ].get_bounding_box_size ()
1178+ assert bbox_size == (300 , 300 , 10 )
1179+ more_data = mag .read (bbox_size )
1180+ assert more_data .shape == (1 , 300 , 300 , 10 )
1181+ assert np .array_equal (more_data [:, :265 , :265 , :10 ], original_data )
1182+
1183+ layer .set_bounding_box_size ((300 , 300 , 10 )) # increase the boundingbox
1184+
1185+ assert ds .properties .data_layers ["color" ].get_bounding_box_offset () == (0 , 0 , 0 )
1186+
1187+ layer .set_bounding_box (
1188+ offset = (10 , 10 , 0 ), size = (255 , 255 , 10 )
1189+ ) # change offset and size
1190+
1191+ new_bbox_offset = ds .properties .data_layers ["color" ].get_bounding_box_offset ()
1192+ new_bbox_size = ds .properties .data_layers ["color" ].get_bounding_box_size ()
1193+ assert new_bbox_offset == (10 , 10 , 0 )
1194+ assert new_bbox_size == (255 , 255 , 10 )
1195+ new_data = mag .read (new_bbox_size )
1196+ assert new_data .shape == (1 , 255 , 255 , 10 )
1197+ assert np .array_equal (original_data [:, 10 :, 10 :, :], new_data )
0 commit comments