def test_rotation(): """""" c = gc.GD1(phi1=np.linspace(-50, 50, 100) * u.deg, phi2=np.zeros(100) * u.deg) ceq = c.transform_to(coord.ICRS) c0gd = gc.GD1(phi1=0 * u.deg, phi2=90 * u.deg) c0 = c0gd.transform_to(coord.ICRS) c1 = [c0gd.phi1, c0gd.phi2] c2 = [c0.ra, c0.dec] plt.close() plt.figure(figsize=(10, 5)) plt.subplot(111) #, projection='mollweide') #plt.plot(ceq.ra.wrap_at(0*u.deg).rad, ceq.dec.rad, 'r.') #print(ceq[0]) for f in np.linspace(0, 1, 50): cpole = great_circle(c1, c2, f=f) pole = coord.SkyCoord(ra=cpole[0], dec=cpole[1]) #print(pole) fr = gc.GreatCircleICRSFrame(pole=pole, ra0=0 * u.deg) crot = ceq.transform_to(fr) #print(crot[0]) plt.plot(crot.phi1.wrap_at(0 * u.deg).rad, crot.phi2.rad, '-', color=mpl.cm.viridis(f))
def gd1_pole(): """""" c = coord.ICRS(ra=0 * u.deg, dec=90 * u.deg) cgd = c.transform_to(gc.GD1) print(cgd) cgd = gc.GD1(phi1=0 * u.deg, phi2=90 * u.deg) c = cgd.transform_to(coord.ICRS) print(c) c1 = [0 * u.deg, 90 * u.deg] c2 = [c.ra, c.dec] plt.close() plt.figure(figsize=(10, 5)) plt.subplot(111, projection='mollweide') plt.plot(c1[0].to(u.rad), c1[1].to(u.rad), 'ro', ms=10) plt.plot(c2[0].to(u.rad), c2[1].to(u.rad), 'ro', ms=10) for f in np.linspace(0, 1, 100): c3 = great_circle(c1, c2, f=f) plt.plot(c3[0].to(u.rad), c3[1].to(u.rad), 'o', color=mpl.cm.viridis(f), ms=4) plt.tight_layout()
def get_orbit(): """""" t_impact, M, rs, bnorm, bx, vnorm, vx = impact_params() # load one orbital point pos = np.load('../data/log_orbit.npy') phi1, phi2, d, pm1, pm2, vr = pos c = gc.GD1(phi1=phi1 * u.deg, phi2=phi2 * u.deg, distance=d * u.kpc, pm_phi1_cosphi2=pm1 * u.mas / u.yr, pm_phi2=pm2 * u.mas / u.yr, radial_velocity=vr * u.km / u.s) w0 = gd.PhaseSpacePosition(c.transform_to(gc_frame).cartesian) # best-fitting orbit dt = 0.5 * u.Myr n_steps = 120 wangle = 180 * u.deg # integrate back in time fit_orbit = ham.integrate_orbit(w0, dt=dt, n_steps=n_steps) prog_phi0 = -20 * u.deg model_gd1 = fit_orbit.to_coord_frame(gc.GD1, galactocentric_frame=gc_frame) prog_i = np.abs(model_gd1.phi1.wrap_at(180 * u.deg) - prog_phi0).argmin() prog_w0 = fit_orbit[prog_i] dt_orbit = 0.5 * u.Myr nstep_impact = np.int64(t_impact / dt_orbit) prog_orbit = ham.integrate_orbit(prog_w0, dt=-dt_orbit, t1=0 * u.Myr, t2=-3 * u.Gyr) #impact_orbit = prog_orbit[nstep_impact:] #impact_orbit = impact_orbit[::-1] prog_orbit = prog_orbit[::-1] #print(nstep_impact, impact_orbit) return prog_orbit
def fiducial_at_encounter(): """Create fiducial model at the time of encounter""" np.random.seed(143531) t_impact = 0.495 * u.Gyr bnorm = 15 * u.pc bx = 6 * u.pc vnorm = 250 * u.km / u.s vx = -25 * u.km / u.s # load one orbital point pos = np.load('../data/log_orbit.npy') phi1, phi2, d, pm1, pm2, vr = pos c = gc.GD1(phi1=phi1 * u.deg, phi2=phi2 * u.deg, distance=d * u.kpc, pm_phi1_cosphi2=pm1 * u.mas / u.yr, pm_phi2=pm2 * u.mas / u.yr, radial_velocity=vr * u.km / u.s) w0 = gd.PhaseSpacePosition(c.transform_to(gc_frame).cartesian) # best-fitting orbit dt = 0.5 * u.Myr n_steps = 120 wangle = 180 * u.deg # integrate back in time fit_orbit = ham.integrate_orbit(w0, dt=dt, n_steps=n_steps) prog_phi0 = -20 * u.deg model_gd1 = fit_orbit.to_coord_frame(gc.GD1, galactocentric_frame=gc_frame) prog_i = np.abs(model_gd1.phi1.wrap_at(180 * u.deg) - prog_phi0).argmin() prog_w0 = fit_orbit[prog_i] dt_orbit = 0.5 * u.Myr nstep_impact = np.int64((t_impact / dt_orbit).decompose()) #prog_orbit = ham.integrate_orbit(prog_w0, dt=-dt_orbit, t1=0*u.Myr, t2=-3*u.Gyr) prog_orbit = ham.integrate_orbit(prog_w0, dt=-dt_orbit, t1=0 * u.Myr, t2=-3 * u.Gyr) impact_orbit = prog_orbit[nstep_impact:] impact_orbit = impact_orbit[::-1] prog_orbit = prog_orbit[::-1] t_disrupt = -300 * u.Myr minit = 7e4 mfin = 1e3 nrelease = 1 n_times = (prog_orbit.t < t_disrupt).sum() prog_mass = np.linspace(minit, mfin, n_times) prog_mass = np.concatenate( (prog_mass, np.zeros(len(prog_orbit.t) - n_times))) * u.Msun model_present = mockstream.dissolved_fardal_stream(ham, prog_orbit, prog_mass=prog_mass, t_disrupt=t_disrupt, release_every=nrelease) n_steps_disrupt = int(abs(t_disrupt / (prog_orbit.t[1] - prog_orbit.t[0]))) model_present = model_present[:-2 * n_steps_disrupt] model_gd1 = model_present.to_coord_frame(gc.GD1, galactocentric_frame=gc_frame) ind_gap = np.where((model_gd1.phi1.wrap_at(wangle) > -43 * u.deg) & (model_gd1.phi1.wrap_at(wangle) < -33 * u.deg))[0] n_times = (impact_orbit.t < t_disrupt).sum() prog_mass = np.linspace(minit, mfin, n_times) prog_mass = np.concatenate( (prog_mass, np.zeros(len(impact_orbit.t) - n_times))) * u.Msun model = mockstream.dissolved_fardal_stream(ham, impact_orbit, prog_mass=prog_mass, t_disrupt=t_disrupt, release_every=nrelease) n_steps_disrupt = int( abs(t_disrupt / (impact_orbit.t[1] - impact_orbit.t[0]))) model = model[:-2 * n_steps_disrupt] Nstar = np.shape(model)[0] ivalid = ind_gap < Nstar ind_gap = ind_gap[ivalid] xgap = np.median(model.xyz[:, ind_gap], axis=1) vgap = np.median(model.v_xyz[:, ind_gap], axis=1) ######################## # Perturber at encounter i = np.array([1, 0, 0], dtype=float) j = np.array([0, 1, 0], dtype=float) k = np.array([0, 0, 1], dtype=float) # find positional plane bi = np.cross(j, vgap) bi = bi / np.linalg.norm(bi) bj = np.cross(vgap, bi) bj = bj / np.linalg.norm(bj) # pick b by = np.sqrt(bnorm**2 - bx**2) b = bx * bi + by * bj xsub = xgap + b # find velocity plane vi = np.cross(vgap, b) vi = vi / np.linalg.norm(vi) vj = np.cross(b, vi) vj = vj / np.linalg.norm(vj) # pick v vy = np.sqrt(vnorm**2 - vx**2) vsub = vx * vi + vy * vj outdict = {'model': model, 'xsub': xsub, 'vsub': vsub} pickle.dump(outdict, open('../data/fiducial_at_encounter.pkl', 'wb'))
def fiducial_at_start(): """Create fiducial model at the beginning of the movie""" np.random.seed(143531) t_impact = 2 * 0.495 * u.Gyr # load one orbital point pos = np.load('../data/log_orbit.npy') phi1, phi2, d, pm1, pm2, vr = pos c = gc.GD1(phi1=phi1 * u.deg, phi2=phi2 * u.deg, distance=d * u.kpc, pm_phi1_cosphi2=pm1 * u.mas / u.yr, pm_phi2=pm2 * u.mas / u.yr, radial_velocity=vr * u.km / u.s) w0 = gd.PhaseSpacePosition(c.transform_to(gc_frame).cartesian) # best-fitting orbit dt = 0.5 * u.Myr n_steps = 120 wangle = 180 * u.deg # integrate back in time fit_orbit = ham.integrate_orbit(w0, dt=dt, n_steps=n_steps) prog_phi0 = -20 * u.deg model_gd1 = fit_orbit.to_coord_frame(gc.GD1, galactocentric_frame=gc_frame) prog_i = np.abs(model_gd1.phi1.wrap_at(180 * u.deg) - prog_phi0).argmin() prog_w0 = fit_orbit[prog_i] dt_orbit = 0.5 * u.Myr nstep_impact = np.int64((t_impact / dt_orbit).decompose()) #prog_orbit = ham.integrate_orbit(prog_w0, dt=-dt_orbit, t1=0*u.Myr, t2=-3*u.Gyr) prog_orbit = ham.integrate_orbit(prog_w0, dt=-dt_orbit, t1=0 * u.Myr, t2=-3 * u.Gyr) impact_orbit = prog_orbit[nstep_impact:] impact_orbit = impact_orbit[::-1] prog_orbit = prog_orbit[::-1] t_disrupt = -300 * u.Myr minit = 7e4 mfin = 1e3 nrelease = 1 n_times = (prog_orbit.t < t_disrupt).sum() prog_mass = np.linspace(minit, mfin, n_times) prog_mass = np.concatenate( (prog_mass, np.zeros(len(prog_orbit.t) - n_times))) * u.Msun model_present = mockstream.dissolved_fardal_stream(ham, prog_orbit, prog_mass=prog_mass, t_disrupt=t_disrupt, release_every=nrelease) n_steps_disrupt = int(abs(t_disrupt / (prog_orbit.t[1] - prog_orbit.t[0]))) model_present = model_present[:-2 * n_steps_disrupt] model_gd1 = model_present.to_coord_frame(gc.GD1, galactocentric_frame=gc_frame) ind_gap = np.where((model_gd1.phi1.wrap_at(wangle) > -43 * u.deg) & (model_gd1.phi1.wrap_at(wangle) < -33 * u.deg))[0] n_times = (impact_orbit.t < t_disrupt).sum() prog_mass = np.linspace(minit, mfin, n_times) prog_mass = np.concatenate( (prog_mass, np.zeros(len(impact_orbit.t) - n_times))) * u.Msun model = mockstream.dissolved_fardal_stream(ham, impact_orbit, prog_mass=prog_mass, t_disrupt=t_disrupt, release_every=nrelease) n_steps_disrupt = int( abs(t_disrupt / (impact_orbit.t[1] - impact_orbit.t[0]))) model = model[:-2 * n_steps_disrupt] xsub = np.ones(3) * u.kpc vsub = np.ones(3) * u.km / u.s outdict = {'model': model, 'xsub': xsub, 'vsub': vsub} pickle.dump(outdict, open('../data/fiducial_at_start.pkl', 'wb'))