export_traces.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import view
  2. import pandas as pd
  3. import logging
  4. import pathlib as pl
  5. # this tells view all settings including the folder structure of your project
  6. # On Windows, if you copy paths from the file explorer, make sure the string below is always of the form r"......"
  7. # ymlfile = r"/Volumes/AG_Galizia/AjayramaKumaraswamy/Ana_RNPN_SampleSet/usage_till.yml"
  8. ymlfile = r"/home/aj/UKN_network_drives/ag_galizia/AjayramaKumaraswamy/Ana_RNPN_SampleSet/usage_till.yml"
  9. # any manual changes to flags, add to dictionary as required
  10. flags_to_update = {
  11. "RM_ROITrace": 0, # MUST: look up the documentation of this flag
  12. # Other flag changes can be included, for example:
  13. # CTV_scalebar: True,
  14. # mv_individualScale: 2,
  15. # .....
  16. }
  17. # list of animals for which traces are to be exported
  18. animals = [
  19. "A_5803a"
  20. ]
  21. if __name__ == '__main__':
  22. # create a view object
  23. view_obj = view.VIEW()
  24. # load flags from yml file
  25. view_obj.update_flags_from_ymlfile(ymlfile)
  26. # update flags specified locally
  27. view_obj.update_flags(flags_to_update)
  28. # iterate over animals
  29. for animal in animals:
  30. # initialize view object with animal
  31. view_obj.initialize_animal(animal=animal)
  32. # initialize and empty data frame to accumulate data
  33. gdm_df = pd.DataFrame()
  34. # iterate over measurements of the animal
  35. for measu in view_obj.get_measus_for_current_animal(analyze_values_to_use=(1,)):
  36. # load a measurement for the animal
  37. view_obj.load_measurement_data_from_current_animal(measu)
  38. # create glodatamix for the loaded measurement
  39. gdm_df_this_measu = view_obj.get_glodatamix_for_current_animal()
  40. # accumulate
  41. gdm_df = gdm_df.append(gdm_df_this_measu, ignore_index=True, sort=False)
  42. # compose output file name
  43. output_file = view_obj.flags.get_gloDatamix_file_for_current_animal()
  44. pl.Path(output_file).parent.mkdir(exist_ok=True)
  45. # save gloDatamix file
  46. gdm_df.to_csv(output_file, sep=';', header=True, index=False)
  47. logging.info(f"Wrote gloDatamix to {output_file}")
  48. # backup this script and the yml file used next to the created GDMs
  49. view_obj.backup_script_flags_configs_for_GDMs(files=[__file__, ymlfile])