alignAllRot.py 1.8 KB

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