patch_size_dependence.py 7.2 KB

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