common.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import pathlib as pl
  2. from view.gui.application_settings import get_view_qsettings_manager
  3. def get_example_data_root_path():
  4. settings = get_view_qsettings_manager()
  5. if settings.contains("view_test_data_path"):
  6. existing_test_data_path_str = settings.value("view_test_data_path")
  7. existing_test_data_path = pl.Path(existing_test_data_path_str)
  8. if existing_test_data_path.is_dir():
  9. return existing_test_data_path
  10. else:
  11. raise FileNotFoundError(
  12. f"Could not find the following folder, to which VIEW is configured for storing test data."
  13. f"\n\n{existing_test_data_path_str}.\n\nPlease run the script 'setup_testing.py' in the root "
  14. f"directory of VIEW source code again to download view test data and configure view test path")
  15. else:
  16. raise ValueError(
  17. "pyVIEW needs some data for testing. Please run the script 'setup_testing.py' in the root "
  18. "directory of VIEW source code again to download view test data and configure view test path")
  19. def get_example_dataset_roots():
  20. example_data_root = get_example_data_root_path()
  21. dataset_roots = []
  22. for child in example_data_root.iterdir():
  23. if child.is_dir() and any(x.name.lower().find("list") > 0 or x.name.lower().find("settings") > 0
  24. for x in child.iterdir()):
  25. dataset_roots.append(child)
  26. return dataset_roots
  27. def initialize_test_yml_list_measurement(tiny_dataset=False):
  28. example_data_path = get_example_data_root_path()
  29. if tiny_dataset:
  30. example_dataset_moaf = example_data_path / "FakeData_tiny"
  31. else:
  32. example_dataset_moaf = example_data_path / "FakeData"
  33. test_yml = example_dataset_moaf / "test_defaults.yml"
  34. test_animal = "FakeData"
  35. test_measu = 8
  36. return str(test_yml), test_animal, test_measu