alignAllTrans.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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.CNGRandTranslate',
  13. ]
  14. refInd = 0
  15. resDir = os.path.join(temp1, 'Results', 'translateRefined')
  16. if not os.path.isdir(resDir):
  17. os.mkdir(resDir)
  18. # ----------------------------------------------------------------------------------------------------------------------
  19. gridSizes = [40.0, 20.0, 10.0]
  20. transBounds = [[-30, 30], [-30, 30], [-30, 30]]
  21. transMinRes = 1
  22. nCPU = 6
  23. refSWC = os.path.join(dirPath, expNames[refInd] + '.swc')
  24. iterReg = IterativeRegistration(refSWC, gridSizes, None, transBounds,
  25. transMinRes, None, None, nCPU)
  26. ipParFile = os.path.join(resDir, 'tmp.json')
  27. vals = ['trans']
  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 + ' Scale')
  36. SWC2Align = os.path.join(dirPath, expName + '.swc')
  37. iterReg.transOnce(SWC2Align, tempOutFiles['trans'], ipParFile)
  38. shutil.copyfile(tempOutFiles['trans'][0], os.path.join(resDir, '{}.swc'.format(expName)))
  39. shutil.copyfile(tempOutFiles['trans'][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)