Fixed a bug with finding the disk's direction (and added an angular momentum test to be sure); added a Jupyter notebook for plotting the results

This commit is contained in:
Yohai Meiron 2020-04-25 22:56:12 -04:00
parent efdb0ea425
commit cb66caf6ba
2 changed files with 323 additions and 16 deletions

View file

@ -43,8 +43,10 @@ def get_half_mass_radius(m, r):
j = searchsorted(m_cum, m_cum[-1]/2)
return r_sorted[j] # close enough
def get_transformation(m, X):
X_center = def_dc(m, X)
def get_transformation(m, X, V=None):
V_center = None
if not V is None: X_center, V_center = def_dc(m, X, V)
else: X_center = def_dc(m, X)
X_shifted = X - X_center
r = linalg.norm(X_shifted, axis=1)
rh = get_half_mass_radius(m, r)
@ -52,7 +54,7 @@ def get_transformation(m, X):
Q = ellipsoids.quadrupole_tensor(*X_shifted[mask].T, m[mask])
eigenvalues, eigenvectors = linalg.eig(Q)
R = ellipsoids.rotation_matrix_from_eigenvectors(eigenvectors, eigenvalues)
return X_center, R, mask
return X_center, V_center, R, mask
f = h5py.File(file_name, 'r')
@ -60,7 +62,7 @@ f = h5py.File(file_name, 'r')
i, snapshot = len(snap)-1, snap[-1]
m = f[str(snapshot)][particle_types['stars']]['Masses'][...]
X = f[str(snapshot)][particle_types['stars']]['Coordinates'][...] * a[i] / h0
X_center_glob, R_glob, _ = get_transformation(m, X)
X_center_glob, _, R_glob, _ = get_transformation(m, X)
for i in range(len(snap)):
snapshot = snap[0] + i
@ -72,23 +74,28 @@ for i in range(len(snap)):
m = append(m_dm, m_gas)
X = vstack([X_dm, X_gas])
X -= X_center_glob # NOTE we don't rotate here because we assume spherical symmetry
X = (R_glob @ (X - X_center_glob).T).T
X_center_halo = def_dc(m, X)
r = linalg.norm(X, axis=1)
r = linalg.norm(X-X_center_halo, axis=1)
rh = get_half_mass_radius(m, r)
b_halo = 0.76642093654*rh
M_halo = sum(m)
particle_type = 'stars'
m = f[str(snapshot)][particle_types[particle_type]]['Masses'][...]
X = f[str(snapshot)][particle_types[particle_type]]['Coordinates'][...] * a[i] / h0
m = f[str(snapshot)][particle_types['stars']]['Masses'][...]
X = f[str(snapshot)][particle_types['stars']]['Coordinates'][...] * a[i] / h0
V = f[str(snapshot)][particle_types['stars']]['Velocities'][...] * sqrt(a[i])
X = (R_glob @ (X - X_center_glob).T).T
V = (R_glob @ V.T).T
X_center_stars, R, mask = get_transformation(m, X)
direction = R[0,:]
X_center_stars, V_center_stars, R, mask = get_transformation(m, X, V)
direction = R[2,:]
if direction[2] < 0: direction = -direction
phi = arctan2(direction[1], direction[0])
theta = arccos(direction[2]/linalg.norm(direction))
theta_inertia = arccos(direction[2]/linalg.norm(direction))
phi_inertia = arctan2(direction[1], direction[0])
L = cross(X-X_center_stars, V-V_center_stars)
L = sum(L[mask], axis=0)
phi_L = arctan2(L[1], L[0])
theta_L = arccos(L[2]/linalg.norm(L))
X_new = (R @ (X - X_center_stars).T).T
x, y, z = X_new.T
@ -96,8 +103,6 @@ for i in range(len(snap)):
m_d = median(sqrt(x[mask]**2+y[mask]**2))
a_mn, b_mn = miyamoto_nagai_params_from_medians(m_d, m_z)
M_disk = sum(m)
print('%d %.8E %.8E %15.8E %15.8E %15.8E %15.8E %15.8E %.8E %.8E %.8E %15.8E %15.8E %15.8E %15.8E' % (snapshot, t[i], M_disk, *X_center_stars, phi, theta, a_mn, b_mn, M_halo, *X_center_halo, b_halo))
print('%d %.8E %.8E %15.8E %15.8E %15.8E %15.8E %15.8E %15.8E %15.8E %.8E %.8E %.8E %15.8E %15.8E %15.8E %15.8E' % (snapshot, t[i], M_disk, *X_center_stars, phi_inertia, theta_inertia, phi_L, theta_L, a_mn, b_mn, M_halo, *X_center_halo, b_halo))
f.close()

File diff suppressed because one or more lines are too long