ICi_ICp_term_comparison.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import numpy as np
  2. from matplotlib import gridspec
  3. from matplotlib.lines import Line2D
  4. from charged_shells import functions as fn
  5. import matplotlib.pyplot as plt
  6. import plot_settings
  7. def imp_exp_term(l: int, x: float, abar: float):
  8. return np.sqrt(2 * l + 1) * fn.sph_bessel_k(l, x) / fn.sph_bessel_k(l+1, x) * abar ** l
  9. def perm_exp_term(l: int, x: float, abar: float):
  10. return np.sqrt(2 * l + 1) * x ** 2 * fn.sph_bessel_i(l, abar * x) * fn.sph_bessel_k(l, x)
  11. def plot_exp(kappaR: list, abar: float, save_as = None):
  12. l = np.arange(11)
  13. fig = plt.figure(figsize=(3, 1.8))
  14. gs = gridspec.GridSpec(1, 1, figure=fig)
  15. gs.update(left=0.15, right=0.95, top=0.97, bottom=0.21)
  16. ax = fig.add_subplot(gs[0, 0])
  17. for kr in kappaR:
  18. color = next(plot_settings.COLORS)
  19. ax.plot(l, imp_exp_term(l, kr, abar) / imp_exp_term(0, kr, abar), label='ICi', marker='o', ls=':', c=color)
  20. ax.plot(l, perm_exp_term(l, kr, abar) / perm_exp_term(0, kr, abar), label='ICp', marker='^', ls=':', c=color)
  21. # plt.legend(fontsize=10)
  22. ax.tick_params(which='both', direction='in', top=True, right=True, labelsize=11)
  23. ax.set_xlabel(r'$l$', fontsize=11)
  24. ax.set_ylabel('normalized coef', fontsize=11)
  25. if save_as is not None:
  26. plt.savefig(save_as, dpi=300)
  27. plt.show()
  28. def plot_exp2(kappaR: float, abar: list, save_as=None, legend=True):
  29. l = np.arange(11)
  30. line1 = Line2D([0], [0], color='black', marker='o', linestyle='None', label='$b_{i,l0}$')
  31. line2 = Line2D([0], [0], color='black', marker='^', linestyle='None', label='$c_{i,l0}$')
  32. abar_lines = []
  33. fig = plt.figure(figsize=(3, 2))
  34. gs = gridspec.GridSpec(1, 1, figure=fig)
  35. gs.update(left=0.15, right=0.95, top=0.87, bottom=0.21)
  36. ax = fig.add_subplot(gs[0, 0])
  37. for ab in abar:
  38. color = next(plot_settings.COLORS)
  39. ax.plot(l, imp_exp_term(l, kappaR, ab) / imp_exp_term(0, kappaR, ab), label='rr', marker='o', ls=':', c=color)
  40. ax.plot(l, perm_exp_term(l, kappaR, ab) / perm_exp_term(0, kappaR, ab), label='tt', marker='^', ls=':',
  41. c=color)
  42. abar_lines.append(Line2D([0], [0], color=color, linewidth=1.2, ls=':', label=rf'$\bar a={ab}$'))
  43. # main_legend = ax.legend(frameon=False)
  44. if legend:
  45. extra_legend = ax.legend(handles=[line1, line2] + abar_lines, loc='upper right', fontsize=11, frameon=False)
  46. # extra_legend2 = ax.legend(handles=abar_lines, loc='center right', fontsize=11, frameon=False)
  47. ax.tick_params(which='both', direction='in', top=True, right=True, labelsize=11)
  48. ax.set_xlabel(r'$l$', fontsize=11)
  49. ax.set_title(f'$\kappa R={kappaR}$', fontsize=11)
  50. ax.set_ylabel('normalized coef', fontsize=11)
  51. if save_as is not None:
  52. plt.savefig(save_as, dpi=300)
  53. plt.show()
  54. def plot_imp_ex(abar: float):
  55. kappaR = np.geomspace(0.1, 50, 1000)
  56. l = np.arange(10)
  57. fig, ax = plt.subplots()
  58. ax.plot(kappaR, imp_exp_term(l[None, :], kappaR[:, None], abar))
  59. ax.set_xscale('log')
  60. plt.show()
  61. def plot_imp_ex_ratio(abar: float):
  62. kappaR = np.geomspace(0.1, 50, 1000)
  63. l = np.arange(10)
  64. fig, ax = plt.subplots()
  65. ax.plot(kappaR, imp_exp_term(l[None, :], kappaR[:, None], abar) / imp_exp_term(l[None, :] + 1, kappaR[:, None], abar))
  66. ax.set_xscale('log')
  67. plt.show()
  68. def plot_perm_ex(abar: float):
  69. kappaR = np.geomspace(0.1, 50, 1000)
  70. l = np.arange(10)
  71. fig, ax = plt.subplots()
  72. ax.plot(kappaR, perm_exp_term(l[None, :], kappaR[:, None], abar))
  73. ax.set_xscale('log')
  74. plt.show()
  75. def plot_perm_ex_ratio(abar: float):
  76. kappaR = np.geomspace(0.1, 50, 1000)
  77. l = np.arange(10)
  78. fig, ax = plt.subplots()
  79. ax.plot(kappaR, perm_exp_term(l[None, :], kappaR[:, None], abar) / perm_exp_term(l[None, :] + 1, kappaR[:, None], abar))
  80. ax.set_xscale('log')
  81. plt.show()
  82. def plot_kappaR_dep(l: int, abar: float):
  83. kappaR = np.geomspace(0.1, 50, 1000)
  84. fig, ax = plt.subplots()
  85. ax.plot(kappaR, imp_exp_term(l, kappaR, abar))
  86. ax.plot(kappaR, perm_exp_term(l, kappaR, abar))
  87. ax.set_xscale('log')
  88. plt.show()
  89. def plot_kappaR_dep_ratio(l: int, abar: float, l_diff: int = 2):
  90. kappaR = np.geomspace(0.1, 50, 1000)
  91. fig, ax = plt.subplots()
  92. ax.plot(kappaR, imp_exp_term(l + l_diff, kappaR, abar) / imp_exp_term(l, kappaR, abar))
  93. ax.plot(kappaR, perm_exp_term(l + l_diff, kappaR, abar) / perm_exp_term(l, kappaR, abar))
  94. ax.set_xscale('log')
  95. plt.show()
  96. if __name__ == '__main__':
  97. # plot_exp([1, 10, 50], 0.4,
  98. # # save_as=FIGURES_PATH.joinpath('ici_icp_expansion_a08_kr10.png')
  99. # )
  100. plot_exp2(1, [0.5, 0.8], legend=True,
  101. # save_as=FIGURES_PATH.joinpath('ici_icp_expansion_kr1.png')
  102. )
  103. # plot_kappaR_dep_ratio(2, 0.8, l_diff=2)
  104. # plot_imp_ex_ratio(0.5)
  105. # plot_perm_ex_ratio(0.5)