saveDiffDensity.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import os
  2. from core.plotDensities import DensityVizualizations, writeTIFF
  3. import numpy as np
  4. from matplotlib import pyplot as plt
  5. homeFolder = os.path.expanduser('~')
  6. plt.ion()
  7. # ----------------------------------------------------------------------------------------------------------------------
  8. # # resDir = os.path.join(homeFolder, 'DataAndResults/morphology/Backups/directPixelBased/HB121224-1_80402010_1p0')
  9. # # resDir = os.path.join(homeFolder, 'DataAndResults/morphology/Backups/directPixelBased/HB121224-1_80402010_noScale')
  10. # resDir = os.path.join(homeFolder, 'DataAndResults/morphology/directPixelBased/HB121224-1')
  11. # expNames1 = ['HB121224-1-WNC10S10x20']
  12. # expNames2 = ['HB121224-1-WNC10S10x40']
  13. #
  14. # part = ''
  15. # label1 = 'x20'
  16. # label2 = 'x40'
  17. # swcSet1 = [os.path.join(resDir, x + '.swc') for x in expNames1]
  18. # swcSet2 = [os.path.join(resDir, x + '.swc') for x in expNames2]
  19. # gridUnitSize = [1] * 3
  20. # sigmas = [5, 5, 5]
  21. # resampleLen = 0.5
  22. # initTrans = np.diag([1, 1, 1])
  23. # ----------------------------------------------------------------------------------------------------------------------
  24. resDir = os.path.join(homeFolder, 'DataAndResults/morphology/directPixelBased/DL-Int-1_Forager_NE/Forager_NE_norm/')
  25. # Foragers
  26. expNames1 = [
  27. 'HB130313-4',
  28. 'HB130322-1',
  29. 'HB130326-2',
  30. 'HB130408-1',
  31. 'HB130425-1',
  32. 'HB130501-2',
  33. 'HB130705-1',
  34. 'HB140424-1',
  35. # 'HB140701-1'
  36. ]
  37. # newlyEmerged
  38. expNames2 = [
  39. 'HB130523-3',
  40. 'HB130605-1',
  41. 'HB130605-2',
  42. 'HB140813-3',
  43. 'HB140917-1',
  44. 'HB140930-1',
  45. 'HB141030-1',
  46. # 'HB140701-1'
  47. ]
  48. part = '-DB'
  49. # part = '-VB'
  50. swcSet1 = [os.path.join(resDir, x + '_norm_norm', x + part + '_norm_norm.swc') for x in expNames1]
  51. swcSet2 = [os.path.join(resDir, x + '_norm_norm', x + part + '_norm_norm.swc') for x in expNames2]
  52. label1 = 'Forager'
  53. label2 = 'NewlyEmerged'
  54. gridUnitSize = [10] * 3
  55. sigmas = [10] * 3
  56. resampleLen = 1
  57. initTrans = np.diag([1, 1, 1])
  58. # ----------------------------------------------------------------------------------------------------------------------
  59. densityDir = os.path.join(resDir, 'DensityDiffResults')
  60. if not os.path.isdir(densityDir):
  61. os.mkdir(densityDir)
  62. outFile = os.path.join(densityDir, label1 + '-' + label2 + '-' + part)
  63. densityViz = DensityVizualizations(swcSet2 + swcSet1, gridUnitSize, resampleLen)
  64. d1, bins = densityViz.calculateDensity(swcSet1, sigmas)
  65. d2, bins = densityViz.calculateDensity(swcSet2, sigmas)
  66. d1Md2 = d1 - d2
  67. d1Md2Norm = d1Md2.copy()
  68. d1Md2Norm += 1
  69. d1Md2Norm /= 2
  70. densityViz.generateDensityColoredSSWC(swcSet1,
  71. [os.path.join(densityDir, x + part + '_density.sswc') for x in expNames1],
  72. d1Md2Norm)
  73. densityViz.generateDensityColoredSSWC(swcSet2,
  74. [os.path.join(densityDir, x + part + '_density.sswc') for x in expNames2],
  75. d1Md2Norm)
  76. np.savez_compressed(outFile, density1=d1, density2=d2, bins=bins, swcSet1=swcSet1, swcSet2=swcSet2)