viz2DOccupancy.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import numpy as np
  2. import seaborn as sns
  3. from matplotlib import pyplot as plt
  4. plt.ion()
  5. import os
  6. from regmaxsn.core.matplotlibRCParams import mplPars
  7. from collections import Counter
  8. import pandas as pd
  9. homeFolder = "/home/aj/"
  10. sns.set(rc=mplPars)
  11. swcFiles = [
  12. os.path.join(homeFolder,
  13. 'DataAndResults/morphology/OriginalData/Tests/HSN-fluoro01.CNG.swc'),
  14. os.path.join(homeFolder,
  15. 'DataAndResults/morphology/OriginalData/Tests/HSN-fluoro01.CNGRandRotY0.swc'),
  16. # os.path.join(homeFolder,
  17. # 'DataAndResults/morphology/OriginalData/Tests/HSN-fluoro01.CNGRandRotY1.swc'),
  18. ]
  19. # gridSize = 20.0
  20. # gridSize = 40.0
  21. gridSize = 10.0
  22. voxels = []
  23. for swc in swcFiles:
  24. aPts = np.loadtxt(swc)[:, 2:4]
  25. aPts[:, 0] *= -1
  26. aVox = np.array(aPts / gridSize, np.int32)
  27. aVoxSet = set(map(tuple, aVox))
  28. voxels.extend(list(aVoxSet))
  29. voxelCounter = Counter(voxels)
  30. df = pd.DataFrame()
  31. for voxel, count in voxelCounter.iteritems():
  32. tempDict = {"X": voxel[0], "Y": voxel[1], "count": count}
  33. df = df.append(tempDict, ignore_index=True)
  34. dfIndexed = df.pivot(index='X', columns='Y', values='count')
  35. fig, ax = plt.subplots(figsize=(14, 11.2))
  36. sns.heatmap(data=dfIndexed, xticklabels=50, yticklabels=50, annot=True, fmt="%d",
  37. square=True, cmap=plt.cm.Dark2, cbar_kws={"ticks": np.arange(1, df["count"].max() + 1)},
  38. ax=ax)
  39. ax.set_xlabel('X')
  40. ax.set_ylabel('Y')
  41. fig.tight_layout()