path_plot.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. import numpy as np
  2. from charged_shells.rotational_path import PairRotationalPath, PathEnergyPlot
  3. from charged_shells import expansion
  4. from charged_shells.parameters import ModelParams
  5. import matplotlib.pyplot as plt
  6. from pathlib import Path
  7. import json
  8. import quadrupole_model_mappings
  9. Array = np.ndarray
  10. zero_to_pi_half = np.linspace(0, np.pi/2, 100, endpoint=True)
  11. pi_half_to_pi = np.linspace(np.pi/2, np.pi, 100, endpoint=True)
  12. QuadPath = PairRotationalPath()
  13. QuadPath.set_default_x_axis(zero_to_pi_half)
  14. QuadPath.add_euler(beta1=np.pi/2, beta2=zero_to_pi_half, start_name="EP", end_name="EE")
  15. QuadPath.add_euler(beta1=zero_to_pi_half[::-1], beta2=zero_to_pi_half[::-1], end_name="PP")
  16. QuadPath.add_euler(beta1=zero_to_pi_half, end_name="EP")
  17. QuadPath.add_euler(beta1=zero_to_pi_half[::-1], beta2=zero_to_pi_half, end_name="EP")
  18. QuadPath.add_euler(beta1=np.pi/2, beta2=zero_to_pi_half, alpha2=np.pi/2, end_name="tEE")
  19. QuadPath.add_euler(beta1=np.pi/2, beta2=np.pi/2, alpha1=zero_to_pi_half[::-1], end_name="EE")
  20. DipolePath = PairRotationalPath()
  21. DipolePath.set_default_x_axis(zero_to_pi_half)
  22. DipolePath.add_euler(beta2=pi_half_to_pi[::-1])
  23. DipolePath.add_euler(beta2=zero_to_pi_half[::-1])
  24. DipolePath.add_euler(beta2=zero_to_pi_half, beta1=zero_to_pi_half)
  25. DipolePath.add_euler(beta2=np.pi/2, beta1=np.pi/2, alpha2=zero_to_pi_half)
  26. DipolePath.add_euler(beta2=np.pi/2, alpha2=np.pi/2, beta1=pi_half_to_pi)
  27. DipolePath.add_euler(beta2=np.pi/2, beta1=pi_half_to_pi[::-1], alpha1=np.pi)
  28. DipolePath.add_euler(beta2=zero_to_pi_half[::-1], beta1=pi_half_to_pi, alpha1=np.pi)
  29. DipolePath.add_euler(beta2=zero_to_pi_half, beta1=pi_half_to_pi[::-1], alpha1=np.pi)
  30. DipolePath.add_euler(beta2=pi_half_to_pi, beta1=zero_to_pi_half[::-1], alpha1=np.pi)
  31. DipolePath2 = PairRotationalPath()
  32. DipolePath2.set_default_x_axis(zero_to_pi_half)
  33. DipolePath2.add_euler(beta2=pi_half_to_pi[::-1])
  34. DipolePath2.add_euler(beta2=zero_to_pi_half[::-1])
  35. DipolePath2.add_euler(beta2=zero_to_pi_half, beta1=zero_to_pi_half)
  36. DipolePath2.add_euler(beta2=np.pi/2, beta1=np.pi/2, alpha2=zero_to_pi_half)
  37. DipolePath2.add_euler(beta2=np.pi/2, alpha2=np.pi/2, beta1=pi_half_to_pi)
  38. DipolePath2.add_euler(beta2=zero_to_pi_half[::-1], beta1=pi_half_to_pi[::-1])
  39. DipolePath2.add_euler(beta2=zero_to_pi_half[::-1], beta1=np.pi)
  40. DipolePath2.add_euler(beta2=zero_to_pi_half, beta1=pi_half_to_pi[::-1], alpha1=np.pi)
  41. DipolePath2.add_euler(beta2=pi_half_to_pi, beta1=zero_to_pi_half[::-1], alpha1=np.pi)
  42. def model_comparison(config_data: dict, save_as=None, save_data=False):
  43. kappaR = 3
  44. params = ModelParams(R=150, kappaR=kappaR)
  45. a_bar = 0.5
  46. sigma_tilde = 0.001
  47. ex1 = expansion.MappedExpansionQuad(a_bar, params.kappaR, sigma_tilde, l_max=30)
  48. ex2 = ex1.clone()
  49. # matching other models to the mapped CSp model based on equal patch size in potential
  50. ex_gauss = quadrupole_model_mappings.ic_to_gauss(sigma_tilde, a_bar, params, l_max=30, sigma0=0)
  51. ex_gauss2 = ex_gauss.clone()
  52. ex_cap = quadrupole_model_mappings.ic_to_cap(sigma_tilde, a_bar, params, l_max=30, sigma0=0)
  53. ex_cap2 = ex_cap.clone()
  54. # path plots for all models
  55. path_plot = PathEnergyPlot(ex1, ex2, QuadPath, dist=2., params=params)
  56. energy = path_plot.evaluate_path()
  57. x_axis = path_plot.rot_path.stack_x_axes()
  58. path_plot_gauss = PathEnergyPlot(ex_gauss, ex_gauss2, QuadPath, dist=2., params=params)
  59. energy_gauss = path_plot_gauss.evaluate_path()
  60. path_plot_cap = PathEnergyPlot(ex_cap, ex_cap2, QuadPath, dist=2., params=params)
  61. energy_cap = path_plot_cap.evaluate_path()
  62. # peak_energy_sanity_check
  63. # ex1new = expansion.MappedExpansionQuad(abar, params.kappaR, sigma_tilde, l_max=30)
  64. # ex2new = ex1new.clone()
  65. # pp_energy = interactions.charged_shell_energy(ex1new, ex2new, params)
  66. # print(f'PP energy: {pp_energy}')
  67. # Emanuele data
  68. em_data = np.load(Path(config_data["emanuele_data"]).joinpath("FIG_7").joinpath("pathway.npz"))['arr_0']
  69. # em_data_path = (Path(config_data["emanuele_data"]).joinpath("FIG_8").joinpath("FIXEDCHARGE")
  70. # .joinpath("FIX_A").joinpath("ECC_0.25"))
  71. # em_data = np.load(em_data_path.joinpath(f"EMME_{kappaR}.").joinpath("pathway.npz"))['arr_0']
  72. if save_data:
  73. np.savez(Path(config_data["figure_data"]).joinpath(f"fig_7_kR{kappaR}.npz"),
  74. ICi=em_data,
  75. CSp=np.stack((x_axis, np.squeeze(energy))).T,
  76. CSp_gauss=np.stack((x_axis, np.squeeze(energy_gauss))).T,
  77. CSp_cap=np.stack((x_axis, np.squeeze(energy_cap))).T)
  78. fig, ax = plt.subplots(figsize=plt.figaspect(0.5))
  79. ax.plot(em_data[:, 0], em_data[:, 1], label='ICi')
  80. ax.plot(x_axis, np.squeeze(energy), label='CSp')
  81. # ax.plot(x_axis, np.squeeze(energy_gauss), label='CSp - Gauss')
  82. # ax.plot(x_axis, np.squeeze(energy_cap), label='CSp - cap')
  83. # ax.plot(x_axis, em_data[:, 1] / np.squeeze(energy), label='CSp')
  84. path_plot.plot_style(fig, ax)
  85. if save_as is not None:
  86. plt.savefig(save_as, dpi=600)
  87. plt.show()
  88. def kappaR_dependence(kappaR: Array, abar: float, sigma_tilde=0.001, save_as=None):
  89. params = ModelParams(R=150, kappaR=kappaR)
  90. ex1 = expansion.MappedExpansionQuad(abar, params.kappaR, sigma_tilde, l_max=30)
  91. ex2 = ex1.clone()
  92. path_plot = PathEnergyPlot(ex1, ex2, QuadPath, dist=2., params=params, match_expansion_axis_to_params=0)
  93. path_plot.plot(labels=[rf'$\kappa R$={kR}' for kR in kappaR],
  94. # norm_euler_angles={'beta2': np.pi},
  95. save_as=save_as)
  96. def abar_dependence(abar: Array, kappaR: float, sigma_tilde=0.001, save_as=None):
  97. params = ModelParams(R=150, kappaR=kappaR)
  98. ex1 = expansion.MappedExpansionQuad(abar, params.kappaR, sigma_tilde, l_max=30)
  99. ex2 = ex1.clone()
  100. path_plot = PathEnergyPlot(ex1, ex2, QuadPath, dist=2., params=params, match_expansion_axis_to_params=None)
  101. path_plot.plot(labels=[rf'$\bar a$={a}' for a in abar],
  102. # norm_euler_angles={'beta2': np.pi},
  103. save_as=save_as)
  104. def sigma0_dependence(sigma0: Array, kappaR: float, abar: float, sigma_tilde=0.001, save_as=None):
  105. params = ModelParams(R=150, kappaR=kappaR)
  106. ex1 = expansion.MappedExpansionQuad(abar, params.kappaR, sigma_tilde, l_max=30, sigma0=sigma0)
  107. ex2 = ex1.clone()
  108. path_plot = PathEnergyPlot(ex1, ex2, QuadPath, dist=2., params=params, match_expansion_axis_to_params=None)
  109. path_plot.plot(labels=[rf'$\eta={s0 / sigma_tilde}$' for s0 in sigma0],
  110. # norm_euler_angles={'beta2': np.pi},
  111. save_as=save_as)
  112. def distance_dependence(dist: Array, kappaR: float, abar: float, sigma_tilde=0.001, save_as=None):
  113. params = ModelParams(R=150, kappaR=kappaR)
  114. ex1 = expansion.MappedExpansionQuad(abar, params.kappaR, sigma_tilde, l_max=30)
  115. ex2 = ex1.clone()
  116. plots = []
  117. for d in dist:
  118. path_plot = PathEnergyPlot(ex1, ex2, QuadPath, dist=d, params=params)
  119. x = d * kappaR
  120. plots.append(path_plot.evaluate_path() * np.exp(x) * x)
  121. x_axis = path_plot.rot_path.stack_x_axes()
  122. labels = [rf'$\rho/R ={d}$' for d in dist]
  123. fig, ax = plt.subplots(figsize=plt.figaspect(0.5))
  124. for pl, lbl in zip(plots, labels):
  125. ax.plot(x_axis, pl, label=lbl)
  126. QuadPath.plot_style(fig, ax)
  127. ax.set_ylabel(r'$U \kappa\rho e^{\kappa\rho}$', fontsize=15)
  128. if save_as is not None:
  129. plt.savefig(save_as, dpi=600)
  130. plt.show()
  131. def IC_kappaR_dependence(config_data: dict, save_as=None):
  132. em_data_path = (Path(config_data["emanuele_data"]).joinpath("FIG_8").joinpath("FIXEDCHARGE")
  133. .joinpath("FIX_A").joinpath("ECC_0.25"))
  134. kR1 = np.load(em_data_path.joinpath("EMME_1.").joinpath("pathway.npz"))['arr_0']
  135. kR3 = np.load(em_data_path.joinpath("EMME_3.").joinpath("pathway.npz"))['arr_0']
  136. kR10 = np.load(em_data_path.joinpath("EMME_10.").joinpath("pathway.npz"))['arr_0']
  137. labels = [rf'$\kappa R$={kR}' for kR in [1, 3, 10]]
  138. fig, ax = plt.subplots()
  139. ax.plot(kR1[:, 0], kR1[:, 1], label=labels[0])
  140. ax.plot(kR3[:, 0], kR3[:, 1], label=labels[1])
  141. ax.plot(kR10[:, 0], kR10[:, 1], label=labels[2])
  142. QuadPath.plot_style(fig, ax)
  143. if save_as is not None:
  144. plt.savefig(save_as, dpi=600)
  145. plt.show()
  146. def IC_abar_dependence(config_data: dict, save_as=None):
  147. em_data_path = (Path(config_data["emanuele_data"]).joinpath("FIG_8").joinpath("FIXEDCHARGE").joinpath("FIX_M"))
  148. a03 = np.load(em_data_path.joinpath("ECC_0.15").joinpath("EMME_3.").joinpath("pathway.npz"))['arr_0']
  149. a04 = np.load(em_data_path.joinpath("ECC_0.2").joinpath("EMME_3.").joinpath("pathway.npz"))['arr_0']
  150. a05 = np.load(em_data_path.joinpath("ECC_0.25").joinpath("EMME_3.").joinpath("pathway.npz"))['arr_0']
  151. labels =[rf'$\bar a$={a}' for a in [0.3, 0.4, 0.5]]
  152. fig, ax = plt.subplots()
  153. ax.plot(a03[:, 0], a03[:, 1], label=labels[0])
  154. ax.plot(a04[:, 0], a04[:, 1], label=labels[1])
  155. ax.plot(a05[:, 0], a05[:, 1], label=labels[2])
  156. QuadPath.plot_style(fig, ax)
  157. if save_as is not None:
  158. plt.savefig(save_as, dpi=600)
  159. plt.show()
  160. def IC_sigma0_dependence(config_data: dict, save_as=None):
  161. em_data_path = (Path(config_data["emanuele_data"]).joinpath("FIG_8").joinpath("CHARGE_ZC"))
  162. undercharged = np.load(em_data_path.joinpath("ZC_-277.27").joinpath("pathway.npz"))['arr_0']
  163. neutral = np.load(em_data_path.joinpath("ZC_-560").joinpath("pathway.npz"))['arr_0']
  164. overchargerd = np.load(em_data_path.joinpath("ZC_-842.74").joinpath("pathway.npz"))['arr_0']
  165. labels = [rf'$\eta={eta}$' for eta in [-0.1, 0, 0.1]]
  166. fig, ax = plt.subplots()
  167. ax.plot(overchargerd[:, 0], overchargerd[:, 1], label=labels[0])
  168. ax.plot(neutral[:, 0], neutral[:, 1], label=labels[1])
  169. ax.plot(undercharged[:, 0], undercharged[:, 1], label=labels[2])
  170. QuadPath.plot_style(fig, ax)
  171. if save_as is not None:
  172. plt.savefig(save_as, dpi=600)
  173. plt.show()
  174. def main():
  175. with open(Path("/home/andraz/ChargedShells/charged-shells/config.json")) as config_file:
  176. config_data = json.load(config_file)
  177. # model_comparison(config_data, save_data=False,
  178. # save_as=Path(config_data["figures"]).joinpath("Emanuele_data").joinpath('IC_CS_quadrupole_path.pdf')
  179. # )
  180. # kappaR_dependence(np.array([1, 3, 10]), 0.5,
  181. # # save_as=Path("/home/andraz/ChargedShells/Figures/quadrupole_kappaR_dep.png")
  182. # )
  183. #
  184. # abar_dependence(np.array([0.3, 0.4, 0.5]), 3,
  185. # save_as=Path("/home/andraz/ChargedShells/Figures/quadrupole_abar_dep.png")
  186. # )
  187. # sigma0_dependence(np.array([-0.001, 0.00, 0.001]), 3, 0.5,
  188. # save_as=Path("/home/andraz/ChargedShells/Figures/quadrupole_charge_dep_abar05_kappaR3.png")
  189. # )
  190. # distance_dependence(dist=np.array([2, 3, 4, 6, 10, 20]), kappaR=3, abar=0.5,
  191. # # save_as=Path(config_data["figures"]).joinpath('quadrupole_distance_dep.png')
  192. # )
  193. # IC_kappaR_dependence(config_data,
  194. # save_as=Path(config_data["figures"]).joinpath("Emanuele_data").joinpath('quadrupole_kappaR_dep.png')
  195. # )
  196. #
  197. # IC_abar_dependence(config_data, save_as=Path(config_data["figures"]).joinpath("Emanuele_data").
  198. # joinpath('quadrupole_abar_dep.png'))
  199. #
  200. IC_sigma0_dependence(config_data, save_as=Path(config_data["figures"]).joinpath("Emanuele_data").
  201. joinpath('quadrupole_charge_dep_abar05_kappaR3.png'))
  202. if __name__ == '__main__':
  203. main()