alignAllScale.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import os
  2. import numpy as np
  3. from RegMaxSCore.iterativeRegistration import IterativeRegistration
  4. import shutil
  5. homeFolder = os.path.expanduser('~')
  6. # ----------------------------------------------------------------------------------------------------------------------
  7. # #
  8. temp = os.path.split(__file__)[0]
  9. temp1 = os.path.split(temp)[0]
  10. dirPath = os.path.join(temp1, 'TestFiles')
  11. expNames = [
  12. 'HSN-fluoro01.CNG',
  13. 'HSN-fluoro01.CNGRandScale',
  14. ]
  15. refInd = 0
  16. resDir = os.path.join(temp1, 'Results', 'scaleRefined')
  17. if not os.path.isdir(resDir):
  18. os.mkdir(resDir)
  19. # ----------------------------------------------------------------------------------------------------------------------
  20. gridSizes = [40.0, 20.0, 10.0]
  21. scaleBounds = [[0.5, 1/0.5], [0.5, 1/0.5], [0.5, 1/0.5]]
  22. minScaleStepSize = 1.005
  23. nCPU = 6
  24. refSWC = os.path.join(dirPath, expNames[refInd] + '.swc')
  25. iterReg = IterativeRegistration(refSWC, gridSizes, None, None,
  26. None, minScaleStepSize, None, nCPU)
  27. ipParFile = os.path.join(resDir, 'tmp.json')
  28. vals = ['scale']
  29. tempOutFiles = {}
  30. for val in vals:
  31. fle1 = os.path.join(resDir, val + '.swc')
  32. fle2 = os.path.join(resDir, val + 'bestSol.json')
  33. tempOutFiles[val] = [fle1, fle2]
  34. for expInd, expName in enumerate(expNames):
  35. if refInd != expInd:
  36. print('Doing ' + expName + ' Scale')
  37. SWC2Align = os.path.join(dirPath, expName + '.swc')
  38. iterReg.scaleOnce(SWC2Align, tempOutFiles['scale'], ipParFile, scaleBounds)
  39. shutil.copyfile(tempOutFiles['scale'][0], os.path.join(resDir, '{}.swc'.format(expName)))
  40. shutil.copyfile(tempOutFiles['scale'][1], os.path.join(resDir, '{}bestSol.json'.format(expName)))
  41. for g in vals:
  42. [os.remove(x) for x in tempOutFiles[g]]
  43. os.remove(ipParFile)