Tried to find the MN disk parameters from the particles' coordinate medians
This commit is contained in:
parent
c2051e9596
commit
80e6a8d635
4 changed files with 166 additions and 49 deletions
|
|
@ -61,11 +61,11 @@ d = sqrt(x**2 + y**2)
|
|||
# Cread a two-dimensional grid
|
||||
# The grid sizes don't _have to_ be equal in both directions, but there is some
|
||||
# logic in keeping them the same.
|
||||
n_grid = 16
|
||||
n_grid_d, n_grid_z = 16, 16
|
||||
d_max = 2*median(d)
|
||||
z_max = 2*median(abs(z))
|
||||
d_grid = linspace(0, d_max, n_grid+1)
|
||||
z_grid = linspace(0, z_max, n_grid+1)
|
||||
d_grid = linspace(0, d_max, n_grid_d+1)
|
||||
z_grid = linspace(0, z_max, n_grid_z+1)
|
||||
|
||||
# Calculates the mass in each (d,z)-cell
|
||||
# We fold negative z-values assuming symmetry with respect to the xy-plane
|
||||
|
|
@ -90,19 +90,23 @@ rho_mn = lambda d, z, M, a, b: \
|
|||
# The minimization procedure
|
||||
means = lambda arr: .5*(arr[:-1]+arr[1:]) # small helper function
|
||||
# Define a grid of the centre of each cell from the histogram we created earlier
|
||||
dd, zz = meshgrid(means(d_grid), means(z_grid))
|
||||
dd, zz = meshgrid(means(d_grid), means(z_grid), indexing='xy')
|
||||
def cost(args):
|
||||
f_plummer, b_plummer, a_mn, b_mn = args
|
||||
f_mn = 1 - f_plummer
|
||||
rho = rho_plummer(sqrt(dd**2+zz**2), f_plummer, b_plummer) + rho_mn(dd, zz, f_mn, a_mn, b_mn)
|
||||
a_mn, b_mn = args
|
||||
rho = rho_mn(dd, zz, 1, a_mn, b_mn)
|
||||
square_diff = (rho - rho_measured_normalized)**2
|
||||
return sum(square_diff)
|
||||
minimization_result = \
|
||||
scipy.optimize.minimize(cost, [0.5, rh, median(abs(z)), median(d)],
|
||||
method='Nelder-Mead', tol=1e-6, options={'maxiter':5000})
|
||||
f_plummer, b_plummer, a_mn, b_mn = minimization_result.x
|
||||
print(f'f_plummer = {f_plummer:.4f} b_plummer = {b_plummer:.4f} kpc a_mn = {a_mn:.4f} kpc b_mn = {b_mn:.4f} kpc')
|
||||
print(f'M_plummer = {f_plummer*M_tot:.2e} MSun M_mn = {(1-f_plummer)*M_tot:.2e} MSun')
|
||||
scipy.optimize.minimize(cost, [median(abs(z)), median(d)], method='Nelder-Mead', tol=1e-6, options={'maxiter':5000})
|
||||
a_mn, b_mn = minimization_result.x
|
||||
####
|
||||
if False:
|
||||
print('!!!Setting parameters artificially!!!')
|
||||
a_mn, b_mn = 2.98, 1.61
|
||||
####
|
||||
rho_best_fit = rho_mn(dd, zz, 1, a_mn, b_mn)
|
||||
print(f'a_mn = {a_mn:.4f} kpc b_mn = {b_mn:.4f} kpc')
|
||||
print(f'M_mn = {M_tot:.2e} MSun')
|
||||
|
||||
# Compare with Matteo's results
|
||||
with h5py.File(file_name, 'r') as f:
|
||||
|
|
@ -126,15 +130,14 @@ print(f'M_bulge = {M_matteo_bulge:.2e} MSun M_disk = {M_matteo_disk:.2e} MSun'
|
|||
print(f'rh_bulge = {rh_matteo_bulge:.4f} kpc (equivalent Plummer radius: {0.76642*rh_matteo_bulge:.4f}) kpc')
|
||||
|
||||
# Plot the density as a function of d for three values of z.
|
||||
f_mn = 1 - f_plummer
|
||||
rho = lambda d, z: rho_plummer(sqrt(d**2+z**2), f_plummer, b_plummer) + rho_mn(d, z, f_mn, a_mn, b_mn)
|
||||
rho = lambda d, z: rho_mn(d, z, 1, a_mn, b_mn)
|
||||
for c, i in enumerate([0, 3, 6, 9]):
|
||||
semilogy(dd[i,:], M_tot*rho_measured_normalized[i,:], c=f'C{c}', ls='-', label=f'h={1000*zz[i,0]:.0f} pc')
|
||||
semilogy(dd[i,:], M_tot*rho(dd[i,:], zz[i,0]), c=f'C{c}', ls='--', alpha=0.5)
|
||||
|
||||
legend()
|
||||
xlabel('x [kpc]')
|
||||
ylabel(r'$\rho\ [\rm M_\odot\ kpc^{-3}]$')
|
||||
legend()
|
||||
xlabel('x [kpc]')
|
||||
ylabel(r'$\rho\ [\rm M_\odot\ kpc^{-3}]$')
|
||||
|
||||
savefig('subhalo_411321_stellar_fit.png')
|
||||
show()
|
||||
savefig('subhalo_411321_stellar_fit.png')
|
||||
show()
|
||||
Loading…
Add table
Add a link
Reference in a new issue