constructRegMaxSNParFile.py 7.4 KB

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