Master_Fake_190822.py 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. # -*- coding: utf-8 -*-
  2. """
  3. @author: Giovanni Galizia
  4. """
  5. ### gio 25.5.2019: "from view.idl_translation_core import View_gr_reports " does not work,
  6. # direct import does: import View_gr_reports as...
  7. # in spyder, anaconca env idl_py, mac.
  8. # next line works in Spyder IF it has been called in the right directory.
  9. from view.idl_translation_core import View_gr_reports as View_gr_reports, IDL_flags as IDL_flags
  10. #import View_gr_reports as View_gr_reports, IDL_flags as IDL_flags
  11. from view.python_core.flags import FlagsManager
  12. #import View_gr_reports as View_gr_reports, IDL_flags as IDL_flags
  13. import pathlib as pl
  14. #import pandas as pd
  15. import os
  16. from sys import platform
  17. #show images inline:
  18. #%matplotlib inline
  19. #show images in extra window
  20. #%matplotlib qt
  21. import shutil
  22. def Set_my_flags(flag):
  23. # use this to change any flags that are important locally
  24. #flag.STG_reporttag = '030725bR'
  25. #chage to indexing in the future, e.g.
  26. #flag["LE_loadExp"] = 666
  27. flag.LE_loadExp = 666
  28. flag.CSM_Movement = 0 # 2 for movement correction on the spot - is slow!
  29. flag.VIEW_batchmode = 1 # fo
  30. flag.LE_CalcMethod = 3900 # calculates raw data
  31. flag.VIEW_ReportMethod = 12 #10 for overviews, 11 for Glodatamix, 12 for movies
  32. flag.SO_Method = 10
  33. flag.SO_indiScale = 0
  34. flag.SO_MV_scalemax = 0.30#18.0
  35. flag.SO_MV_scalemin = -0.08#-2.0
  36. flag.SO_withinmask= 0
  37. flag.CTV_firstframe = 20
  38. flag.CTV_lastframe = 30
  39. flag.CTV_Method = 22 #22 , 12 takes average from firstframe to lastframe
  40. flag.RM_FotoOk = 0
  41. flag.RM_NextPosition = (0,0)
  42. flag.CTV_scalebar = 0
  43. flag.Signal_FilterSpaceFlag = 0
  44. flag.mv_individualScale = 2
  45. flag.FT_radius = 5
  46. flag.SO_MV_colortable = 12
  47. return flag
  48. def ChooseFileFolder():
  49. import tkinter as tk
  50. from tkinter.filedialog import askopenfilenames
  51. # Choose raw files
  52. root = tk.Tk()
  53. root.withdraw() # so that windows closes after file chosen
  54. root.attributes('-topmost', True)
  55. # the mac system does not accept filetypes, therefore ask for system
  56. if platform == 'darwin':
  57. filenames = askopenfilenames(
  58. parent=root,
  59. title='Select one or more settings files (*.settings.xls)',
  60. ) # ask user to choose file
  61. else:
  62. filenames = askopenfilenames(
  63. parent=root,
  64. title='Select one or more settings files',
  65. filetypes=[('settings files', '*.settings.xls'), ('all files', '*')]
  66. ) # ask user to choose file
  67. return filenames
  68. def RunThroughAnimals(flag, animallist):
  69. #list all animals to be processed
  70. #list animals to work with here
  71. # animallist = ['190607_locust_ip32', '190702_locust_ip33']
  72. # animal='pixel_calibration'
  73. for i,animal in enumerate(animallist):
  74. print(i, animal)
  75. flag.STG_ReportTag =animal
  76. # run gr_190227_locust_ip14 to select also the order of how measurements are evaluated
  77. #(p1, flag) = gr_190227_locust_ip14(flag)
  78. # run gr_takefromlist to use the 'analyze' column
  79. #list what to do with each animal here
  80. print('in Master/RunThroughAnimals: now running animal: ', animal)
  81. (p1, flag) = View_gr_reports.gr_takefromlist(flag.STG_ReportTag, 1, flag, selectformat ='analyze')
  82. return p1, flag
  83. # end of Inga_2019_Fura_test
  84. def gr_190227_locust_ip14(flag):
  85. #single animal selection of order how measurements are evaluated
  86. flag.RM_NewColumn = 1
  87. ### IDL commant is this
  88. # subloop, '14'; 12_AIR
  89. ### converts into Python like this
  90. (p1,flag) = View_gr_reports.gr_takefromlist(flag.STG_ReportTag, 1, flag, selectformat ='subloop')
  91. flag.RM_NewColumn = 0
  92. (p1,flag) = View_gr_reports.gr_takefromlist(flag.STG_ReportTag, 3, flag, selectformat ='subloop') # 01_LINT-4
  93. (p1,flag) = View_gr_reports.gr_takefromlist(flag.STG_ReportTag, 5, flag, selectformat ='subloop') # 02_LINT-3
  94. (p1,flag) = View_gr_reports.gr_takefromlist(flag.STG_ReportTag, 7, flag, selectformat ='subloop') # 14_LINT-4
  95. (p1,flag) = View_gr_reports.gr_takefromlist(flag.STG_ReportTag, 9, flag, selectformat ='subloop') # 00_MOL
  96. (p1,flag) = View_gr_reports.gr_takefromlist(flag.STG_ReportTag, 11, flag, selectformat ='subloop') # 13_MOL
  97. (p1,flag) = View_gr_reports.gr_takefromlist(flag.STG_ReportTag, 13, flag, selectformat ='subloop') # 15_NONL-3
  98. return p1, flag
  99. def gr_190227_locust_ip16(flag):
  100. #single animal selection of order how measurements are evaluated
  101. flag.RM_NewColumn = 1
  102. ### IDL commant is this
  103. # subloop, '14'; 12_AIR
  104. ### converts into Python like this
  105. (p1,flag) = View_gr_reports.gr_takefromlist(flag.STG_ReportTag, 1, flag, selectformat ='subloop')
  106. flag.RM_NewColumn = 0
  107. (p1,flag) = View_gr_reports.gr_takefromlist(flag.STG_ReportTag, 3, flag, selectformat ='subloop') # 01_LINT-4
  108. (p1,flag) = View_gr_reports.gr_takefromlist(flag.STG_ReportTag, 5, flag, selectformat ='subloop') # 02_LINT-3
  109. (p1,flag) = View_gr_reports.gr_takefromlist(flag.STG_ReportTag, 7, flag, selectformat ='subloop') # 14_LINT-4
  110. (p1,flag) = View_gr_reports.gr_takefromlist(flag.STG_ReportTag, 9, flag, selectformat ='subloop') # 00_MOL
  111. (p1,flag) = View_gr_reports.gr_takefromlist(flag.STG_ReportTag, 11, flag, selectformat ='subloop') # 13_MOL
  112. (p1,flag) = View_gr_reports.gr_takefromlist(flag.STG_ReportTag, 13, flag, selectformat ='subloop') # 15_NONL-3
  113. return p1, flag
  114. #########################################################
  115. ########## Main starts here
  116. #########################################################
  117. # define flags
  118. #IDL.flags.IDL_default_flags sets the general rules
  119. #Set_my_flags modifies these
  120. #on my windows system
  121. #STG_MotherOfAllFolders = 'C:\\Users\\Giovanni Galizia\\Documents\\Code\\ShareWinXP\\WindowsExchange\\IDL_Data\\spont_activity' #if empty, working directory is used
  122. #if platform == 'darwin':
  123. # STG_MotherOfAllFolders = '/Users/galizia/Documents/Code/ShareWinXP/WindowsExchange/IDL_Data/spont_activity'
  124. print()
  125. print('Running this master file: ', __file__)
  126. print()
  127. flags_from_yml = True
  128. if flags_from_yml:
  129. #default are settings in yml file, ising same procedure as VIEWgui
  130. #modified by Set_my_flags above
  131. # yml_filename = '/Users/galizia/Documents/Code/VIEWsampletrees/FakeData/view_fake_data.yml'
  132. # yml_filename = 'E:\\FakeData\\view_fake_data.yml'
  133. yml_filename = '/home/aj/SharedWithWindows/FakeData/view_fake_data.yml'
  134. flags = FlagsManager()
  135. flags.read_flags_from_yml(yml_filename)
  136. # convert flags to pd.Series because that is what Set_my_flags is expecting.
  137. # this will be obsolete when Set_my_flags will use indexing instead of attribure
  138. flag_series = Set_my_flags(flags.to_series())
  139. # or take flags exactly as in .yml file
  140. # flag = pd.Series(pc_flags.read_yml_flags(yml_filename))
  141. else: #alternative: defaults are in IDL_falgs.IDL_default_flags
  142. # STG_MotherOfAllFolders = '/Users/galizia/Documents/Code/VIEWsampletrees/FakeData'
  143. # STG_MotherOfAllFolders = 'E:\\FakeData'
  144. STG_MotherOfAllFolders = '/home/aj/SharedWithWindows/FakeData'
  145. flag_series = Set_my_flags(IDL_flags.IDL_default_flags(STG_MotherOfAllFolders))
  146. #flag.STG_OdorReportPath = os.path.join(STG_MotherOfAllFolders + 'IDL_output\\movies\\'
  147. # call program that opens .lst file and performs analysis
  148. # the command in spont_activity_master.pro was "subloop, '24'
  149. #(p1,flag) = View_gr_reports.gr_takefromlist('030725bR', 3, flag)
  150. ####make sure all settings/flags are set, then call this animal
  151. RunThroughAnimals(flag_series,
  152. ['FakeData'])
  153. #document how this analysis was done, by copying this file into the output folder
  154. shutil.copy(__file__, flag_series.STG_OdorReportPath)
  155. if flags_from_yml:
  156. # initialize the path of the current script into a pathlib.Path object
  157. current_file_path = pl.Path(__file__)
  158. # use the stem of the path of the current string to form yml file name in STG_OdorReportPath
  159. yml_outfilename_path = pl.Path(flags["STG_OdorReportPath"]) / f"{current_file_path.stem}.yml"
  160. yml_outfilename = str(yml_outfilename_path)
  161. flags.write_flags_to_yml(yml_outfilename)