constructRegMaxSParFile.py 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. # Ajayrama Kumaraswamy, 2017, LMU Munich
  2. """
  3. Description: This script is used to generate a parameter file required to run RegMaxS.py. This parameter file
  4. should contain a json string of a list of dictionaries. Each dictionary is one Reg-MaxS job that
  5. contains Reg-MaxS parameters. See core/RegMaxSPars.py for the description of the parameters.
  6. Usage: python <path to file>constructRegMaxSParFile.py
  7. Action: creates a parameter file for RegMaxS.py
  8. Usage guidelines: There are a couple of cases with examples shown below.
  9. Read the comments therein.
  10. Essentially edit the values of some variables in this script and run it.
  11. """
  12. from numpy import pi, deg2rad
  13. import os
  14. import json
  15. from regmaxsn.core.RegMaxSPars import RegMaxSParNames
  16. # obtaining the directory path containing the folder containing this file
  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 = [80.0, 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. retainTempFiles = False
  30. inPartsDir = None
  31. outPartsDir = None
  32. nCPU = 6
  33. # **********************************************************************************************************************
  34. # # User defined parameters
  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. # **********************************************************************************************************************
  44. # # Case 1: Default or user defined parameters above and
  45. # # refSWC: the reference SWC
  46. # # testSWC: the test SWC
  47. # # resFile: the registered version of testSWC will be written into this file path when RegMaxS.py is run with the
  48. # # parameter file generated by this script
  49. # # parFile: the parameter file will be generated at this file path.
  50. # # Usage: Replace refSWC, testSWC, resFile and parFile as required and run this file to generate parFile.
  51. # # Then run python <...>/RegMaxS.py parFile
  52. #
  53. # -------------------------------------------
  54. # # Example 1
  55. # refSWC = os.path.join(temp1, 'TestFiles', 'HSN-fluoro01.CNG.swc')
  56. # testSWC = os.path.join(temp1, 'TestFiles', 'HSN-fluoro01.CNGRandTrans1.swc')
  57. # resFile = os.path.join(temp1, 'Results', 'Tests', 'HSN-fluoro01.CNGRandTrans1.swc')
  58. # parFile = os.path.join(temp1, 'ParFiles', 'Reg-MaxS', 'HSN-fluoro01.CNGRandTrans1.json')
  59. # -------------------------------------------
  60. # # Example 2
  61. # refSWC = os.path.join(temp1, 'TestFiles', 'HSN-fluoro01.CNG.swc')
  62. # testSWC = os.path.join(temp1, 'TestFiles', 'HSN-fluoro01.CNGRandRot0.swc')
  63. # resFile = os.path.join(temp1, 'Results', 'Tests', 'HSN-fluoro01.CNGRandRot0.swc')
  64. # parFile = os.path.join(temp1, 'ParFiles', 'Reg-MaxS', 'HSN-fluoro01.CNGRandRot0.json')
  65. # -------------------------------------------
  66. # # Example 3
  67. refSWC = os.path.join(temp1, 'TestFiles', 'HSN-fluoro01.CNG.swc')
  68. testSWC = os.path.join(temp1, 'TestFiles', 'HSN-fluoro01.CNGRandTranslate0.swc')
  69. resFile = os.path.join(temp1, 'Results', 'Tests', 'HSN-fluoro01.CNGRandTranslate0.swc')
  70. parFile = os.path.join(temp1, 'ParFiles', 'Reg-MaxS', 'HSN-fluoro01.CNGRandTranslate0.json')
  71. # -------------------------------------------
  72. # # Example 4
  73. # refSWC = os.path.join(temp1, 'TestFiles', 'HSN-fluoro01.CNG.swc')
  74. # testSWC = os.path.join(temp1, 'TestFiles', 'HSN-fluoro01.CNGRandScale0.swc')
  75. # resFile = os.path.join(temp1, 'Results', 'Tests', 'HSN-fluoro01.CNGRandScale0.swc')
  76. # parFile = os.path.join(temp1, 'ParFiles', 'Reg-MaxS', 'HSN-fluoro01.CNGRandScale0.json')
  77. # -------------------------------------------
  78. # Example 5
  79. # refSWC = os.path.join(temp1, 'TestFiles', 'LLC', 'Gad1-F-000062.CNG.swc')
  80. # testSWC = os.path.join(temp1, 'TestFiles', 'LLC', 'Cha-F-400051.CNG.swc')
  81. # resFile = os.path.join(temp1, 'Results', 'Tests', 'LLC', 'Cha-F-400051.CNG.swc')
  82. # parFile = os.path.join(temp1, 'ParFiles', 'Reg-MaxS', 'LLC1.json')
  83. # inPartsDir = os.path.join(temp1, 'TestFiles', 'LLC', 'Cha-F-400051.CNG')
  84. # outPartsDir = os.path.join(temp1, 'Results', 'Tests', 'LLC', 'Cha-F-400051.CNG')
  85. #
  86. # -------------------------------------------
  87. # obtains the list of variables in the current work space
  88. ns = vars()
  89. # forms the dictionary of parameters to be saved into the parameter file.
  90. pars = [{k: ns[k] for k in RegMaxSParNames}]
  91. # **********************************************************************************************************************
  92. # # Case 2: Default or user defined parameters above, one reference SWC and several test SWCs, all in the same folder.
  93. # # dirPath: directory containing the reference SWC and the test SWCs
  94. # # refSWC: the reference SWC
  95. # # testSWCFiles: file names of test SWC files in dirPath
  96. # # parameter file generated by this script
  97. # # parFile: the parameter file will be generated at this file path.
  98. # # resPath: the testSWCs registered to the reference SWC will be generated in this directory when RegMaxS.py is run
  99. # # with the parameter file generated by this running this script.
  100. #
  101. # # Usage: Replace dirPath, refSWC, expNames, resPath and parFile as required and run this file to generate parFile
  102. # # Then run python <...>/RegMaxS.py parFile
  103. # -------------------------------------------
  104. # dirPath = os.path.join(temp1, 'TestFiles')
  105. # refSWC = os.path.join(dirPath, 'HSN-fluoro01.CNG.swc')
  106. # testSWCFiles = [
  107. # 'HSN-fluoro01.CNGRandTrans0.swc',
  108. # 'HSN-fluoro01.CNGRandTrans1.swc',
  109. # 'HSN-fluoro01.CNGRandTrans2.swc',
  110. # 'HSN-fluoro01.CNGRandTrans3.swc',
  111. # 'HSN-fluoro01.CNGRandTrans4.swc',
  112. # 'HSN-fluoro01.CNGRandTrans5.swc',
  113. # 'HSN-fluoro01.CNGRandTrans6.swc',
  114. # 'HSN-fluoro01.CNGRandTrans7.swc',
  115. # 'HSN-fluoro01.CNGRandTrans8.swc',
  116. # 'HSN-fluoro01.CNGRandTrans9.swc',
  117. #
  118. # # 'HSN-fluoro01.CNGNoiseStd1RandTrans.swc',
  119. # # 'HSN-fluoro01.CNGNoiseStd2RandTrans.swc',
  120. # # 'HSN-fluoro01.CNGNoiseStd3RandTrans.swc',
  121. # # 'HSN-fluoro01.CNGNoiseStd4RandTrans.swc',
  122. # # 'HSN-fluoro01.CNGNoiseStd5RandTrans.swc',
  123. # # 'HSN-fluoro01.CNGNoiseStd6RandTrans.swc',
  124. # # 'HSN-fluoro01.CNGNoiseStd7RandTrans.swc',
  125. # # 'HSN-fluoro01.CNGNoiseStd8RandTrans.swc',
  126. # # 'HSN-fluoro01.CNGNoiseStd9RandTrans.swc',
  127. # ]
  128. # resPath = os.path.join(temp1, 'Results', 'Tests')
  129. # parFile = os.path.join(temp1, 'ParFiles', 'Reg-MaxS', 'HSN-fluoro01.CNGRandTrans0-9.json')
  130. #
  131. # pars = []
  132. # for sfr in testSWCFiles:
  133. # testSWC = os.path.join(dirPath, sfr)
  134. # resFile = os.path.join(resPath, sfr)
  135. # # obtains the list of variables in the current work space
  136. # ns = vars()
  137. # # forms the dictionary of parameters to be saved into the parameter file.
  138. # pars.append({k: ns[k] for k in RegMaxSParNames})
  139. # -------------------------------------------
  140. # **********************************************************************************************************************
  141. # write the parameters into the parameter file.
  142. with open(parFile, 'w') as fle:
  143. json.dump(pars, fle)