peak_heigth.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import matplotlib.pyplot as plt
  2. from charged_shells import expansion, interactions, mapping
  3. from charged_shells.parameters import ModelParams
  4. import numpy as np
  5. from typing import Literal
  6. from pathlib import Path
  7. from functools import partial
  8. import json
  9. Array = np.ndarray
  10. Expansion = expansion.Expansion
  11. RotConfig = Literal['ep', 'pp']
  12. def peak_energy_plot(kappaR: Array,
  13. a_bar: Array,
  14. which: Literal['ep', 'pp'],
  15. R: float = 150,
  16. dist: float = 2.,
  17. l_max=20,
  18. save_as: Path = None):
  19. params = ModelParams(R=R, kappaR=kappaR)
  20. # energy = []
  21. # for params in params.unravel():
  22. # ex1 = expansion.MappedExpansionQuad(a_bar, params.kappaR, 0.001, l_max=l_max)
  23. # ex2 = ex1.clone()
  24. # if which == 'ep':
  25. # ex1.rotate_euler(alpha=0, beta=np.pi / 2, gamma=0)
  26. # energy.append(interactions.charged_shell_energy(ex1, ex2, dist, params))
  27. #
  28. # energy = np.array(energy)
  29. ex1 = expansion.MappedExpansionQuad(a_bar[:, None], params.kappaR[None, :], 0.001, l_max=l_max)
  30. ex2 = ex1.clone()
  31. if which == 'ep':
  32. ex1.rotate_euler(alpha=0, beta=np.pi / 2, gamma=0)
  33. energy_fn = mapping.parameter_map_two_expansions(partial(interactions.charged_shell_energy, dist=dist), 1)
  34. energy = energy_fn(ex1, ex2, params)
  35. fig, ax = plt.subplots()
  36. for en, ab in zip(energy, a_bar):
  37. ax.plot(kappaR, en / en[0], label=rf'$\bar a = {ab:.1f}$')
  38. # ax.plot(kappaR, en, label=rf'$\bar a = {ab:.1f}$')
  39. ax.legend(fontsize=12)
  40. ax.tick_params(which='both', direction='in', top=True, right=True, labelsize=15)
  41. ax.set_xlabel(r'$\kappa R$', fontsize=15)
  42. ax.set_ylabel(rf'$\bar V$', fontsize=15)
  43. plt.tight_layout()
  44. if save_as is not None:
  45. plt.savefig(save_as, dpi=600)
  46. plt.show()
  47. def IC_peak_energy_plot(config_data: dict,
  48. a_bar: list,
  49. which: Literal['ep', 'pp'],
  50. save_as: Path = None):
  51. em_data_path = (Path(config_data["emanuele_data"]).joinpath("FIG_11"))
  52. em_data = np.load(em_data_path.joinpath("pair_energy_fig11.npz"))
  53. data = em_data['fixA']
  54. if which == 'ep':
  55. column_idx = 4
  56. elif which == 'pp':
  57. column_idx = 3
  58. else:
  59. raise ValueError
  60. abar, inverse, counts = np.unique(data[:, 1], return_counts=True, return_inverse=True)
  61. # print(indices, counts)
  62. print(inverse)
  63. # sort_abar = np.argsort(indices)
  64. # print(data[:, 1][indices])
  65. # print(sort_abar)
  66. # print(data[:, 1][indices[sort_abar]])
  67. # energies = data[:, column_idx].reshape(-1, counts[0])
  68. # kappaR = data[:, 2].reshape(-1, counts[0])
  69. # print(len(kappaR), len(energies), len(abar))
  70. fig, ax = plt.subplots()
  71. for i in range(len(abar)):
  72. if abar[i] in a_bar:
  73. idx, = np.nonzero(inverse == i)
  74. kR = data[idx, 2]
  75. en = data[idx, column_idx]
  76. sort = np.argsort(kR)
  77. # ax.plot(kR[sort], en[sort] / en[sort][0], label=rf'$\bar a = {abar[i]:.2f}$')
  78. ax.plot(kR[sort], en[sort], label=rf'$\bar a = {abar[i]:.2f}$')
  79. ax.legend(fontsize=12)
  80. ax.tick_params(which='both', direction='in', top=True, right=True, labelsize=15)
  81. ax.set_xlabel(r'$\kappa R$', fontsize=15)
  82. ax.set_ylabel(rf'$\bar V_{{{which}}}$', fontsize=15)
  83. plt.tight_layout()
  84. ax.set_yscale('log')
  85. ax.set_xscale('log')
  86. if save_as is not None:
  87. plt.savefig(save_as, dpi=600)
  88. plt.show()
  89. if __name__ == '__main__':
  90. with open(Path("/home/andraz/ChargedShells/charged-shells/config.json")) as config_file:
  91. config_data = json.load(config_file)
  92. kappaR = np.arange(0.5, 10, 0.1)
  93. a_bar = np.arange(0.2, 0.8, 0.2)
  94. # peak_energy_plot(kappaR, a_bar, which='pp',
  95. # # save_as=Path('/home/andraz/ChargedShells/Figures/nonmonotonicity_check_ep.pdf')
  96. # )
  97. IC_peak_energy_plot(config_data, a_bar=[0.2, 0.24, 0.36, 0.52, 0.8], which='pp',
  98. # save_as=Path('/home/andraz/ChargedShells/Figures/Emanuele_data/nonmonotonicity_check_ep.pdf')
  99. )