courtemanche2D_phases.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. # Courtemanche1998 model, 2 ruimtedimensies, 21 variabelen
  12. data = ith.SimData.from_stem("myokit12/myokit_2")
  13. # Vermijd randeffecten en initialiatie
  14. # TODO: begintijd zou in principe in de log moeten staan
  15. def snij_randen_weg(variabele,begintijd, eindtijd):
  16. def begin(index):
  17. if index == 0:
  18. return begintijd
  19. return variabele.shape[index]//8
  20. def eind(index):
  21. if index == 0:
  22. return eindtijd
  23. if variabele.shape[index] < 20:
  24. return variabele.shape[index]
  25. return (7 * variabele.shape[index])//8
  26. return variabele[begin(0):eind(0),begin(1):eind(1),begin(2):eind(2),begin(3):eind(3)]
  27. def snij_randen_weg2(variables,begintijd,eindtijd):
  28. newdata = dict()
  29. for key in variables.keys():
  30. newdata[key] = snij_randen_weg(variables[key], begintijd,eindtijd)
  31. return newdata
  32. t0 = 1
  33. t1 = 150
  34. aantal_punten = 15000
  35. vars = snij_randen_weg2(data.vars, t0, t1)
  36. for key in vars.keys():
  37. vars[key] = vars[key].ravel()
  38. def plot4(x,y,z,w,autoclose=False):
  39. choices = np.random.choice(vars[x].shape[0], aantal_punten, replace=True)
  40. var1 = vars[x][choices]
  41. var2 = vars[y][choices]
  42. var3 = vars[z][choices]
  43. var4 = vars[w][choices]
  44. fig = plt.figure()
  45. ax = fig.add_subplot(projection='3d')
  46. ax.scatter(var1, var2, var3, c=var4, cmap='viridis')
  47. ax.set_xlabel(x)
  48. ax.set_ylabel(y)
  49. ax.set_zlabel(z)
  50. plt.axis('tight')
  51. #plt.savefig("Courtemanche2D (%s, %s, %s -> %s).png" % (x, y, z, w))
  52. if not autoclose:
  53. plt.show()
  54. plt.close()
  55. matplotlib.use("TkAgg")
  56. # Choose random combinations of vour variables.
  57. keys = list(vars.keys())
  58. assert(np.std(data.vars['K']) == 0) # it is constant, so don't plot it (the contrentation of K+ ions remains constant?)
  59. keys.remove('K')
  60. keys.sort()
  61. np.random.seed(1234)
  62. for i in range(0,500):
  63. which_keys = np.random.choice(keys, 4, replace=False)
  64. print(which_keys)
  65. plot4(which_keys[0], which_keys[1], which_keys[2], which_keys[3])
  66. # , autoclose=True)
  67. plot4("gatexr", "gatev", "gatew", "Ca")
  68. # gateh, Na, gateu, ??
  69. # gated, >Ca, gateexr
  70. # PDF cOURTEMANCHE: https://journals-physiology-org.kuleuven.e-bronnen.be/doi/epdf/10.1152/ajpheart.1998.275.1.H301
  71. # ajpheart.1998.275.1.h301
  72. # ['gateoi' 'gatew' 'gateoa' 'gatefCa'] # saai
  73. # ['gateui' 'Ca' 'Carel' 'gated'] # saai
  74. # ['gateh' 'gateu' 'Na' 'Caup']
  75. plot4('gateh', 'gateu', 'Na', 'Caup')
  76. plot4('gateh', 'gateu', 'Caup', 'Na')
  77. plot4('gateh', 'Caup', 'gateu', 'Na')
  78. plot4('Caup', 'gateh', 'gateu', 'Na')
  79. # rprobeer: gateu, Caup, ???, ??
  80. np.random.seed(1234)
  81. for i in range(0,40):
  82. keys2 = list(keys)
  83. keys2.remove('gateu')
  84. keys2.remove('Caup')
  85. which_keys2 = np.random.choice(keys2, 2, replace=False)
  86. print (['gateu', 'Caup', which_keys2[0], which_keys2[1]])
  87. plot4('gateu', 'Caup', which_keys2[0], which_keys2[1])
  88. #['gateu', 'Caup', 'gatexs', 'gateoa'] --> complex, still 2D? (maybe check with diffmap
  89. #['gateu', 'Caup', 'gateoi', 'gateh'] --> closed, non-weird
  90. #['gateu', 'Caup', 'gateui', 'gatev'] --> not closed, complex, still 2D, maybe
  91. #['gateu', 'Caup', 'gateui', 'gateh'] --> not closed, complex, still 2D, maybe
  92. #['gateu', 'Caup', 'gateui', 'Ca'] --> complex, maybe closed,
  93. #['gateu', 'Caup', 'gateoa', 'gateoi'] --> maybe 2D, but check
  94. #['gateu', 'Caup', 'gatev', 'gatefCa'] ---> maybe 3D, check!
  95. #['gateu', 'Caup', 'gatew', 'gatef'] --> check