plot-some-times.py 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/bin/env python3
  2. import ithildin as ith
  3. import numpy as np
  4. import matplotlib.pyplot as plt
  5. import sys
  6. from typing import List
  7. from scipy.interpolate import RectBivariateSpline
  8. from pydiffmap.diffusion_map import DiffusionMap
  9. from pydiffmap import visualization as diff_visualization
  10. import matplotlib
  11. import matplotlib.cm as cm
  12. matplotlib.use("TkAgg")
  13. courtemanche_spiral = ith.SimData.from_stem("myokit_CMspiral3/myokit_5")
  14. # 70, 74, 78
  15. for i in range(70,79,4):
  16. print(i)
  17. frame = courtemanche_spiral.vars['u'][i,0,:,:]
  18. plt.imshow(frame)
  19. plt.savefig("CMspiral3-z0-t%s.pdf" % (i,))
  20. plt.savefig("CMspiral3-z0-t%s.png" % (i,))
  21. plt.show()
  22. # todo assen benoemen
  23. plt.close()
  24. # Show two frames of courtemanche_spiral, with a single colourbar,
  25. # as described in <https://stackoverflow.com/questions/13784201/how-to-have-one-colorbar-for-all-subplots/23795901#23795901>
  26. fig,axes = plt.subplots(ncols=2, constrained_layout=True, sharex=True, sharey=True)
  27. fig.supxlabel(r"$x$[mm]",y=0.16)
  28. fig.supylabel(r"$y$[mm]")
  29. frame70 = courtemanche_spiral.vars['u'][70,0,:,:]
  30. frame74 = courtemanche_spiral.vars['u'][74,0,:,:]
  31. vmin = min([np.min(frame70),np.min(frame74)]) # lowest value for colour bar
  32. vmax = min([np.max(frame70),np.max(frame74)]) # highest value for colour bar
  33. im = axes.flat[0].imshow(frame70, vmin=vmin, vmax=vmax)
  34. im = axes.flat[1].imshow(frame74, vmin=vmin, vmax=vmax)
  35. fig.colorbar(im, ax=axes.ravel().tolist(),shrink=0.5,label='u[A.U]')
  36. plt.savefig("CMspiral3-z0-t70-and-74.pdf",bbox_inches='tight')
  37. plt.savefig("CMspiral3-z0-t70-and-74.png",bbox_inches='tight')
  38. plt.show()
  39. plt.close()
  40. ap = ith.SimData.from_stem("phase_1000/phase_1000")
  41. np.random.seed(1)
  42. u = ap.vars['u'][100:,:,20:380,20:380].ravel()
  43. v = ap.vars['v'][100:,:,20:380:,20:380].ravel()
  44. points = np.random.choice(u.size,2500000)
  45. u = u[points]
  46. v = v[points]
  47. plt.xlabel("u[A.U]")
  48. plt.ylabel("v[A.U]")
  49. plt.scatter(u,v,s=0.001)
  50. plt.savefig("phase1000-fase.png")
  51. plt.show()
  52. plt.close()
  53. # Make a standalone colourbar for the thesis.
  54. bofc = ith.SimData.from_stem("results_9010/PDL_9010")
  55. fig, ax = plt.subplots(figsize=(1,3))
  56. fig.subplots_adjust(right=0.25)
  57. bofc_vmin = np.min(bofc.vars['s'])
  58. bofc_vmax = np.min(bofc.vars['s'])
  59. fig.colorbar(cm.ScalarMappable(cmap='viridis',norm=matplotlib.colors.Normalize(vmin=bofc_vmin,vmax=bofc_vmax)),orientation="vertical",cax=ax)
  60. plt.savefig("bofc-transformed-4th-standalone-colourbar.png",bbox_inches='tight')
  61. plt.savefig("bofc-transformed-4th-standalone-colourbar.pdf",bbox_inches='tight')
  62. plt.show()
  63. plt.close()
  64. # TODO check, actually run
  65. # Not very fast but < a minute
  66. np.random.seed(1)
  67. # Vermijd randeffecten en initialiatie
  68. def snoei(variable):
  69. print(np.shape(variable))
  70. # see dimensiereductie_BOFC_verbeterd.py
  71. return variable[(41 * 7 + 32)//33:,2:18,375//8:322,375//8:322].ravel()
  72. u = snoei(bofc.vars['u'])
  73. points = np.random.choice(u.size,500000)
  74. #2500000
  75. u = u[points]
  76. v = snoei(bofc.vars['v'])[points]
  77. w = snoei(bofc.vars['w'])[points]
  78. s = snoei(bofc.vars['s'])[points]
  79. fig = plt.figure()
  80. ax = fig.add_subplot(projection='3d')
  81. ax.scatter(u,v,w,c=s,cmap='viridis',s=0.002) #,cmap='viridis') #plt.hot(),s=0.002)
  82. ax.set_xlabel(r'$u$')
  83. ax.set_ylabel(r'$v$')
  84. ax.set_zlabel(r'$w$')
  85. #plt.colorbar() TODO
  86. fig.gca().set_title(r'$s$')
  87. plt.savefig("BOFC-fase-5000.png")
  88. plt.show()
  89. plt.close()