export_traces_synthetic.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import view
  2. import logging
  3. import pathlib as pl
  4. # this tells view all settings including the folder structure of your project
  5. # On Windows, if you copy paths from the file explorer, make sure the string below is always of the form r"......"
  6. from view.python_core.gdm_generation.gdm_data_classes import GDMFile
  7. #mother of all folders
  8. moaf = pl.Path(__file__).parents[1]
  9. # this tells view all settings including the folder structure of your project
  10. # On Windows, if you copy paths from the file explorer, make sure the string below is always of the form r"......"
  11. ymlfile = moaf / r"view_synthetic_666.yml"
  12. # any manual changes to flags, add to dictionary as required
  13. flags_to_update = {
  14. "RM_ROITrace": 3, # set to 0 for .coor files, 3 for .roi files and 4 for .roi.tif
  15. # Other flag changes can be included, for example:
  16. # CTV_scalebar: True,
  17. # mv_individualScale: 2,
  18. # .....
  19. }
  20. # list of animals for which traces are to be exported
  21. animals = [
  22. "Synthetic_data_strip"#,
  23. #""
  24. ]
  25. Analyze_column_values_to_use = (-1,1)
  26. if __name__ == '__main__':
  27. # create a view object
  28. view_obj = view.VIEW()
  29. # load flags from yml file
  30. view_obj.update_flags_from_ymlfile(ymlfile)
  31. # update flags specified locally
  32. view_obj.update_flags(flags_to_update)
  33. # iterate over animals
  34. for animal in animals:
  35. # initialize view object with animal
  36. view_obj.initialize_animal(animal=animal)
  37. # get ROI information for this animal
  38. roi_data_dict, roi_file = view_obj.get_roi_info_for_current_animal()
  39. # initialize and empty data frame to accumulate data
  40. gdm_file = GDMFile()
  41. # iterate over measurements of the animal
  42. for measu in view_obj.get_measus_for_current_animal(analyze_values_to_use=Analyze_column_values_to_use):
  43. # load a measurement for the animal
  44. view_obj.load_measurement_data_from_current_animal(measu)
  45. # calculate signals
  46. view_obj.calculate_signals()
  47. # create glodatamix for the loaded measurement
  48. gdm_file_this_measu, _ = view_obj.get_gdm_file_for_current_measurement(roi_data_dict)
  49. # accumulate
  50. gdm_file.append_from_a_gdm_file(gdm_file_this_measu)
  51. # compose output file name and create parent directory if needed
  52. output_file = view_obj.flags.get_gloDatamix_file_for_current_animal()
  53. pl.Path(output_file).parent.mkdir(exist_ok=True)
  54. # save gloDatamix file
  55. gdm_file.write_to_csv(output_file)
  56. logging.getLogger("VIEW").info(f"Wrote gloDatamix to {output_file}")
  57. # backup this script and the yml file used next to the created GDMs
  58. view_obj.backup_script_flags_configs_for_GDMs(files=[__file__, ymlfile])