diff --git a/examples/example_basic.ipynb b/examples/example_basic.ipynb index 7fa65910b9078944cef3d566248c6978558e99cb..23005dbf8504108e1b47076fed5b73bb5ce051f9 100644 --- a/examples/example_basic.ipynb +++ b/examples/example_basic.ipynb @@ -12,7 +12,7 @@ "\n", "def create_example_file(path):\n", " # Create a new io file object with a 100x100cm world\n", - " f = robofish.io.File(world_size_cm=[100, 100], frequency_hz=25.0)\n", + " f = robofish.io.File(world_size_cm=[100, 100], frequency_hz=25.0, world_shape=\"rectangle\")\n", "\n", " # create a robofish with 1000 timesteps. If we would not give a name, the name would be generated to be robot_1.\n", " robofish_timesteps = 1000\n", diff --git a/examples/example_basic.py b/examples/example_basic.py index f37d0cc253053f8e5ffa06000d79dea38d80f927..a8257746399d3aa461a55e5cfbf4061d4ffa7f4e 100755 --- a/examples/example_basic.py +++ b/examples/example_basic.py @@ -5,7 +5,9 @@ import numpy as np def create_example_file(path): # Create a new io file object with a 100x100cm world. # Mode "w" means that the file should be opened with write access. - f = robofish.io.File(path, "w", world_size_cm=[100, 100], frequency_hz=25.0) + f = robofish.io.File( + path, "w", world_size_cm=[100, 100], frequency_hz=25.0, world_shape="rectangle" + ) # create a robofish with 1000 timesteps. If we would not give a name, the name would be generated to be robot_1. robofish_timesteps = 1000 diff --git a/examples/example_readme.py b/examples/example_readme.py index 7b2e22c66fbdb08d9520c0a23deac58ed65f9184..cf77488b96577c557d5e3f1bafa26e9f39bd5583 100644 --- a/examples/example_readme.py +++ b/examples/example_readme.py @@ -5,7 +5,9 @@ import numpy as np def create_example_file(path): # Create a new robofish io file # Mode "w" means that the file should be opened with write access. - f = robofish.io.File(path, "w", world_size_cm=[100, 100], frequency_hz=25.0) + f = robofish.io.File( + path, "w", world_size_cm=[100, 100], frequency_hz=25.0, world_shape="rectangle" + ) f.attrs["experiment_setup"] = "This is a simple example with made up data." # Create a new robot entity with 10 timesteps. diff --git a/src/robofish/io/app.py b/src/robofish/io/app.py index 2f4091db6ac1a0c51d40b42a3bb31ddd5086be14..0efc84c86cf9f4a4fd986da6ba8d4ca863e47665 100644 --- a/src/robofish/io/app.py +++ b/src/robofish/io/app.py @@ -430,7 +430,9 @@ def update_world_shape(args: dict = None) -> None: for file in pbar: pbar.set_description(f"Updating {file.name}") - with robofish.io.File(file, "r+") as f: + with robofish.io.File( + file, "r+", validate_when_saving=False, calculate_data_on_close=False + ) as f: f.attrs["world_shape"] = args.world_shape pbar.update(1) diff --git a/tests/resources/invalid.hdf5 b/tests/resources/invalid.hdf5 index 18e2361c58dce4478a173e40f9c998cda90beac7..e76736436cc0d0499e8a95a031bccc449a07fc50 100755 Binary files a/tests/resources/invalid.hdf5 and b/tests/resources/invalid.hdf5 differ diff --git a/tests/resources/nan_test.hdf5 b/tests/resources/nan_test.hdf5 index 92c3050e3b5204721b0eb0a0543adf0c4d5f65c0..daabe3c98a442a0f35bfe834d9c09cae6cd8ad59 100644 Binary files a/tests/resources/nan_test.hdf5 and b/tests/resources/nan_test.hdf5 differ diff --git a/tests/resources/valid_1.hdf5 b/tests/resources/valid_1.hdf5 index 664e40a39b908364ac70cf99dc11715a6ecd2abc..cb5d38c857def87d8719ef309c189fe4374bc308 100644 Binary files a/tests/resources/valid_1.hdf5 and b/tests/resources/valid_1.hdf5 differ diff --git a/tests/resources/valid_2.hdf5 b/tests/resources/valid_2.hdf5 index eb8c69e1a01f1704c29c94b7c85590c5443275dd..a080dda64d6ba7d59d2505482757249725376005 100644 Binary files a/tests/resources/valid_2.hdf5 and b/tests/resources/valid_2.hdf5 differ diff --git a/tests/robofish/evaluate/test_app_evaluate.py b/tests/robofish/evaluate/test_app_evaluate.py index d8b1d69947a7e6208b085303cb521c95b9a8ec60..4b1332f7dad72d268e1c6f59a571731f2ca06159 100644 --- a/tests/robofish/evaluate/test_app_evaluate.py +++ b/tests/robofish/evaluate/test_app_evaluate.py @@ -14,46 +14,43 @@ h5py_file_2 = utils.full_path(__file__, "../../resources/valid_2.hdf5") nan_file_path = utils.full_path(__file__, "../../resources/nan_test.hdf5") +class DummyArgs: + def __init__(self, analysis_type, paths, save_path, add_train_data): + self.paths = paths + self.names = None + self.analysis_type = analysis_type + self.save_path = save_path + self.labels = None + self.add_train_data = add_train_data + + def test_app_validate(tmp_path): """This tests the function of the robofish-io-validate command""" - class DummyArgs: - def __init__(self, analysis_type, paths, save_path): - self.paths = paths - self.names = None - self.analysis_type = analysis_type - self.save_path = save_path - self.labels = None - for mode in app.function_dict().keys(): if mode == "all": - app.evaluate(DummyArgs(mode, [h5py_file_1], tmp_path)) - app.evaluate(DummyArgs(mode, [h5py_file_2, h5py_file_2], tmp_path)) - app.evaluate(DummyArgs(mode, [nan_file_path], tmp_path)) + app.evaluate(DummyArgs(mode, [h5py_file_1], tmp_path, False)) + app.evaluate(DummyArgs(mode, [h5py_file_2, h5py_file_2], tmp_path, False)) + app.evaluate(DummyArgs(mode, [nan_file_path], tmp_path, False)) else: - app.evaluate(DummyArgs(mode, [h5py_file_1], tmp_path / "image.png")) + app.evaluate(DummyArgs(mode, [h5py_file_1], tmp_path / "image.png", False)) app.evaluate( - DummyArgs(mode, [h5py_file_2, h5py_file_2], tmp_path / "image.png") + DummyArgs( + mode, [h5py_file_2, h5py_file_2], tmp_path / "image.png", False + ) ) def test_app_validate(tmp_path): """This tests the function of the robofish-io-validate command""" - - class DummyArgs: - def __init__(self, analysis_type, paths, save_path): - self.paths = paths - self.names = None - self.analysis_type = analysis_type - self.save_path = save_path - self.labels = None - for mode in app.function_dict().keys(): if mode == "all": - app.evaluate(DummyArgs(mode, [h5py_file_1], tmp_path)) - app.evaluate(DummyArgs(mode, [h5py_file_2, h5py_file_2], tmp_path)) + app.evaluate(DummyArgs(mode, [h5py_file_1], tmp_path, False)) + app.evaluate(DummyArgs(mode, [h5py_file_2, h5py_file_2], tmp_path, False)) else: - app.evaluate(DummyArgs(mode, [h5py_file_1], tmp_path / "image.png")) + app.evaluate(DummyArgs(mode, [h5py_file_1], tmp_path / "image.png", False)) app.evaluate( - DummyArgs(mode, [h5py_file_2, h5py_file_2], tmp_path / "image.png") + DummyArgs( + mode, [h5py_file_2, h5py_file_2], tmp_path / "image.png", False + ) ) diff --git a/tests/robofish/io/test_entity.py b/tests/robofish/io/test_entity.py index 0d843bb2829b40b9b0df4b8a05afd27c43b219db..38d50dea85d464b39a4a5958f80e00231a032500 100644 --- a/tests/robofish/io/test_entity.py +++ b/tests/robofish/io/test_entity.py @@ -4,7 +4,9 @@ import numpy as np def test_entity_object(): - sf = robofish.io.File(world_size_cm=[100, 100], frequency_hz=25) + sf = robofish.io.File( + world_size_cm=[100, 100], frequency_hz=25, world_shape="rectangle" + ) f = sf.create_entity("fish", positions=[[10, 10]]) assert type(f) == robofish.io.Entity, "Type of entity was wrong" assert f.name == "fish_1", "Name of entity was wrong" @@ -40,7 +42,9 @@ def test_entity_turns_speeds(): There is an open issue, to check this test again: https://git.imp.fu-berlin.de/bioroboticslab/robofish/io/-/issues/14 """ - f = robofish.io.File(world_size_cm=[100, 100], frequency_hz=25) + f = robofish.io.File( + world_size_cm=[100, 100], frequency_hz=25, world_shape="rectangle" + ) circle_rad = np.linspace(0, 2 * np.pi, num=100) circle_size = 40 poses_rad = np.stack( diff --git a/tests/robofish/io/test_file.py b/tests/robofish/io/test_file.py index 04d4b988148fe4c44304deac663e1bb5d6422098..927f44ff4d30f44b84bb396529b4d31c0a563698 100644 --- a/tests/robofish/io/test_file.py +++ b/tests/robofish/io/test_file.py @@ -15,33 +15,37 @@ nan_file_path = utils.full_path(__file__, "../../resources/nan_test.hdf5") def test_constructor(): - sf = robofish.io.File(world_size_cm=[100, 100]) + sf = robofish.io.File(world_size_cm=[100, 100], world_shape="rectangle") sf.validate() sf.close() def test_context(): - with robofish.io.File(world_size_cm=[10, 10]) as f: + with robofish.io.File(world_size_cm=[10, 10], world_shape="rectangle") as f: pass def test_new_file_w_path(tmp_path): f = tmp_path / "file.hdf5" - sf = robofish.io.File(f, "w", world_size_cm=[100, 100], frequency_hz=25) + sf = robofish.io.File( + f, "w", world_size_cm=[100, 100], frequency_hz=25, world_shape="rectangle" + ) sf.create_entity("fish") sf.validate() sf.close() def test_missing_attribute(): - sf = robofish.io.File(world_size_cm=[10, 10]) + sf = robofish.io.File(world_size_cm=[10, 10], world_shape="rectangle") sf.attrs.pop("world_size_cm") assert not sf.validate(strict_validate=False)[0] sf.close() def test_single_entity_frequency_hz(): - sf = robofish.io.File(world_size_cm=[100, 100], frequency_hz=(1000 / 40)) + sf = robofish.io.File( + world_size_cm=[100, 100], frequency_hz=(1000 / 40), world_shape="rectangle" + ) test_poses = np.ones(shape=(10, 4)) test_poses[:, 3] = 0 # All Fish pointing right sf.create_entity("robofish", poses=test_poses) @@ -54,7 +58,9 @@ def test_single_entity_frequency_hz(): def test_single_entity_monotonic_time_points_us(): with pytest.warns(Warning): sf = robofish.io.File( - world_size_cm=[100, 100], monotonic_time_points_us=np.ones(10) + world_size_cm=[100, 100], + monotonic_time_points_us=np.ones(10), + world_shape="rectangle", ) test_poses = np.ones(shape=(10, 4)) test_poses[:, 3] = 0 # All Fish pointing right @@ -76,7 +82,9 @@ def test_multiple_entities(): with pytest.warns(Warning): sf = robofish.io.File( - world_size_cm=[100, 100], monotonic_time_points_us=m_points + world_size_cm=[100, 100], + monotonic_time_points_us=m_points, + world_shape="rectangle", ) returned_entities = sf.create_multiple_entities("fish", poses) returned_names = [entity.name for entity in returned_entities] @@ -146,7 +154,9 @@ def test_multiple_entities(): def test_actions_speeds_turns_angles(): - with robofish.io.File(world_size_cm=[100, 100], frequency_hz=25) as f: + with robofish.io.File( + world_size_cm=[100, 100], frequency_hz=25, world_shape="rectangle" + ) as f: poses = np.zeros((10, 100, 3)) f.create_multiple_entities("fish", poses=poses) @@ -155,7 +165,9 @@ def test_actions_speeds_turns_angles(): def test_entity_poses_rad(caplog): - with robofish.io.File(world_size_cm=[100, 100], frequency_hz=25) as f: + with robofish.io.File( + world_size_cm=[100, 100], frequency_hz=25, world_shape="rectangle" + ) as f: # Create an entity, using radians f.create_entity("fish", poses=np.ones((100, 3))) @@ -169,7 +181,9 @@ def test_entity_poses_rad(caplog): def test_entity_positions_no_orientation(): - with robofish.io.File(world_size_cm=[100, 100], frequency_hz=25) as f: + with robofish.io.File( + world_size_cm=[100, 100], frequency_hz=25, world_shape="rectangle" + ) as f: # Create an entity, using radians f.create_entity("fish", positions=np.ones((100, 2)))