|
14 | 14 | from wkw import wkw |
15 | 15 | from wkw.wkw import WKWException |
16 | 16 |
|
| 17 | +from wkcuber.api.bounding_box import BoundingBox |
17 | 18 | from wkcuber.api.dataset import Dataset |
18 | 19 | from os import makedirs |
19 | 20 |
|
@@ -1439,3 +1440,37 @@ def test_dataset_name(tmp_path: Path) -> None: |
1439 | 1440 | tmp_path / "some_new_name", scale=(1, 1, 1), name="very important dataset" |
1440 | 1441 | ) |
1441 | 1442 | assert ds2.name == "very important dataset" |
| 1443 | + |
| 1444 | + |
| 1445 | +def test_add_copy_layer(tmp_path: Path) -> None: |
| 1446 | + ds = Dataset.create(tmp_path / "ds", scale=(2, 2, 1)) |
| 1447 | + |
| 1448 | + # Create dataset to copy data from |
| 1449 | + other_ds = Dataset.create(tmp_path / "other_ds", scale=(2, 2, 1)) |
| 1450 | + original_color_layer = other_ds.add_layer("color", LayerCategories.COLOR_TYPE) |
| 1451 | + original_color_layer.add_mag(1).write( |
| 1452 | + offset=(10, 20, 30), data=(np.random.rand(32, 64, 128) * 255).astype(np.uint8) |
| 1453 | + ) |
| 1454 | + |
| 1455 | + # Copies the "color" layer from a different dataset |
| 1456 | + ds.add_copy_layer(tmp_path / "other_ds" / "color") |
| 1457 | + assert len(ds.layers) == 1 |
| 1458 | + color_layer = ds.get_layer("color") |
| 1459 | + assert color_layer.get_bounding_box() == BoundingBox( |
| 1460 | + topleft=(10, 20, 30), size=(32, 64, 128) |
| 1461 | + ) |
| 1462 | + assert color_layer.mags.keys() == original_color_layer.mags.keys() |
| 1463 | + assert len(color_layer.mags.keys()) >= 1 |
| 1464 | + for mag in color_layer.mags.keys(): |
| 1465 | + np.array_equal( |
| 1466 | + color_layer.get_mag(mag).read(), original_color_layer.get_mag(mag).read() |
| 1467 | + ) |
| 1468 | + # Test if the copied layer contains actual data |
| 1469 | + assert np.max(color_layer.get_mag(mag).read()) > 0 |
| 1470 | + |
| 1471 | + with pytest.raises(IndexError): |
| 1472 | + # The dataset already has a layer called "color". |
| 1473 | + ds.add_copy_layer(tmp_path / "other_ds" / "color") |
| 1474 | + |
| 1475 | + # Test if the changes of the properties are persisted on disk by opening it again |
| 1476 | + assert "color" in Dataset(tmp_path / "ds").layers.keys() |
0 commit comments