patch_size_dependence.py 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. from pathlib import Path
  2. import numpy as np
  3. from charged_shells import expansion, patch_size
  4. from charged_shells.parameters import ModelParams
  5. import time
  6. import json
  7. from plot_settings import *
  8. def plot_abar_dependence(*, save=False, save_data=False):
  9. a_bar = np.linspace(0.2, 0.8, 101)
  10. kappaR = np.array([1, 3, 10])
  11. params = ModelParams(R=150, kappaR=kappaR)
  12. ex = expansion.MappedExpansionQuad(a_bar=a_bar[:, None], sigma_tilde=0.001, l_max=30, kappaR=kappaR[None, :])
  13. ps = patch_size.potential_patch_size(ex, params, match_expansion_axis_to_params=1)
  14. marked_point_ex = expansion.MappedExpansionQuad(a_bar=0.5, sigma_tilde=0.001, l_max=30, kappaR=3)
  15. mark_ps = patch_size.potential_patch_size(marked_point_ex, ModelParams(R=150, kappaR=3),
  16. match_expansion_axis_to_params=None)
  17. markers = ['o', 's', '^', 'D', 'v', '<', '>', 'p', '*', 'H', '+', 'x']
  18. if save_data:
  19. data_dict = {}
  20. for key, patch in zip(["kR=01", "kR=1", "kR=3", "kR=10", "kR=30"], ps.T):
  21. data_dict[key] = np.stack((a_bar, patch)).T
  22. with open(Path("/home/andraz/ChargedShells/charged-shells/config.json")) as config_file:
  23. config_data = json.load(config_file)
  24. np.savez(Path(config_data["figure_data"]).joinpath("fig_6.npz"), **data_dict)
  25. # fig, ax = plt.subplots(figsize=plt.figaspect(0.5)/1.5)
  26. fig, ax = plt.subplots(figsize=(2, 1.7))
  27. for patch, kR, marker in zip(ps.T, kappaR, markers):
  28. ax.plot(a_bar, patch, label=rf'$\kappa R$ = {kR}', linewidth=1.5,
  29. # marker=marker, markerfacecolor='none', markersize=8, markevery=10
  30. )
  31. ax.tick_params(which='both', direction='in', top=True, right=True, labelsize=11)
  32. ax.set_xlabel(r'$\bar a$', fontsize=11)
  33. ax.set_ylabel(r'$\theta_0$', fontsize=11)
  34. plt.legend(handlelength=0.6, fontsize=9, frameon=False, loc='upper right', bbox_to_anchor=(0.55, 0.63))
  35. # plt.tight_layout()
  36. plt.subplots_adjust(left=0.22, right=0.97, top=0.95, bottom=0.22)
  37. plt.axhline(y=mark_ps, color='black', linestyle=':')
  38. plt.axvline(x=0.5, color='black', linestyle=':')
  39. ax.xaxis.set_label_coords(0.5, -0.17)
  40. if save:
  41. plt.savefig(Path("/home/andraz/ChargedShells/Figures/final_figures/patch_size_potential.png"), dpi=300)
  42. plt.show()
  43. def plot_abar_charge_dependence(*, save=False):
  44. a_bar = np.linspace(0.2, 0.8, 101)
  45. kappaR = np.array([0.1, 1, 3, 10, 30])
  46. ex = expansion.MappedExpansionQuad(a_bar=a_bar[:, None], sigma_tilde=0.001, l_max=30, kappaR=kappaR[None, :])
  47. ps = patch_size.charge_patch_size(ex)
  48. markers = ['o', 's', '^', 'D', 'v', '<', '>', 'p', '*', 'H', '+', 'x']
  49. fig, ax = plt.subplots(figsize=plt.figaspect(0.5)/1.5)
  50. for patch, kR, marker in zip(ps.T, kappaR, markers):
  51. ax.plot(a_bar, patch, label=rf'$\kappa R$ = {kR}', marker=marker, markerfacecolor='none', markevery=5)
  52. ax.tick_params(which='both', direction='in', top=True, right=True, labelsize=12)
  53. ax.set_xlabel(r'$\bar a$', fontsize=15)
  54. ax.set_ylabel(r'$\theta_0$', fontsize=15)
  55. plt.legend(fontsize=14)
  56. plt.tight_layout()
  57. if save:
  58. plt.savefig(Path("/home/andraz/ChargedShells/Figures/patch_size_charge.pdf"), dpi=300)
  59. plt.show()
  60. def plot_kappaR_charge_dependence(*, normalized=False, save=False):
  61. a_bar = np.array([0.2, 0.4, 0.6, 0.8])
  62. kappaR = np.linspace(0.01, 30, 100)
  63. ex = expansion.MappedExpansionQuad(a_bar=a_bar[None, :], sigma_tilde=0.001, l_max=30, kappaR=kappaR[:, None])
  64. ps = patch_size.charge_patch_size(ex)
  65. if normalized:
  66. ps = ps / ps[0][None, :]
  67. markers = ['o', 's', '^', 'D', 'v', '<', '>', 'p', '*', 'H', '+', 'x']
  68. fig, ax = plt.subplots(figsize=plt.figaspect(0.5)/1.5)
  69. for patch, abar, marker in zip(ps.T, a_bar, markers):
  70. ax.plot(kappaR, patch, label=rf'$\bar a$ = {abar}', marker=marker, markerfacecolor='none', markevery=5)
  71. ax.tick_params(which='both', direction='in', top=True, right=True, labelsize=12)
  72. ax.set_xlabel(r'$\kappa R$', fontsize=15)
  73. ax.set_ylabel(r'$\theta_0$', fontsize=15)
  74. plt.legend(fontsize=14)
  75. plt.tight_layout()
  76. if save:
  77. plt.savefig(Path("/home/andraz/ChargedShells/Figures/patch_size_charge_nonmonotonicity.pdf"), dpi=300)
  78. plt.show()
  79. def plot_sigma0_dependence(*, save=False):
  80. # kappaR = np.array([0.1, 1, 3, 10, 30])
  81. kappaR = np.linspace(0.1, 15, 201)
  82. # sigma0 = np.linspace(-0.001, 0.0015, 6)
  83. sigma0 = np.array([-0.0002, 0, 0.0002])
  84. params = ModelParams(R=150, kappaR=kappaR)
  85. ex = expansion.MappedExpansionQuad(a_bar=0.3, sigma_tilde=0.001, l_max=30, kappaR=kappaR, sigma0=sigma0)
  86. t0 = time.perf_counter()
  87. ps = patch_size.potential_patch_size(ex, params, match_expansion_axis_to_params=0, skip_nozero_cases=True)
  88. t1 = time.perf_counter()
  89. print(f'Time: {t1 - t0}')
  90. markers = ['o', 's', '^', 'D', 'p', 'v', '<', '>', 'x', '*', 'H', '+']
  91. fig, ax = plt.subplots(figsize=plt.figaspect(0.5)/1.5)
  92. for patch, sgm, marker in zip(ps.T, sigma0, markers):
  93. nonzero_ps = np.nonzero(patch)
  94. ax.plot(kappaR[nonzero_ps], patch[nonzero_ps], label=rf'$\tilde \sigma_0$ = {sgm}', marker=marker, markerfacecolor='none', markevery=10)
  95. ax.tick_params(which='both', direction='in', top=True, right=True, labelsize=12)
  96. ax.set_xlabel(r'$\kappa R$', fontsize=15)
  97. ax.set_ylabel(r'$\theta_0$', fontsize=15)
  98. plt.legend(fontsize=14, loc='upper right')
  99. plt.tight_layout()
  100. if save:
  101. plt.savefig(Path("/home/andraz/ChargedShells/Figures/patch_size_potential_charge_abar03.pdf"), dpi=300)
  102. plt.show()
  103. def plot_sigma0_dependence_relative(*, save=False):
  104. # kappaR = np.array([0.1, 1, 3, 10, 30])
  105. kappaR = np.linspace(0.1, 15, 201)
  106. # sigma0 = np.linspace(-0.001, 0.0015, 6)
  107. sigma0 = np.array([-0.0002, 0, 0.0002])
  108. params = ModelParams(R=150, kappaR=kappaR)
  109. ex = expansion.MappedExpansionQuad(a_bar=0.8, sigma_tilde=0.001, l_max=30, kappaR=kappaR, sigma0=sigma0)
  110. ex_neutral = expansion.MappedExpansionQuad(a_bar=0.3, sigma_tilde=0.001, l_max=30, kappaR=kappaR, sigma0=0)
  111. ps = patch_size.potential_patch_size(ex, params, match_expansion_axis_to_params=0, skip_nozero_cases=True)
  112. ps_neutral = patch_size.potential_patch_size(ex_neutral, params, match_expansion_axis_to_params=0)
  113. markers = ['o', 's', '^', 'D', 'p', 'v', '<', '>', 'x', '*', 'H', '+']
  114. fig, ax = plt.subplots(figsize=plt.figaspect(0.5)/1.5)
  115. for patch, sgm, marker in zip(ps.T, sigma0, markers):
  116. nonzero_ps = np.nonzero(patch)
  117. ax.plot(kappaR[nonzero_ps], patch[nonzero_ps] / ps_neutral[nonzero_ps],
  118. label=rf'$\tilde \sigma_0$ = {sgm}', marker=marker, markerfacecolor='none', markevery=10)
  119. ax.tick_params(which='both', direction='in', top=True, right=True, labelsize=12)
  120. ax.set_xlabel(r'$\kappa R$', fontsize=15)
  121. ax.set_ylabel(r'$\theta_0$', fontsize=15)
  122. plt.legend(fontsize=14)
  123. plt.tight_layout()
  124. if save:
  125. plt.savefig(Path("/home/andraz/ChargedShells/Figures/patch_size_potential_charge_abar03_relative.pdf"), dpi=300)
  126. plt.show()
  127. def main():
  128. plot_abar_dependence(save=True)
  129. # plot_sigma0_dependence(save=True)
  130. # plot_sigma0_dependence_relative(save=True)
  131. # plot_abar_charge_dependence(save=True)
  132. # plot_kappaR_charge_dependence(normalized=True, save=True)
  133. if __name__ == '__main__':
  134. main()