Skip to content
Snippets Groups Projects
Commit 3c0d61be authored by Andi Gerken's avatar Andi Gerken
Browse files

Added possibility to create files with path

parent a07a5180
No related branches found
No related tags found
No related merge requests found
Pipeline #35126 failed
...@@ -30,6 +30,19 @@ def evaluate(args=None): ...@@ -30,6 +30,19 @@ def evaluate(args=None):
nargs="+", nargs="+",
help="The paths to io/hdf5 files. Multiple paths can be given which will be shown in different colors", help="The paths to io/hdf5 files. Multiple paths can be given which will be shown in different colors",
) )
parser.add_argument(
"--names",
type=str,
nargs="+",
help="Names, that should be used in the graphs instead of the pahts",
default=None,
)
parser.add_argument(
"--save_folder",
type=str,
help="Output folder for saving resulting graphics",
default=None,
)
if args is None: if args is None:
args = parser.parse_args() args = parser.parse_args()
......
...@@ -71,7 +71,8 @@ class File(h5py.File): ...@@ -71,7 +71,8 @@ class File(h5py.File):
self._tf_path = Path(temp_dir.name) / self._name self._tf_path = Path(temp_dir.name) / self._name
self.load(path, strict_validate) self.load(path, strict_validate)
if path is None: if path is None or not Path(path).exists():
# Initialize new file # Initialize new file
assert world_size_cm is not None and format_version is not None assert world_size_cm is not None and format_version is not None
...@@ -99,9 +100,11 @@ class File(h5py.File): ...@@ -99,9 +100,11 @@ class File(h5py.File):
path: path to a io file as a string or path object path: path to a io file as a string or path object
strict_validate: optional boolean, if the file should be strictly validated, when loaded from a path. The default is False. strict_validate: optional boolean, if the file should be strictly validated, when loaded from a path. The default is False.
""" """
if path is not None:
self._f_path = Path(path)
if path is not None and Path(path).exists(): if path is not None and Path(path).exists():
logging.info(f"Opening File {path}") logging.info(f"Opening File {path}")
self._f_path = Path(path)
shutil.copyfile(self._f_path, self._tf_path) shutil.copyfile(self._f_path, self._tf_path)
super().__init__(self._tf_path, "r+") super().__init__(self._tf_path, "r+")
self.validate(strict_validate) self.validate(strict_validate)
...@@ -149,7 +152,6 @@ class File(h5py.File): ...@@ -149,7 +152,6 @@ class File(h5py.File):
calendar_time_points: Iterable = None, calendar_time_points: Iterable = None,
default: bool = False, default: bool = False,
): ):
print(frequency_hz, monotonic_time_points_us)
if frequency_hz is not None and monotonic_time_points_us is not None: if frequency_hz is not None and monotonic_time_points_us is not None:
logging.exception("Specify either frequency_hz or timestamps, not both.") logging.exception("Specify either frequency_hz or timestamps, not both.")
......
...@@ -15,6 +15,7 @@ def full_path(path): ...@@ -15,6 +15,7 @@ def full_path(path):
valid_file_path = full_path("../../resources/valid.hdf5") valid_file_path = full_path("../../resources/valid.hdf5")
created_by_test_path = full_path("../../resources/created_by_test.hdf5") created_by_test_path = full_path("../../resources/created_by_test.hdf5")
created_by_test_path_2 = full_path("../../resources/created_by_test_2.hdf5")
def test_constructor(): def test_constructor():
...@@ -23,6 +24,15 @@ def test_constructor(): ...@@ -23,6 +24,15 @@ def test_constructor():
sf.validate() sf.validate()
def test_new_file_w_path():
sf = robofish.io.File(
created_by_test_path_2, world_size_cm=[100, 100], frequency_hz=25
)
sf.create_entity("fish")
sf.save()
sf.validate()
def test_missing_attribute(): def test_missing_attribute():
sf = robofish.io.File(world_size_cm=[10, 10]) sf = robofish.io.File(world_size_cm=[10, 10])
sf.attrs.pop("world_size_cm") sf.attrs.pop("world_size_cm")
...@@ -164,6 +174,7 @@ def test_validate_created_file_after_reloading(): ...@@ -164,6 +174,7 @@ def test_validate_created_file_after_reloading():
def test_z_cleanup(): def test_z_cleanup():
""" This cleans up after all tests and removes all test artifacts """ """ This cleans up after all tests and removes all test artifacts """
created_by_test_path.unlink() created_by_test_path.unlink()
created_by_test_path_2.unlink()
if __name__ == "__main__": if __name__ == "__main__":
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment