peak_heigth_janus.py 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. from matplotlib import gridspec
  2. from charged_shells import expansion, interactions, mapping, functions
  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. from plot_settings import *
  10. from dataclasses import dataclass
  11. import peak_heigth
  12. Array = np.ndarray
  13. Expansion = expansion.Expansion
  14. class JanusPeakPP(peak_heigth.Peak):
  15. def __init__(self, ex: Expansion, log_y: bool = False, kappaR_axis_in_expansion: int = None):
  16. self.emanuele_data_column = 3
  17. self.y_label = r'$V_\mathrm{PP, 1}$'
  18. self.ex1 = ex.clone()
  19. self.ex2 = ex.clone()
  20. self.ex1.rotate_euler(beta=np.pi, alpha=0, gamma=0)
  21. self.ex2.rotate_euler(beta=np.pi, alpha=0, gamma=0)
  22. self.log_y = log_y
  23. self.kappaR_axis_in_expansion = kappaR_axis_in_expansion
  24. class JanusPeakPPinv(peak_heigth.Peak):
  25. def __init__(self, ex: Expansion, log_y: bool = False, kappaR_axis_in_expansion: int = None):
  26. self.emanuele_data_column = 4
  27. self.y_label = r'$V_\mathrm{PP, 2}$'
  28. self.ex1 = ex.clone()
  29. self.ex2 = ex.clone().inverse_sign(exclude_00=True)
  30. self.ex1.rotate_euler(beta=np.pi, alpha=0, gamma=0)
  31. self.ex2.rotate_euler(beta=np.pi, alpha=0, gamma=0)
  32. self.log_y = log_y
  33. self.kappaR_axis_in_expansion = kappaR_axis_in_expansion
  34. class JanusPeakEP(peak_heigth.Peak):
  35. def __init__(self, ex: Expansion, log_y: bool = False, kappaR_axis_in_expansion: int = None):
  36. self.emanuele_data_column = 4
  37. self.y_label = r'$V_{EP, 1}$'
  38. self.ex1 = ex.clone()
  39. self.ex2 = ex.clone()
  40. self.ex1.rotate_euler(beta=np.pi/2, alpha=0, gamma=0)
  41. self.ex2.rotate_euler(beta=np.pi/2, alpha=0, gamma=0)
  42. self.log_y = log_y
  43. self.kappaR_axis_in_expansion = kappaR_axis_in_expansion
  44. class JanusPeakEPinv(peak_heigth.Peak):
  45. def __init__(self, ex: Expansion, log_y: bool = False, kappaR_axis_in_expansion: int = None):
  46. self.emanuele_data_column = 4
  47. self.y_label = r'$V_{EP, 2}$'
  48. self.ex1 = ex.clone()
  49. self.ex2 = ex.clone().inverse_sign(exclude_00=True)
  50. self.ex1.rotate_euler(beta=np.pi/2, alpha=0, gamma=0)
  51. self.ex2.rotate_euler(beta=np.pi/2, alpha=0, gamma=0)
  52. self.log_y = log_y
  53. self.kappaR_axis_in_expansion = kappaR_axis_in_expansion
  54. def get_charge_energy_dicts(peak: peak_heigth.Peak, params: ModelParams, emanuele_data: Array, sigma0: Array, abar_cs: list, sigma_tilde=0.001):
  55. abar_ic, inverse, counts = np.unique(emanuele_data[:, 1], return_counts=True, return_inverse=True)
  56. # abar_ic = [0.1, 0.2, 0.3]
  57. energy_fn = mapping.parameter_map_two_expansions(partial(interactions.charged_shell_energy, dist=2),
  58. peak.kappaR_axis_in_expansion)
  59. energy = energy_fn(peak.ex1, peak.ex2, params)
  60. data_dict_ic = {}
  61. data_dict_cs = {}
  62. k = 0
  63. for i in range(len(abar_ic)):
  64. ab = np.around(abar_ic[i], 5)
  65. if ab in np.around(abar_cs, 5):
  66. idx, = np.nonzero(inverse == i)
  67. charge = emanuele_data[idx, 0]
  68. en = emanuele_data[idx, peak.emanuele_data_column]
  69. sort = np.argsort(charge)
  70. if peak.log_y:
  71. data_dict_ic[ab] = np.stack((charge[sort], np.abs(en)[sort])).T
  72. data_dict_cs[ab] = np.stack((sigma0 / sigma_tilde, np.abs(energy[k]))).T
  73. else:
  74. data_dict_ic[ab] = np.stack((charge[sort], en[sort])).T
  75. data_dict_cs[ab] = np.stack((sigma0 / sigma_tilde, energy[k])).T
  76. k += 1
  77. return data_dict_ic, data_dict_cs
  78. def IC_peak_energy_charge_combined_plot(config_data: dict,
  79. a_bar: list,
  80. R: float = 150,
  81. save_as: Path = None,
  82. log_y: bool = False):
  83. # em_data_path = (Path(config_data["emanuele_data"]).joinpath("FIG_11"))
  84. em_data_path = (Path(config_data["emanuele_data"]).joinpath("FIG_5_JANUS")).joinpath("FIG_5_JANUS_NEW_CHARGE")
  85. em_data = np.load(em_data_path.joinpath("pair_energy_PP_janus.npz"))
  86. data = em_data['changezc']
  87. params = ModelParams(R=R, kappaR=3)
  88. sigma0 = np.linspace(-0.00099, 0.00099, 300)
  89. sigma_tilde = 0.00099
  90. ex = expansion.MappedExpansionDipole(np.sort(np.array(a_bar)), # sorting necessary as it is also in energy_dicts()
  91. kappaR=3, sigma0=sigma0, l_max=20, sigma_tilde=sigma_tilde)
  92. peak_pp = JanusPeakPP(ex, log_y)
  93. peak_pp_inv = JanusPeakPPinv(ex, log_y)
  94. peaks = [peak_pp, peak_pp_inv]
  95. # peak_ep = JanusPeakEP(ex, log_y)
  96. # peak_ep_inv = JanusPeakEPinv(ex, log_y)
  97. # peaks = [peak_ep, peak_ep_inv]
  98. data_ic = []
  99. data_cs = []
  100. for peak in peaks:
  101. dict_ic, dict_cs = get_charge_energy_dicts(peak, params, data, sigma0, a_bar, sigma_tilde)
  102. data_ic.append(dict_ic)
  103. data_cs.append(dict_cs)
  104. # fig, axs = plt.subplots(3, 1, figsize=(3, 7.8))
  105. fig = plt.figure(figsize=(4, 1.7))
  106. gs = gridspec.GridSpec(1, 2, figure=fig)
  107. gs.update(left=0.125, right=0.975, top=0.99, bottom=0.21, wspace=0.35)
  108. axs = [fig.add_subplot(gs[0, 0]), fig.add_subplot(gs[0, 1])]
  109. for ax, data_dict_ic, data_dict_cs, peak in zip(axs, data_ic, data_cs, peaks):
  110. colors = cycle(plt.rcParams['axes.prop_cycle'].by_key()['color'])
  111. for ab in a_bar:
  112. key = np.around(ab, 5)
  113. current_color = next(colors)
  114. ax.plot(data_dict_ic[key][:, 0], data_dict_ic[key][:, 1], label=rf'$\bar a = {key:.1f}$', c=current_color, linewidth=1.5)
  115. ax.plot(data_dict_cs[key][:, 0], data_dict_cs[key][:, 1], ls='--', c=current_color, linewidth=1.5,
  116. # label=rf'$\bar a = {key:.1f}$'
  117. )
  118. ax.legend(fontsize=9, ncol=1, frameon=False, handlelength=0.7, loc='upper right',
  119. bbox_to_anchor=(0.75, 1.03),
  120. )
  121. ax.tick_params(which='both', direction='in', top=True, right=True, labelsize=11)
  122. # if ax == axs[-1]:
  123. ax.set_xlabel(r'$\eta$', fontsize=11)
  124. ax.set_ylabel(peak.y_label, fontsize=11)
  125. if peak.log_y:
  126. ax.set_yscale('log')
  127. # ax.set_xscale('log')
  128. ax.yaxis.set_label_coords(-0.18, 0.5)
  129. ax.xaxis.set_label_coords(0.5, -0.12)
  130. axs[0].set_ylim(-23, 23)
  131. # plt.subplots_adjust(left=0.3)
  132. # plt.tight_layout()
  133. if save_as is not None:
  134. plt.savefig(save_as, dpi=300)
  135. plt.show()
  136. def main():
  137. with open(Path("/home/andraz/ChargedShells/charged-shells/config.json")) as config_file:
  138. config_data = json.load(config_file)
  139. a_bar = [0.2, 0.5, 0.8]
  140. # IC_peak_energy_kappaR_combined_plot(config_data, a_bar,
  141. # save_as=Path(
  142. # '/home/andraz/ChargedShells/Figures/final_figures/peak_combined_kappaR.png')
  143. # )
  144. # a_bar = [0.1, 0.2, 0.3]
  145. # IC_peak_energy_charge_combined_plot(config_data, a_bar,
  146. # save_as=Path('/home/andraz/ChargedShells/Figures/final_figures/janus_peak_combined_charge.png')
  147. # )
  148. if __name__ == '__main__':
  149. main()