def bound_mass_evolution(prop, output, max_time=None): plt.clf() times = nbody_tools.get_times(prop['simFileGRAVOUTPUT']) if (max_time): times = times[times < max_time] mass_dm = np.ones(len(times)) mass_st = np.ones(len(times)) for i, t in enumerate(times): data, centre = grab_snapshot(prop, t, with_centre=True) data = data_to_pandas(data) mass_dm[i] = np.sum(data.mass[data.dm == 1.]) mass_st[i] = np.sum(data.mass[data.dm == 0.]) plt.plot(times, mass_dm / mass_dm[0], ls='dotted', label='DM') plt.plot(times, mass_st / mass_st[0], ls='dashed', label='Stars') plt.plot(times, (mass_st + mass_dm) / (mass_dm[0] + mass_st[0]), color='k', label='Total') plt.xlabel(r'$t/\mathrm{Gyr}$') plt.ylabel(r'$M/M_\mathrm{init}$') plt.legend() plt.semilogy() plt.savefig(output, bbox_inches='tight')
def shape_evolution(prop, output, max_time=None): plt.clf() times = nbody_tools.get_times(prop['simFileGRAVOUTPUT']) if (max_time): times = times[times < max_time] ba_dm = np.ones(len(times)) ca_dm = np.ones_like(ba_dm) align_dm = np.ones_like(ba_dm) ba_st = np.ones(len(times)) ca_st = np.ones_like(ba_st) align_st = np.ones_like(ba_st) for i, t in enumerate(times): data, centre = grab_snapshot(prop, t, with_centre=True) if not len(data): continue data = data_to_pandas(data) ba_st[i], ca_st[i], pr = moment_of_inertia_diagonalization( data[data.dm == 0.], # no offset 0., 0., 0., reduced=True)[:3] align_st[i] = np.abs( np.dot(pr, centre[:3]) / np.sqrt(np.sum(centre[:3]**2))) ba_dm[i], ca_dm[i], pr = moment_of_inertia_diagonalization( data[data.dm == 1.], # no offset 0., 0., 0., reduced=True)[:3] align_dm[i] = np.abs( np.dot(pr, centre[:3]) / np.sqrt(np.sum(centre[:3]**2))) # times/=nbody_tools.kms2kpcGyr return shape_evolution_plot(output, ba_dm, ca_dm, align_dm, ba_st, ca_st, align_st, times)
def all_evolution(prop, max_time=None, prune_radius=None): plt.clf() times = nbody_tools.get_times(prop['simFileGRAVOUTPUT']) if (max_time): times = times[times < max_time] mass_dm = np.ones(len(times)) mass_st = np.ones(len(times)) mass_dm_core = np.ones(len(times)) mass_st_core = np.ones(len(times)) mass_dm_core_init = np.ones(len(times)) mass_st_core_init = np.ones(len(times)) mass_dm_core_tilde = np.ones(len(times)) mass_st_core_tilde = np.ones(len(times)) ba_dm = np.ones(len(times)) ca_dm = np.ones_like(ba_dm) align_dm = np.ones_like(ba_dm) ba_st = np.ones(len(times)) ca_st = np.ones_like(ba_st) align_st = np.ones_like(ba_st) r_half = np.zeros_like(ba_st) eps = np.ones_like(ba_st) r_core = np.zeros_like(ba_st) eps_king = np.ones_like(ba_st) c_king = np.ones_like(ba_st) sig_maj = np.zeros_like(ba_st) sig_int = np.zeros_like(ba_st) sig_min = np.zeros_like(ba_st) sig_proj = np.zeros_like(ba_st) sig_proj_flat = np.zeros_like(ba_st) centre_x = np.zeros_like(ba_st) centre_y = np.zeros_like(ba_st) centre_z = np.zeros_like(ba_st) centre_vx = np.zeros_like(ba_st) centre_vy = np.zeros_like(ba_st) centre_vz = np.zeros_like(ba_st) eq_centre_s = np.zeros_like(ba_st) eq_centre_vlos = np.zeros_like(ba_st) for i, t in enumerate(times): data, centre = grab_snapshot(prop, t, with_centre=True) if not len(data): continue data = data_to_pandas(data) ba_dm[i], ca_dm[ i], pmaj, pint, pmin = moment_of_inertia_diagonalization( data[data.dm == 1.], # no offset 0., 0., 0., reduced=True) align_dm[i] = np.abs( np.dot(pmaj, centre[:3]) / np.sqrt(np.sum(centre[:3]**2))) ba_st[i], ca_st[ i], pmaj, pint, pmin = moment_of_inertia_diagonalization( data[data.dm == 0.], # no offset 0., 0., 0., reduced=True) align_st[i] = np.abs( np.dot(pmaj, centre[:3]) / np.sqrt(np.sum(centre[:3]**2))) xtil = np.sum(pmaj * data.values.T[1:4].T, axis=1) ytil = np.sum(pint * data.values.T[1:4].T, axis=1) ztil = np.sum(pmin * data.values.T[1:4].T, axis=1) if np.count_nonzero(data.dm == 0.): vmaj = np.sum(pmaj * data[data.dm == 0.].values.T[4:7].T, axis=1) vint = np.sum(pint * data[data.dm == 0.].values.T[4:7].T, axis=1) vmin = np.sum(pmin * data[data.dm == 0.].values.T[4:7].T, axis=1) vmaj -= np.sum(data.mass[data.dm == 0.] * vmaj) / np.sum( data.mass[data.dm == 0.]) vint -= np.sum(data.mass[data.dm == 0.] * vint) / np.sum( data.mass[data.dm == 0.]) vmin -= np.sum(data.mass[data.dm == 0.] * vmin) / np.sum( data.mass[data.dm == 0.]) sig_maj[i] = np.sqrt( np.sum(data.mass[data.dm == 0.] * vmaj**2) / np.sum(data.mass[data.dm == 0.])) sig_int[i] = np.sqrt( np.sum(data.mass[data.dm == 0.] * vint**2) / np.sum(data.mass[data.dm == 0.])) sig_min[i] = np.sqrt( np.sum(data.mass[data.dm == 0.] * vmin**2) / np.sum(data.mass[data.dm == 0.])) mass_dm[i] = np.sum(data.mass[data.dm == 1.]) mass_st[i] = np.sum(data.mass[data.dm == 0.]) radii = np.sqrt(data.x**2 + data.y**2 + data.z**2) radii_tilde = np.sqrt(xtil**2 + (ytil / ba_st[i])**2 + (ztil / ca_st[i])**2) mass_dm_core_init[i] = np.sum(data.mass[(data.dm == 1.) & (radii < prop['rs'])]) mass_st_core_init[i] = np.sum(data.mass[(data.dm == 0.) & (radii < prop['rs'])]) # data,centre = grab_snapshot(prop,t,with_centre=True,recentre_sim=False) # data = data_to_pandas(data) data_recentre = recentre(data.values[:, :7], centre=-np.copy(centre)) for ii, nn in enumerate(['x', 'y', 'z', 'vx', 'vy', 'vz']): data[nn] = data_recentre[:, ii + 1] if np.count_nonzero(data.dm == 0.): results, xtmp, ytmp = nbody_tools.fit_surface_density( data[data.dm == 0.].values, centre=np.copy(centre)) r_half[i] = results[0] eps[i] = results[1] results, xtmp, ytmp = nbody_tools.fit_surface_density( data[data.dm == 0.].values, centre=np.copy(centre), profile="King") r_core[i] = results[0] eps_king[i] = results[1] c_king[i] = results[-1] print '#######################' print 'King fit ##############' print r_core[i], c_king[i] print '#######################' mass_dm_core[i] = np.sum(data.mass[(data.dm == 1.) & (radii < r_half[i])]) mass_st_core[i] = np.sum(data.mass[(data.dm == 0.) & (radii < r_half[i])]) mass_dm_core_tilde[i] = np.sum(data.mass[(data.dm == 1.) & (radii_tilde < r_half[i])]) mass_st_core_tilde[i] = np.sum(data.mass[(data.dm == 0.) & (radii_tilde < r_half[i])]) ## Solar velocity doesn't matter here eq = np.array([ aa_py.CartesianToGalactic( ii[1:7], np.array([8.2, 0., 0., 11.1, 240., 7.25])) for ii in data[data.dm == 0.].values ]) eq_centre = aa_py.CartesianToGalactic( centre[:6], np.array([8.2, 0., 0., 11.1, 240., 7.25])) from scipy.optimize import minimize from scipy.misc import logsumexp def logl(p, x): if p[1] < 0. or p[3] < 0. or p[-1] < 0. or p[-1] > 1.: return np.inf return -np.sum( np.logaddexp( -(x - p[0])**2 / 2. / p[1]**2 - .5 * np.log(p[1]**2) + np.log(1. - p[-1]), (-(x - p[2])**2 / 2. / p[3]**2 - .5 * np.log(p[3]**2) + np.log(p[-1])))) if np.count_nonzero(data.dm == 0.): ## Changed this to see if it makes a difference vproj = eq.T[3] - eq_centre[3] vproj -= np.sum(data.mass[data.dm == 0.] * vproj) / np.sum( data.mass[data.dm == 0.]) Rvec = centre[:3] - np.array([8.2, 0., 0.]) Rvec /= np.sqrt(np.sum(Rvec**2)) vprojR = data.vx * Rvec[0] + data.vy * Rvec[1] + data.vz * Rvec[2] vprojR = vprojR[data.dm == 0] vprojR -= np.sum(data.mass[data.dm == 0.] * vprojR) / np.sum( data.mass[data.dm == 0.]) sig_proj[i] = minimize( logl, [0.05, sig_maj[i], 0.05, 2. * sig_maj[i], 0.2], args=(vproj, )).x[1] sig_proj_flat[i] = minimize( logl, [0.05, sig_maj[i], 0.05, 2. * sig_maj[i], 0.2], args=(vprojR, )).x[1] # sig_proj[i]=np.sqrt(np.sum(data.mass[data.dm==0.]*vproj**2)/np.sum(data.mass[data.dm==0.])) # print i, sig_maj[i], sig_min[i], sig_proj[i], centre, eq_centre, np.count_nonzero(data.dm==0.) print '#####################' print t, r_half[i], sig_proj[i] print '#####################' centre_x[i] = centre[0] centre_y[i] = centre[1] centre_z[i] = centre[2] centre_vx[i] = centre[3] centre_vy[i] = centre[4] centre_vz[i] = centre[5] eq_centre_s[i] = eq_centre[2] eq_centre_vlos[i] = eq_centre[3] # times/=nbody_tools.kms2kpcGyr names = [ 'times', 'mass_dm', 'mass_st', 'ba_dm', 'ca_dm', 'align_dm', 'ba_st', 'ca_st', 'align_st', 'r_half', 'eps', 'r_core', 'eps_king', 'c_king', 'sig_maj', 'sig_int', 'sig_min', 'sig_proj', 'sig_proj_flat', 'mass_dm_core', 'mass_st_core', 'mass_dm_core_tilde', 'mass_st_core_tilde', 'mass_dm_core_init', 'mass_st_core_init', 'x', 'y', 'z', 'vx', 'vy', 'vz', 's', 'vlos' ] outputs = np.vstack( (times, mass_dm, mass_st, ba_dm, ca_dm, align_dm, ba_st, ca_st, align_st, r_half, eps, r_core, eps_king, c_king, sig_maj, sig_int, sig_min, sig_proj, sig_proj_flat, mass_dm_core, mass_st_core, mass_dm_core_tilde, mass_st_core_tilde, mass_dm_core_init, mass_st_core_init, centre_x, centre_y, centre_z, centre_vx, centre_vy, centre_vz, eq_centre_s, eq_centre_vlos)) return pd.DataFrame(outputs.T, columns=names)
propermotions = [caldwell_propermotion, [0., 0.], [0., 0.17]] rot = [[84., 208., 0.]] veldisp = 10. if __name__ == '__main__': for p in list(itertools.product(*[segregation, propermotions, shapes])): print p simproperties = generate_simproperties(SegregationParameter=p[0], propermotion=p[1], flattening=p[2], fixed_veldisp=veldisp) generate_plum_in_nfw(simproperties, nmax=20, int_step_frac=50.) times = nbody_tools.get_times(simproperties['simFileGRAVOUTPUT']) # compare_1d_profiles_2(simproperties, # simproperties['sim_name'] + '1dprof.pdf', # times=[0., times[-1]]) # compare_1d_sigmar_profiles_2(simproperties, # simproperties['sim_name'] + # '1dsrprof.pdf', # times=[0., times[-1]], sigmayaxis=100.) # shape_evolution(simproperties, # simproperties['sim_name'] + 'shape.pdf', # max_time=times[-1]) # bound_mass_evolution(simproperties, # simproperties['sim_name'] + 'mass.pdf', # max_time=times[-1])