Master_Inga_190821.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Wed May 30 10:13:47 2018
  4. @author: Giovanni Galizia
  5. copy of master
  6. in C:\\Users\\Giovanni Galizia\\Documents\\Code\\ShareWinXP\\WindowsExchange\\IDL_Data\\spont_activity\\00_copy_IDL
  7. changed May 2019
  8. to run Hanna Apis2018 as sample data
  9. on mac gio: run in environment idl_py
  10. """
  11. ### gio 25.5.2019: "from view.idl_translation_core import View_gr_reports " does not work,
  12. # direct import does: import View_gr_reports as...
  13. # in spyder, anaconca env idl_py, mac.
  14. #from view.idl_translation_core import View_gr_reports as View_gr_reports, IDL_flags as IDL_flags
  15. import View_gr_reports as View_gr_reports, IDL_flags as IDL_flags
  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. flag.LE_loadExp = 4
  26. flag.CSM_Movement = 0 # 2 for movement correction on the spot - is slow!
  27. flag.VIEW_batchmode = 1 # fo
  28. flag.LE_CalcMethod = 4900
  29. flag.VIEW_ReportMethod = 10 #10 for overviews, 11 for Glodatamix, 12 for movies
  30. flag.SO_Method = 10
  31. flag.SO_individualScale= 3
  32. flag.SO_MV_scalemax = 18.0
  33. flag.SO_MV_scalemin = -2.0
  34. flag.SO_withinArea= 0
  35. flag.CTV_firstframe = 18
  36. flag.CTV_lastframe = 30
  37. flag.CTV_Method = 22 #22
  38. flag.RM_FotoOk = 0
  39. flag.RM_NextPosition = (0,0)
  40. flag.CTV_scalebar = 0
  41. flag.Signal_FilterSpaceFlag = 1
  42. flag.Signal_FilterSpaceSize = 5
  43. flag.mv_individualScale = 3
  44. flag.RM_Radius = 5
  45. flag.SO_MV_colortable = 11
  46. return flag
  47. def ChooseFileFolder():
  48. import tkinter as tk
  49. from tkinter.filedialog import askopenfilenames
  50. # Choose raw files
  51. root = tk.Tk()
  52. root.withdraw() # so that windows closes after file chosen
  53. root.attributes('-topmost', True)
  54. # the mac system does not accept filetypes, therefore ask for system
  55. if platform == 'darwin':
  56. filenames = askopenfilenames(
  57. parent=root,
  58. title='Select one or more settings files (*.settings.xls)',
  59. ) # ask user to choose file
  60. else:
  61. filenames = askopenfilenames(
  62. parent=root,
  63. title='Select one or more settings files',
  64. filetypes=[('settings files', '*.settings.xls'), ('all files', '*')]
  65. ) # ask user to choose file
  66. return filenames
  67. def Inga_2019_Fura_test(flag):
  68. #list all animals to be processed
  69. flag.SO_MV_scalemax =3.000
  70. flag.SO_MV_scalemin = -2.000
  71. #list animals to work with here
  72. animallist = ['190607_locust_ip32', '190702_locust_ip33']
  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. (p1, flag) = View_gr_reports.gr_takefromlist(flag.STG_ReportTag, 1, flag, selectformat ='analyze')
  81. return p1, flag
  82. # end of Inga_2019_Fura_test
  83. def gr_190227_locust_ip14(flag):
  84. #single animal selection of order how measurements are evaluated
  85. flag.RM_NewColumn = 1
  86. ### IDL commant is this
  87. # subloop, '14'; 12_AIR
  88. ### converts into Python like this
  89. (p1,flag) = View_gr_reports.gr_takefromlist(flag.STG_ReportTag, 1, flag, selectformat ='subloop')
  90. flag.RM_NewColumn = 0
  91. (p1,flag) = View_gr_reports.gr_takefromlist(flag.STG_ReportTag, 3, flag, selectformat ='subloop') # 01_LINT-4
  92. (p1,flag) = View_gr_reports.gr_takefromlist(flag.STG_ReportTag, 5, flag, selectformat ='subloop') # 02_LINT-3
  93. (p1,flag) = View_gr_reports.gr_takefromlist(flag.STG_ReportTag, 7, flag, selectformat ='subloop') # 14_LINT-4
  94. (p1,flag) = View_gr_reports.gr_takefromlist(flag.STG_ReportTag, 9, flag, selectformat ='subloop') # 00_MOL
  95. (p1,flag) = View_gr_reports.gr_takefromlist(flag.STG_ReportTag, 11, flag, selectformat ='subloop') # 13_MOL
  96. (p1,flag) = View_gr_reports.gr_takefromlist(flag.STG_ReportTag, 13, flag, selectformat ='subloop') # 15_NONL-3
  97. return p1, flag
  98. def gr_190227_locust_ip16(flag):
  99. #single animal selection of order how measurements are evaluated
  100. flag.RM_NewColumn = 1
  101. ### IDL commant is this
  102. # subloop, '14'; 12_AIR
  103. ### converts into Python like this
  104. (p1,flag) = View_gr_reports.gr_takefromlist(flag.STG_ReportTag, 1, flag, selectformat ='subloop')
  105. flag.RM_NewColumn = 0
  106. (p1,flag) = View_gr_reports.gr_takefromlist(flag.STG_ReportTag, 3, flag, selectformat ='subloop') # 01_LINT-4
  107. (p1,flag) = View_gr_reports.gr_takefromlist(flag.STG_ReportTag, 5, flag, selectformat ='subloop') # 02_LINT-3
  108. (p1,flag) = View_gr_reports.gr_takefromlist(flag.STG_ReportTag, 7, flag, selectformat ='subloop') # 14_LINT-4
  109. (p1,flag) = View_gr_reports.gr_takefromlist(flag.STG_ReportTag, 9, flag, selectformat ='subloop') # 00_MOL
  110. (p1,flag) = View_gr_reports.gr_takefromlist(flag.STG_ReportTag, 11, flag, selectformat ='subloop') # 13_MOL
  111. (p1,flag) = View_gr_reports.gr_takefromlist(flag.STG_ReportTag, 13, flag, selectformat ='subloop') # 15_NONL-3
  112. return p1, flag
  113. #########################################################
  114. ########## Main starts here
  115. #########################################################
  116. # define flags
  117. #IDL.flags.IDL_default_flags sets the general rules
  118. #Set_my_flags modifies these
  119. #on my windows system
  120. #STG_MotherOfAllFolders = 'C:\\Users\\Giovanni Galizia\\Documents\\Code\\ShareWinXP\\WindowsExchange\\IDL_Data\\spont_activity' #if empty, working directory is used
  121. #if platform == 'darwin':
  122. # STG_MotherOfAllFolders = '/Users/galizia/Documents/Code/ShareWinXP/WindowsExchange/IDL_Data/spont_activity'
  123. print()
  124. print('Running this master file: ', __file__)
  125. print()
  126. # Inga data on my mac
  127. STG_MotherOfAllFolders = '/Users/galizia/Documents/KN_Group/19_Inga/Inga_locust_best_SampleTree'
  128. flag = Set_my_flags(IDL_flags.IDL_default_flags(STG_MotherOfAllFolders))
  129. #flag.STG_OdorReportPath = os.path.join(STG_MotherOfAllFolders + 'IDL_output\\movies\\'
  130. # call program that opens .lst file and performs analysis
  131. # the command in spont_activity_master.pro was "subloop, '24'
  132. #(p1,flag) = View_gr_reports.gr_takefromlist('030725bR', 3, flag)
  133. ####make sure all settings/flags are set, then call this animal
  134. (p1,flag) = Inga_2019_Fura_test(flag)
  135. #document how this analysis was done, by copying this file into the output folder
  136. shutil.copy(__file__, flag.STG_OdorReportPath)
  137. #TODO also copy the .yml file if that contains flag settings