patch_size_dependence.py 6.7 KB

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