1
0

H1line.py 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. """Compare the H1 observations of the Antennae to the simulation"""
  2. import matplotlib.pyplot as plt
  3. import numpy as np
  4. from analysis import utils
  5. # These paremeters were checked by running an interactive version of this function
  6. def plot2d(i=135, theta=1.86, phi=4.10, view=5.10, scaling=12, v_scaling=150, v_offset=43, x_offset=-4, y_offset=2):
  7. """Plot an encounter
  8. Parameters:
  9. i (int): timestep
  10. theta (float): polar angle
  11. phi (float): azimuthal angle
  12. view (float): rotation along line of sight
  13. scaling (float): scaling of the position vectors
  14. v_scaling (float): scaling of the line of sight velocity
  15. v_offset (float): offset of the line of sight velocity
  16. x_offset (float): position offset in the x direction
  17. y_offset (float): position offset in the y direction
  18. """
  19. data = utils.loadData('antennae', 13500)
  20. r_vec, v_vec = data['r_vec'], data['v_vec']*v_scaling
  21. mask = data['type'][:,0] == 'disk'
  22. r_vec, v_vec = r_vec[mask], v_vec[mask]
  23. # Viewing angles
  24. M1 = np.array([[1, 0, 0],
  25. [0, np.cos(theta), np.sin(theta)],
  26. [0, -np.sin(theta), np.cos(theta)]])
  27. M2 = np.array([[np.cos(phi), np.sin(phi), 0],
  28. [-np.sin(phi), np.cos(phi), 0],
  29. [0, 0, 1]])
  30. M3 = np.array([[np.cos(view), np.sin(view), 0],
  31. [-np.sin(view), np.cos(view), 0],
  32. [0, 0, 1]])
  33. M = np.matmul(M2, np.matmul(M1, M3))
  34. r_vec = np.tensordot(r_vec, M, axes=[1,0])
  35. v_vec = np.tensordot(v_vec, M, axes=[1,0])
  36. # Offsets
  37. r_vec[:,0] = r_vec[:,0]*scaling + x_offset
  38. r_vec[:,1] = r_vec[:,1]*scaling + y_offset
  39. v_vec[:,2] += v_offset
  40. f, axs = plt.subplots(2, 2, figsize=((11+14/1.97)/2, (14+11/1.54)/2),
  41. gridspec_kw = {'width_ratios':[11, 14/1.97], 'height_ratios':[14, 11/1.54]})
  42. # Plot background images
  43. # We manually derive the region that must be plotted based on
  44. # the data from Hibbard
  45. axs[0,0].imshow(plt.imread('literature/figs/hibbard1.png'),
  46. extent=[-58.2, 88.6, -86.5, 78.7])
  47. axs[1,0].imshow(plt.imread('literature/figs/hibbard3.png'),
  48. extent=[-58.2, 88.6, -270, 310])
  49. axs[0,1].imshow(plt.imread('literature/figs/hibbard2.png'),
  50. extent=[-270, 310, -86.5, 78.7])
  51. # Plot
  52. axs[0,0].scatter(r_vec[:,0], r_vec[:,1], s=3, edgecolor='', alpha=3E-1)
  53. axs[1,0].scatter(r_vec[:,0], v_vec[:,2], s=3, edgecolor='', alpha=3E-1)
  54. axs[0,1].scatter(v_vec[:,2], r_vec[:,1], s=3, edgecolor='', alpha=3E-1)
  55. f.subplots_adjust(hspace=0, wspace=0)
  56. # Get the correct scales on all axes
  57. axs[0,0].set_xlim((-58.2, 88.6))
  58. axs[0,0].set_ylim((-86.5, 78.7))
  59. axs[1,0].set_xlim((-58.2, 88.6))
  60. axs[1,0].set_ylim((-270, 310))
  61. axs[1,0].set_aspect((88.6 + 58.2)/(270+310) / 1.54)
  62. axs[0,1].set_ylim((-86.5, 78.7))
  63. axs[0,1].set_xlim((-270, 310))
  64. axs[0,1].set_aspect((270+310)/(86.5 + 78.7) * 1.97)
  65. axs[1,1].axis('off')
  66. # Styling
  67. utils.stylizePlot(axs.flatten())
  68. axs[0,1].set_xlabel(r'$v_{los}$ / km s$^{-1}$', fontsize=14)
  69. axs[1,0].set_ylabel(r'$v_{los}$ / km s$^{-1}$', fontsize=14)
  70. axs[1,0].set_xlabel(r'$x$ / kpc', fontsize=14)
  71. axs[0,0].set_ylabel(r'$y$ / kpc', fontsize=14)
  72. plt.show()
  73. plot2d()