def test_staeckel_fudge_delta(): import galpy.potential as galpy_pot from galpy.actionAngle import estimateDeltaStaeckel ro = 8.1 * u.kpc vo = 229 * u.km / u.s paired_potentials = [] # Miyamoto-Nagai potential = gp.MiyamotoNagaiPotential(m=6e10 * u.Msun, a=3 * u.kpc, b=0.3 * u.kpc, units=galactic) amp = (G * potential.parameters['m']).to_value(vo**2 * ro) a = potential.parameters['a'].to_value(ro) b = potential.parameters['b'].to_value(ro) galpy_potential = galpy_pot.MiyamotoNagaiPotential(amp=amp, a=a, b=b, ro=ro, vo=vo) paired_potentials.append((potential, galpy_potential)) # Hernquist potential = gp.HernquistPotential(m=6e10 * u.Msun, c=0.3 * u.kpc, units=galactic) amp = (G * potential.parameters['m']).to_value(vo**2 * ro) a = potential.parameters['c'].to_value(ro) galpy_potential = galpy_pot.HernquistPotential(amp=amp, a=a, ro=ro, vo=vo) paired_potentials.append((potential, galpy_potential)) # NFW potential = gp.NFWPotential(m=6e11 * u.Msun, r_s=15.6 * u.kpc, units=galactic) amp = (G * potential.parameters['m']).to_value(vo**2 * ro) a = potential.parameters['r_s'].to_value(ro) galpy_potential = galpy_pot.NFWPotential(amp=amp, a=a, ro=ro, vo=vo) paired_potentials.append((potential, galpy_potential)) # TEST: N = 1024 rnd = np.random.default_rng(42) w = PhaseSpacePosition(pos=rnd.uniform(-10, 10, size=(3, N)) * u.kpc, vel=rnd.uniform(-100, 100, size=(3, N)) * u.km / u.s) R = w.cylindrical.rho.to_value(ro) z = w.z.to_value(ro) for p, galpy_p in paired_potentials: galpy_deltas = estimateDeltaStaeckel(galpy_p, R, z, no_median=True) gala_deltas = get_staeckel_fudge_delta(p, w).value print(p, np.allclose(gala_deltas, galpy_deltas)) assert np.allclose(gala_deltas, galpy_deltas, atol=1e-6)
def test_orbit_to_fs(): potential = gp.NFWPotential(m=1E12, r_s=15, b=0.9, c=0.8, units=galactic) w0 = gd.CartesianPhaseSpacePosition(pos=[1., 0, 0] * u.kpc, vel=[30., 150, 71] * u.km / u.s) P = 40 * u.Myr orbit = potential.integrate_orbit(w0, dt=P / 128, t1=0 * u.Myr, t2=P * 128, Integrator=gi.DOPRI853Integrator) fs = orbit_to_fs(orbit, galactic)
def get_potential(log_M_h, log_r_s, log_M_n, log_a): mw_potential = gp.CCompositePotential() mw_potential['bulge'] = gp.HernquistPotential(m=5E9, c=1., units=galactic) mw_potential['disk'] = gp.MiyamotoNagaiPotential(m=6.8E10 * u.Msun, a=3 * u.kpc, b=280 * u.pc, units=galactic) mw_potential['nucl'] = gp.HernquistPotential(m=np.exp(log_M_n), c=np.exp(log_a) * u.pc, units=galactic) mw_potential['halo'] = gp.NFWPotential(m=np.exp(log_M_h), r_s=np.exp(log_r_s), units=galactic) return mw_potential
for xind in range(0, 201): for zind in range(0, 61): xtemp = xind / 2. - 50 ztemp = zind / 2. - 15 temp_index[0] = xtemp temp_index[2] = ztemp los_mass = np.sum(pot.density(temp_index * u.kpc)) / 8 mock_image[zind, xind] = max(0., los_mass.value / 2.) # Suppose roughly half of disc is gas mass ## Adding halo to potential now that mock galaxy image is in place pot['halo'] = gp.NFWPotential(m=10E11, r_s=25 * u.kpc, units=galactic) ######################################## # Set up progenitor initial conditions - syntax is a bit weird but I didn't come up with it! x, y, z, vx, vy, vz = [x_0, y_0, z_0, vx_0, vy_0, vz_0] # in kpc and km/s c_gc = coord.Galactocentric(x=x * u.kpc, y=y * u.kpc, z=z * u.kpc, v_x=vx * u.km / u.s, v_y=vy * u.km / u.s, v_z=vz * u.km / u.s) psp = gd.PhaseSpacePosition(pos=c_gc.data.xyz, vel=[vx, vy, vz] * u.km / u.s) orbit = gp.Hamiltonian(pot).integrate_orbit(psp,
# TODO: add other tunable parameters once I decide on the potential... # ============================================================================== # Define the potential model up to the bar component potential_no_bar = gp.CCompositePotential() potential_no_bar['disk'] = gp.MiyamotoNagaiPotential(m=5E10 * u.Msun, a=3 * u.kpc, b=280 * u.pc, units=galactic) potential_no_bar['spheroid'] = gp.HernquistPotential(m=4E9 * u.Msun, c=0.6 * u.kpc, units=galactic) potential_no_bar['halo'] = gp.NFWPotential(m=6E11, r_s=18 * u.kpc, units=galactic) def get_hamiltonian(config_file=None): c = Config() c.load(config_file) pot = potential_no_bar.copy() pot['bar'] = get_bar_potential(config_file) Om = [0., 0., c.Omega] * u.km / u.s / u.kpc frame = gp.ConstantRotatingFrame(Omega=Om, units=galactic) return gp.Hamiltonian(potential=pot, frame=frame)