constructRegMaxSNParFile.py 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. # Ajayrama Kumaraswamy, 2017, LMU Munich
  2. """
  3. Description: This script is used to generate a parameter file required to run RegMaxSN.py. This parameter file
  4. should contain a json string of a list of dictionaries. Each dictionary is one Reg-MaxS-N job
  5. that contains Reg-MaxS-N parameters.
  6. See core/RegMaxSPars.py for the description of the parameters.
  7. Usage: python constructRegMaxSNParFile.py
  8. Action: creates a parameter file for RegMaxSN.py
  9. Usage guidelines: There are a couple of cases with examples shown below.
  10. Read the comments therein.
  11. Essentially edit the values of some variables in this script and run it.
  12. """
  13. from numpy import pi, deg2rad
  14. import os
  15. import json
  16. from regmaxsn.core.RegMaxSPars import RegMaxSNParNames
  17. temp = os.path.split(os.path.abspath(__file__))[0]
  18. temp1 = os.path.split(temp)[0]
  19. # **********************************************************************************************************************
  20. # Default parameters
  21. # distances in um, angles in radians
  22. gridSizes = [40.0, 20.0, 10.0]
  23. transBounds = [[-30, 30], [-30, 30], [-30, 30]]
  24. transMinRes = 1
  25. rotBounds = [[-pi / 6, pi / 6], [-pi / 6, pi / 6], [-pi / 6, pi / 6]]
  26. rotMinRes = deg2rad(1).round(4)
  27. scaleBounds = [[0.5, 1 / 0.5], [0.5, 1 / 0.5], [0.5, 1 / 0.5]]
  28. minScaleStepSize = 1.005
  29. usePartsDir = True
  30. nCPU = 6
  31. maxIter = 100
  32. # **********************************************************************************************************************
  33. # # User defined parameters. Change these if required
  34. # # distances in um, angles in radians
  35. # gridSizes = [40.0, 20.0, 10.0]
  36. # transBounds = [[-30, 30], [-30, 30], [-30, 30]]
  37. # transMinRes = 1
  38. # rotBounds = [[-pi / 6, pi / 6], [-pi / 6, pi / 6], [-pi / 6, pi / 6]]
  39. # rotMinRes = deg2rad(1).round(4)
  40. # scaleBounds = [[0.5, 1 / 0.5], [0.5, 1 / 0.5], [0.5, 1 / 0.5]]
  41. # minScaleStepSize = 1.005
  42. # nCPU = 6
  43. # maxIter = 100
  44. # **********************************************************************************************************************
  45. # Case 1: Using Default or user defined parameters above and
  46. # swcList: contains the list of SWCs to register together. This is formed using the list expNames and the directory
  47. # swcDir
  48. # initRefSWC: the initial reference SWC. May or may not be one among swcList
  49. # resDir: directory in which the results are to be created when RegMaxSN.py is run with the parameter file generated by
  50. # this script.
  51. # parFile: the parameter file will be generated at this file path by running this script.
  52. # finallyNormalizeWRT: all SWCs are affinely tranformed together by RegMaxSN.py after completing the registration
  53. # so that this SWC is brought back to its original form.
  54. # Usage: Replace initRefSWC, swcDir, expNames, resDir, parFile, finallyNormalizeWRT as required and
  55. # run this file to generate parFile
  56. # Then run python <...>/RegMaxSN.py parFile
  57. # -----------------------------------------------------------------------------------
  58. # # Example 1
  59. # initRefSWC = os.path.join(temp1, 'TestFiles', 'HSNL', 'HSN-fluoro02.CNG.swc')
  60. # swcDir = os.path.join(temp1, 'TestFiles', 'HSNL')
  61. # expNames = [
  62. # 'HSN-fluoro02.CNG',
  63. # 'HSN-fluoro03.CNG',
  64. # 'HSN-fluoro06.CNG',
  65. # 'HSN-fluoro08.CNG',
  66. # 'HSN-fluoro10.CNG',
  67. # ]
  68. # swcList = [os.path.join(swcDir, expName + '.swc') for expName in expNames]
  69. # resDir = os.path.join(temp1, 'Results', 'Reg-MaxS-N', 'HSNL')
  70. # parFile = os.path.join(temp1, 'ParFiles', 'Reg-MaxS-N', 'HSNL.json')
  71. # finallyNormalizeWRT = initRefSWC
  72. #
  73. # obtains the list of variables in the current work space
  74. # ns = vars()
  75. # forms the dictionary of parameters to be saved into the parameter file.
  76. # pars = [{k: ns[k] for k in RegMaxSNParNames}]
  77. # -----------------------------------------------------------------------------------
  78. # Example 2
  79. initRefSWC = os.path.join(temp1, 'TestFiles', 'LLC', 'Gad1-F-000062.CNG.swc')
  80. swcDir = os.path.join(temp1, 'TestFiles', 'LLC')
  81. expNames = [
  82. 'Gad1-F-000062.CNG',
  83. 'Cha-F-000012.CNG',
  84. 'Cha-F-300331.CNG',
  85. 'Gad1-F-600000.CNG',
  86. 'Cha-F-000018.CNG',
  87. 'Cha-F-300051.CNG',
  88. 'Cha-F-400051.CNG',
  89. 'Cha-F-200000.CNG'
  90. ]
  91. swcList = [os.path.join(swcDir, expName + '.swc') for expName in expNames]
  92. resDir = os.path.join(temp1, 'Results', 'Reg-MaxS-N', 'LLC')
  93. parFile = os.path.join(temp1, 'ParFiles', 'Reg-MaxS-N', 'LLC.json')
  94. finallyNormalizeWRT = initRefSWC
  95. # obtains the list of variables in the current work space
  96. ns = vars()
  97. # forms the dictionary of parameters to be saved into the parameter file.
  98. pars = [{k: ns[k] for k in RegMaxSNParNames}]
  99. # -----------------------------------------------------------------------------------
  100. # **********************************************************************************************************************
  101. # # Case 2: Using Default or user defined parameters above, and other parameters below.
  102. # Parameters are same as in Case 1 above, but multiple jobs can be specified in this case.
  103. # Usage: Replace initRefSWC, swcDir, expNames, resDir, parFile, finallyNormalizeWRT as required for each job and
  104. # run this file to generate parFile
  105. # Then run python <...>/RegMaxSN.py parFile
  106. #
  107. # pars = []
  108. # parFile = os.path.join(temp1, 'ParFiles', 'Reg-MaxS-N', 'HSNL-HSNR.json')
  109. # # -----------------------------------------------------------------------------------
  110. # # job 1
  111. # # -----------------------------------------------------------------------------------
  112. # initRefSWC = os.path.join(temp1, 'TestFiles', 'HSNL', 'HSN-fluoro02.CNG.swc')
  113. # swcDir = os.path.join(temp1, 'TestFiles', 'HSNL')
  114. # expNames = [
  115. # 'HSN-fluoro02.CNG',
  116. # 'HSN-fluoro03.CNG',
  117. # 'HSN-fluoro06.CNG',
  118. # 'HSN-fluoro08.CNG',
  119. # 'HSN-fluoro10.CNG',
  120. # ]
  121. # swcList = [os.path.join(swcDir, expName + '.swc') for expName in expNames]
  122. # resDir = os.path.join(temp1, 'Results', 'Reg-MaxS-N', 'HSNL')
  123. # finallyNormalizeWRT = initRefSWC
  124. #
  125. # obtains the list of variables in the current work space
  126. # ns = vars()
  127. # forms the dictionary of parameters to be saved into the parameter file.
  128. # pars += [{k: ns[k] for k in RegMaxSNParNames}]
  129. #
  130. # # -----------------------------------------------------------------------------------
  131. # # job 2
  132. # # -----------------------------------------------------------------------------------
  133. # initRefSWC = os.path.join(temp1, 'TestFiles', 'HSNR', 'HSN-fluoro01.CNG.swc')
  134. # swcDir = os.path.join(temp1, 'TestFiles', 'HSNR')
  135. # expNames = [
  136. # 'HSN-fluoro01.CNG',
  137. # 'HSN-fluoro04.CNG',
  138. # 'HSN-fluoro05.CNG',
  139. # 'HSN-fluoro07.CNG',
  140. # 'HSN-fluoro09.CNG',
  141. # ]
  142. # swcList = [os.path.join(swcDir, expName + '.swc') for expName in expNames]
  143. # resDir = os.path.join(temp1, 'Results', 'Reg-MaxS-N', 'HSNR')
  144. # finallyNormalizeWRT = initRefSWC
  145. #
  146. # obtains the list of variables in the current work space
  147. # ns = vars()
  148. # forms the dictionary of parameters to be saved into the parameter file.
  149. # pars += [{k: ns[k] for k in RegMaxSNParNames}]
  150. # **********************************************************************************************************************
  151. # write the parameters into the parameter file.
  152. with open(parFile, 'w') as fle:
  153. json.dump(pars, fle)