test_io.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. from common import initialize_test_yml_list_measurement
  2. from view import VIEW
  3. from view.python_core.io import read_tif_2Dor3D, write_tif_2Dor3D
  4. import tempfile
  5. import pathlib as pl
  6. import numpy as np
  7. def test_tif_io():
  8. test_yml, test_animal, test_measu = initialize_test_yml_list_measurement()
  9. view = VIEW()
  10. view.update_flags_from_ymlfile(test_yml)
  11. view.initialize_animal(test_animal)
  12. view.load_measurement_data_from_current_animal(test_measu)
  13. temp_tif_fn = str(pl.Path(tempfile.gettempdir()) / f"{tempfile.gettempprefix()}.tif")
  14. write_tif_2Dor3D(view.p1.raw1, temp_tif_fn)
  15. read_stack, labels = read_tif_2Dor3D(temp_tif_fn)
  16. assert np.allclose(view.p1.raw1, read_stack)
  17. assert labels is None
  18. # needs to fix reading labels
  19. # write_tif_2Dor3D(view.p1.raw1[:, :, 0], temp_tif_fn, labels="test")
  20. #
  21. # read_stack, labels = read_tif_2Dor3D(temp_tif_fn)
  22. #
  23. # assert np.allclose(view.p1.raw1[:, :, 0], read_stack)
  24. # assert labels == ["test"]
  25. #
  26. # fake_labels = [str(x) for x in range(view.p1.raw1.shape[2])]
  27. # write_tif_2Dor3D(view.p1.raw1, temp_tif_fn, labels=fake_labels)
  28. #
  29. # read_stack, read_labels = read_tif_2Dor3D(temp_tif_fn)
  30. #
  31. # assert np.allclose(view.p1.raw1, read_stack)
  32. # assert all(x == y for x, y in zip(fake_labels, read_labels))
  33. if __name__ == '__main__':
  34. test_tif_io()