def radial_velocity(): # set the masses M_star1 = 4.0 * M_sun # star 1's mass M_star2 = M_sun # star 2's mass # set the semi-major axis of the star 2 (and derive that of star 1) # M_star2 a_star2 = -M_star1 a_star1 (center of mass) a_star2 = 10.0 * AU a_star1 = (M_star2 / M_star1) * a_star2 # set the eccentricity ecc = 0.4 # set the angle to rotate the semi-major axis wrt the observer theta = np.pi / 6.0 # display additional information annotate = True # create the binary object b = bi.Binary(M_star1, M_star2, a_star1 + a_star2, ecc, theta, annotate=annotate) # set the timestep in terms of the orbital period dt = b.P / 360.0 tmax = 2.0 * b.P # maximum integration time b.integrate(dt, tmax) s1 = b.orbit1 s2 = b.orbit2 # ================================================================ # plotting # ================================================================ iframe = 0 xmin = 1.05 * (s2.x - s1.x).min() xmax = 1.05 * (s2.x - s1.x).max() ymin = 1.05 * (s2.y - s1.y).min() ymax = 1.05 * (s2.y - s1.y).max() for n in range(len(s1.t)): fig = plt.figure(1) fig.clear() plt.subplots_adjust(left=0.025, right=0.975, bottom=0.025, top=0.95) axl = fig.add_subplot(121) axr = fig.add_subplot(122) for i in range(2): if i == 0: ax = axl # offsets -- we want star 1 at the origin xoffset = s1.x[n] yoffset = s1.y[n] else: ax = axr # no offsets xoffset = 0.0 yoffset = 0.0 ax.set_aspect("equal", "datalim") ax.set_axis_off() # center of mass ax.scatter([0 - xoffset], [0 - yoffset], s=150, marker="x", color="k") if i == 0: # plot star 1's position symsize = 200 ax.scatter([s1.x[n] - xoffset], [s1.y[n] - yoffset], s=symsize, color="C0") # plot star 2's orbit and position symsize = 200 * (b.M2 / b.M1) ax.plot(s2.x - s1.x, s2.y - s1.y, color="C1") ax.scatter([s2.x[n] - xoffset], [s2.y[n] - yoffset], s=symsize, color="C1", zorder=100) else: # plot star 1's orbit position symsize = 200 ax.scatter([s1.x[n]], [s1.y[n]], s=symsize, color="C0", zorder=100) ax.plot(s1.x, s1.y, color="C0") # plot star 2's orbit and position symsize = 200 * (b.M2 / b.M1) ax.scatter([s2.x[n]], [s2.y[n]], s=symsize, color="C1", zorder=100) ax.plot(s2.x, s2.y, color="C1") if i == 0 and annotate: # display time ax.text(0.05, 0.05, "time = {:6.3f} yr".format(s1.t[n] / year), transform=ax.transAxes) # display information about stars ax.text(0.025, 0.9, r"mass ratio: {:3.2f}".format(b.M1 / b.M2), transform=ax.transAxes, color="k", fontsize="medium") ax.text(0.025, 0.86, r"eccentricity: {:3.2f}".format(b.e), transform=ax.transAxes, color="k", fontsize="medium") if annotate: # plot a reference line ax.plot([0, 1 * AU], [0.93 * ymin, 0.93 * ymin], color="k") ax.text(0.5 * AU, 0.975 * ymin, "1 AU", horizontalalignment="center", verticalalignment="top") ax.set_xlim(xmin, xmax) ax.set_ylim(ymin, ymax) if i == 0: ax.set_title("massive star frame of reference") else: ax.set_title("center of mass frame of reference") fig.set_size_inches(12.8, 7.2) plt.savefig("binary_star_{:04d}.png".format(iframe)) iframe += 1
def doit(): # set the masses M_star1 = M_sun # star 1's mass M_star2 = 0.6 * M_sun # star 2's mass # set the semi-major axis of the star 2 (and derive that of star 1) # M_star2 a_star2 = -M_star1 a_star1 (center of mass) a_star2 = 1.0 * AU a_star1 = (M_star2 / M_star1) * a_star2 # set the eccentricity ecc = 0.4 # set the angle to rotate the semi-major axis wrt the observer theta = math.pi / 6.0 # create the binary container b = bi.Binary(M_star1, M_star2, a_star1 + a_star2, ecc, theta) # set the timestep in terms of the orbital period dt = b.P / 360.0 tmax = 2.0 * b.P # maximum integration time b.integrate(dt, tmax) s1 = b.orbit1 s2 = b.orbit2 # ================================================================ # plotting # ================================================================ fig = plt.figure(1) ax = fig.add_subplot(111) plt.subplots_adjust(left=0.05, right=0.95, bottom=0.05, top=0.95) ax.set_aspect("equal", "datalim") ax.set_axis_off() n = 0 ax.scatter([0], [0], s=150, marker="x", color="k") # plot star 1's orbit and position symsize = 200 ax.plot(s1.x, s1.y, color="C0") # plot star 2's orbit and position #symsize = 200*(M_star2/M_star1) ax.plot(s2.x, s2.y, color="C1", linestyle="--") ax.scatter([s2.x[n]], [s2.y[n]], s=symsize, color="C1", marker='h') # reference points -- in terms of total number of steps integrated f1 = 0.0943 f2 = 0.25 f3 = 0.5 - f1 npts = len(s2.t) xc = 0.5 * (s2.x[0] + s2.x[npts // 4]) yc = 0.5 * (s2.y[0] + s2.y[npts // 4]) # compute the angle of f1 wrt the initial position (just for debugging) a1 = math.atan2(s2.y[int(f1 * npts)] - yc, s2.x[int(f1 * npts)] - xc) a0 = math.atan2(s2.y[0] - yc, s2.x[0] - xc) print((a1 - a0) * 180. / math.pi) ax.scatter([s2.x[int(f1 * npts)]], [s2.y[int(f1 * npts)]], s=symsize, color="C1", marker='h') ax.scatter([s2.x[int(f2 * npts)]], [s2.y[int(f2 * npts)]], s=symsize, color="C1", marker='h') ax.scatter([s2.x[int(f3 * npts)]], [s2.y[int(f3 * npts)]], s=symsize, color="C1", marker='h') # label the points ax.text(s2.x[n] * 1.15, s2.y[n], "A4") ax.text(s2.x[int(f1 * npts)] * 1.15, s2.y[int(f1 * npts)] * 1.15, "A1") ax.text(s2.x[int(f2 * npts)] * 1.15, s2.y[int(f2 * npts)], "A2") ax.text(s2.x[int(f3 * npts)] * 0.85, s2.y[int(f3 * npts)] * 1.15, "A3") plt.axis([-1.4 * b.a2, 0.8 * b.a2, -1.4 * b.a2, 0.8 * b.a2]) fig.set_size_inches(7.2, 7.2) plt.savefig("binary_fig.pdf", bbox_inches="tight")
def doit(): # set the masses M_star1 = 50 * M_sun # star 1's mass M_star2 = M_sun # star 2's mass # set the semi-major axis of the star 2 (and derive that of star 1) # M_star2 a_star2 = -M_star1 a_star1 (center of mass) a_star2 = 1.0 * AU a_star1 = (M_star2 / M_star1) * a_star2 # set the eccentricity ecc = 0.0 # set the angle to rotate the semi-major axis wrt the observer theta = math.pi / 6.0 # create the solar system container b = bi.Binary(M_star1, M_star2, a_star1 + a_star2, ecc, theta) # set the timestep in terms of the orbital period dt = b.P / 360.0 tmax = 2.0 * b.P # maximum integration time s1, s2 = b.integrate(dt, tmax) # ================================================================ # plotting # ================================================================ iframe = 0 for n in range(len(s1.t)): plt.clf() plt.subplots_adjust(left=0.1, right=0.9, bottom=0.1, top=0.9) a = plt.gca() a.set_aspect("equal", "datalim") plt.axis("off") # if e = 0 and M_star1 = M_star2, then the orbits lie on top of one # another, so plot only a single orbital line. # plot star 1's orbit and position symsize = 500 if not (b.M1 == b.M2 and b.e == 0.0): plt.plot(s1.x, s1.y, color="r") else: plt.plot(s1.x, s1.y, color="k") plt.scatter([s1.x[n]], [s1.y[n]], s=symsize, color="r") # plot star 2's orbit and position symsize = 1000 * (b.M2 / b.M1) if not (b.M1 == b.M2 and b.e == 0.0): plt.plot(s2.x, s2.y, color="g") plt.scatter([s2.x[n]], [s2.y[n]], s=symsize, color="g") plt.scatter([0], [0], s=150, marker="x", color="k", zorder=1000) plt.axis( [-1.4 * a_star2, 1.4 * a_star2, -1.4 * a_star2, 1.4 * a_star2]) f = plt.gcf() f.set_size_inches(7.2, 7.2) plt.savefig("planetary_orbit_%04d.png" % iframe) iframe += 1
def astrometric_binary(): # set the masses M_star1 = M_sun # star 1's mass M_star2 = 0.5 * M_sun # star 2's mass # set the semi-major axis of the star 2 (and derive that of star 1) # M_star2 a_star2 = -M_star1 a_star1 (center of mass) a_star2 = 1.0 * AU a_star1 = (M_star2 / M_star1) * a_star2 # set the eccentricity ecc = 0.0 # set the angle to rotate the semi-major axis wrt the observer theta = math.pi / 2.0 b = bi.Binary(M_star1, M_star2, a_star1 + a_star2, ecc, theta) # velocity of the center of mass v = 10 * a_star2 / b.P # set the timestep in terms of the orbital period dt = b.P / 360.0 tmax = 2.0 * b.P # maximum integration time s1, s2 = b.integrate(dt, tmax) # now move the center of mass according to the velocity defined # above, and update the positions x_cm = np.zeros(len(s1.t), np.float64) y_cm = np.zeros(len(s2.t), np.float64) for n in range(len(s1.t)): x_cm[n] = v * s1.t[n] y_cm[n] = 0.0 s1.x[n] += v * s1.t[n] s2.x[n] += v * s2.t[n] # ================================================================ # plotting # ================================================================ plt.clf() plt.subplots_adjust(left=0.1, right=0.9, bottom=0.1, top=0.9) a = plt.gca() a.set_aspect("equal", "datalim") plt.axis("off") # plot the center of mass motion plt.scatter([0], [0], s=50, marker="x", color="k") plt.plot(x_cm, y_cm, color="0.5", linestyle="--") # plot star 1's orbit and position plt.plot(s1.x, s1.y, color="r") plt.scatter([s1.x[0]], [s1.y[0]], s=200, color="r") # plot star 2's orbit and position plt.plot(s2.x, s2.y, color="g") plt.scatter([s2.x[0]], [s2.y[0]], s=100, color="g") plt.text(10 * a_star2, 3 * a_star2, "mass ratio: %3.2f" % (b.M1 / b.M2), color="k", verticalalignment="center") plt.text(10 * a_star2, 2.5 * a_star2, "eccentricity: %3.2f" % (ecc), color="k", verticalalignment="center") # labels plt.plot([0.1 * a_star2, 1.1 * a_star2], [2.9 * a_star2, 2.9 * a_star2], color="0.5", linestyle="--") plt.text(1.3 * a_star2, 2.9 * a_star2, "path of center of mass", verticalalignment="center", color="0.5") plt.plot([0.1 * a_star2, 1.1 * a_star2], [2.4 * a_star2, 2.4 * a_star2], color="r") plt.text(1.3 * a_star2, 2.4 * a_star2, "path of primary star", verticalalignment="center", color="r") plt.plot([0.1 * a_star2, 1.1 * a_star2], [1.9 * a_star2, 1.9 * a_star2], color="g") plt.text(1.3 * a_star2, 1.9 * a_star2, "path of unseen companion", verticalalignment="center", color="g") plt.axis([-0.3 * a_star2, 19.7 * a_star2, -3 * a_star2, 3 * a_star2]) f = plt.gcf() f.set_size_inches(10.0, 3.0) plt.savefig("astrometric_binary.png")
def radial_velocity(): # set the masses M_star = M_sun # star's mass M_p = 0.15 * M_sun # planet's mass # set the semi-major axis of the planet (and derive that of the star) a_p = 1.0 * AU a_star = (M_p / M_star) * a_p # M_p a_p = -M_star a_star (center of mass) ecc = 0.3 theta = math.pi / 6.0 # create the solar system container b = bi.Binary(M_star, M_p, a_star + a_p, ecc, theta) # set the timestep in terms of the orbital period dt = b.P / 360.0 tmax = 2.0 * b.P # maximum integration time s, p = b.integrate(dt, tmax) # ================================================================ # plotting # ================================================================ iframe = 0 # first plot a legend intro sequence while iframe < 100: plt.clf() plt.subplot(121) plt.subplots_adjust(left=0.1, right=0.95, bottom=0.15, top=0.85, wspace=0.45, hspace=0.0) a = plt.gca() a.set_aspect("equal", "datalim") plt.axis("off") plt.scatter([0], [0], s=150, marker="x", color="k") # plot the planet's orbit and position plt.plot(p.x, p.y, color="g") plt.scatter([p.x[0]], [p.y[0]], s=100, color="g") # plot the star's orbit and position plt.plot(s.x, s.y, color="r") plt.scatter([s.x[0]], [s.y[0]], s=200, color="r") # plot a reference line plt.plot([0, 1 * AU], [-1.2 * a_p, -1.2 * a_p], color="k") plt.text(0.5 * AU, -1.4 * a_p, "1 AU", horizontalalignment='center') plt.arrow(0.0, 1.5 * a_p, 0.0, 0.2 * a_p, width=0.025 * a_p, facecolor="b", edgecolor="k", alpha=1.0, clip_on=0, length_includes_head=True, head_width=0.075 * a_p, head_length=0.075 * a_p) plt.text(0.0, 1.4 * a_p, "observer", horizontalalignment='center') plt.text(-1.8 * a_p, -1.6 * a_p, "time = %6.3f yr" % (p.t[0] / year)) plt.axis([-1.5 * a_p, 1.5 * a_p, -1.5 * a_p, 1.5 * a_p]) plt.subplot(122) plt.scatter([0.1], [0.8], s=200, color="r") plt.text(0.2, 0.8, "star", color="r") plt.scatter([0.1], [0.6], s=100, color="g") plt.text(0.2, 0.6, "planet", color="g") plt.text(0.2, 0.5, "(note: planet's mass exaggerated", size="small", color="k") plt.text(0.2, 0.45, " to enhance effect)", size="small", color="k") plt.scatter([0.1], [0.3], s=150, marker="x", color="k") plt.text(0.2, 0.3, "center of mass", color="k") plt.axis([0, 1, 0, 1]) plt.axis("off") f = plt.gcf() f.set_size_inches(12.8, 7.2) plt.savefig("radial_velocity_%04d.png" % iframe) iframe += 1 # now plot the actual data for n in range(len(s.t)): plt.clf() plt.subplot(121) plt.subplots_adjust(left=0.1, right=0.95, bottom=0.15, top=0.85, wspace=0.45, hspace=0.0) a = plt.gca() a.set_aspect("equal", "datalim") plt.axis("off") plt.scatter([0], [0], s=150, marker="x", color="k") # plot the planet's orbit and position plt.plot(p.x, p.y, color="g") plt.scatter([p.x[n]], [p.y[n]], s=100, color="g") # plot the star's orbit and position plt.plot(s.x, s.y, color="r") plt.scatter([s.x[n]], [s.y[n]], s=200, color="r") # plot a reference line plt.plot([0, 1 * AU], [-1.2 * a_p, -1.2 * a_p], color="k") plt.text(0.5 * AU, -1.4 * a_p, "1 AU", horizontalalignment='center') plt.arrow(0.0, 1.5 * a_p, 0.0, 0.2 * a_p, width=0.025 * a_p, facecolor="b", edgecolor="k", alpha=1.0, clip_on=0, length_includes_head=True, head_width=0.075 * a_p, head_length=0.075 * a_p) plt.text(0.0, 1.4 * a_p, "observer", horizontalalignment='center') plt.text(-1.8 * a_p, -1.6 * a_p, "time = %6.3f yr" % (s.t[n] / year)) plt.axis([-1.5 * a_p, 1.5 * a_p, -1.5 * a_p, 1.5 * a_p]) plt.subplot(122) # plot km/s vs years # note: radial velocity convention is that if it is moving # toward us, then the velocity is negative. Since the observer # is at +Y, we want to plot -vy as the radial velocity. plt.plot(s.t / b.P, -s.vy / 1.e5, color="r") plt.scatter([s.t[n] / b.P], [-s.vy[n] / 1.e5], color="r", s=50) # plot a reference line at vy = 0 plt.plot([0.0, tmax / b.P], [0.0, 0.0], "k--") plt.axis([ 0.0, tmax / b.P, -int(numpy.max(s.vy)) / 1.e5 - 1, -int(numpy.min(s.vy)) / 1.e5 + 1 ]) plt.xlabel("t/period") plt.ylabel("radial velocity [km/s]") f = plt.gcf() f.set_size_inches(12.8, 7.2) plt.savefig("radial_velocity_%04d.png" % iframe) iframe += 1
def radial_velocity(M1=1, M2=1, a2=10, e=0.0, annotate=False): # set the masses M_star1 = M1*M_sun # star 1's mass M_star2 = M2*M_sun # star 2's mass # set the semi-major axis of the star 2 (and derive that of star 1) # M_star2 a_star2 = -M_star1 a_star1 (center of mass) a_star2 = a2*AU a_star1 = (M_star2/M_star1)*a_star2 # set the eccentricity ecc = e # set the angle to rotate the semi-major axis wrt the observer theta = np.pi/6.0 # create the binary object b = bi.Binary(M_star1, M_star2, a_star1 + a_star2, ecc, theta, annotate=annotate) # set the timestep in terms of the orbital period dt = b.P/360.0 tmax = 2.0*b.P # maximum integration time b.integrate(dt, tmax) s1 = b.orbit1 s2 = b.orbit2 # ================================================================ # plotting # ================================================================ iframe = 0 KE1, KE2 = b.kinetic_energies() PE = b.potential_energy() bar = progressbar.ProgressBar() for n in bar(range(len(s1.t))): fig = plt.figure(1) fig.clear() ax = fig.add_subplot(111) plt.subplots_adjust(left=0.025, right=0.975, bottom=0.025, top=0.975) ax.set_aspect("equal", "datalim") ax.set_axis_off() ax.scatter([0], [0], s=150, marker="x", color="k") # if e = 0 and M_star1 = M_star2, then the orbits lie on top of one # another, so plot only a single orbital line. # plot star 1's orbit and position symsize = 200 if not (b.M1 == b.M2 and b.e == 0.0): ax.plot(s1.x, s1.y, color="C0") else: ax.plot(s1.x, s1.y, color="k") ax.scatter([s1.x[n]], [s1.y[n]], s=symsize, color="C0", zorder=100) # plot star 2's orbit and position symsize = 200*(b.M2/b.M1) if not (b.M1 == b.M2 and b.e == 0.0): ax.plot(s2.x, s2.y, color="C1") ax.scatter([s2.x[n]], [s2.y[n]], s=symsize, color="C1", zorder=100) if annotate: # display time ax.text(0.05, 0.05, "time = {:6.3f} yr".format(s1.t[n]/year), transform=ax.transAxes) # display information about stars ax.text(0.05, 0.95, r"mass ratio: {:3.2f}".format(b.M1/b.M2), transform=ax.transAxes, color="k", fontsize="large") ax.text(0.05, 0.9, r"eccentricity: {:3.2f}".format(b.e), transform=ax.transAxes, color="k", fontsize="large") # energies if annotate: # KE 1 sig, ex = find_scinotat(KE1[n]) ax.text(0.05, 0.4, r"$K_1 = {:+4.2f} \times 10^{{{:2d}}}$ erg".format(sig, ex), transform=ax.transAxes, color="C0") sig, ex = find_scinotat(KE2[n]) ax.text(0.05, 0.35, r"$K_2 = {:+4.2f} \times 10^{{{:2d}}}$ erg".format(sig, ex), transform=ax.transAxes, color="C1") sig, ex = find_scinotat(PE[n]) ax.text(0.05, 0.3, r"$U = {:+4.2f} \times 10^{{{:2d}}}$ erg".format(sig, ex), transform=ax.transAxes) sig, ex = find_scinotat(KE1[n] + KE2[n] + PE[n]) ax.text(0.05, 0.25, r"$E = {:+4.2f} \times 10^{{{:2d}}}$ erg".format(sig, ex), transform=ax.transAxes) xmin = 1.05*min(s1.x.min(), s2.x.min()) xmax = 1.05*max(s1.x.max(), s2.x.max()) ymin = 1.05*min(s1.y.min(), s2.y.min()) ymax = 1.05*max(s1.y.max(), s2.y.max()) if annotate: # plot a reference line ax.plot([0, 1*AU], [0.93*ymin, 0.93*ymin], color="k") ax.text(0.5*AU, 0.975*ymin, "1 AU", horizontalalignment="center", verticalalignment="top") ax.set_xlim(xmin, xmax) ax.set_ylim(ymin, ymax) fig.set_size_inches(12.8, 7.2) plt.tight_layout() if annotate: plt.savefig("binary_star_mratio={:3.2f}_e={:3.2f}_{:04d}_energy.png".format(M_star1/M_star2, e, iframe)) else: plt.savefig("binary_star_mratio={:3.2f}_e={:3.2f}_{:04d}.png".format(M_star1/M_star2, e, iframe)) iframe += 1
def radial_velocity(): # set the masses M_star1 = 4.0 * M_sun # star 1's mass M_star2 = M_sun # star 2's mass # set the semi-major axis of the star 2 (and derive that of star 1) # M_star2 a_star2 = -M_star1 a_star1 (center of mass) a_star2 = 10.0 * AU a_star1 = (M_star2 / M_star1) * a_star2 # set the eccentricity ecc = 0.4 # set the angle to rotate the semi-major axis wrt the observer theta = math.pi / 6.0 # display additional information annotate = True # create the binary object b = bi.Binary(M_star1, M_star2, a_star1 + a_star2, ecc, theta, annotate=annotate) # set the timestep in terms of the orbital period dt = b.P / 360.0 tmax = 2.0 * b.P # maximum integration time s1, s2 = b.integrate(dt, tmax) # ================================================================ # plotting # ================================================================ plt.rc('text', usetex=True) plt.rc('font', family='serif') iframe = 0 for n in range(len(s1.t)): plt.clf() plt.subplots_adjust(left=0.1, right=0.9, bottom=0.1, top=0.9) a = plt.gca() a.set_aspect("equal", "datalim") plt.axis("off") # offsets -- we want star 1 at the origin xoffset = s1.x[n] yoffset = s1.y[n] plt.scatter([0 - xoffset], [0 - yoffset], s=150, marker="x", color="k") # plot star 1's position symsize = 200 plt.scatter([s1.x[n] - xoffset], [s1.y[n] - yoffset], s=symsize, color="r") # plot star 2's orbit and position symsize = 200 * (b.M2 / b.M1) plt.plot(s2.x - s1.x, s2.y - s1.y, color="g") plt.scatter([s2.x[n] - xoffset], [s2.y[n] - yoffset], s=symsize, color="g") if annotate: # plot a reference line plt.plot([0, 1 * AU], [-1.6 * b.a2, -1.6 * b.a2], color="k") plt.text(0.5 * AU, -1.8 * b.a2, "1 AU", horizontalalignment='center') # display time plt.text(-1.8 * b.a2, -1.7 * b.a2, "time = %6.3f yr" % (s1.t[n] / year)) # display information about stars plt.text(-1.8 * b.a2, 0.9 * b.a2, r"mass ratio: %3.2f" % (b.M1 / b.M2), color="k") plt.text(-1.8 * b.a2, 0.7 * b.a2, r"eccentricity: %3.2f" % (b.e), color="k") plt.axis([-1.8 * b.a2, 1.0 * b.a2, -1.8 * b.a2, 1.0 * b.a2]) f = plt.gcf() f.set_size_inches(7.2, 7.2) plt.savefig("binary_star_%04d.png" % iframe) iframe += 1
def radial_velocity(): # set the masses M_star = M_sun # star's mass M_p = 0.15 * M_sun # planet's mass # set the semi-major axis of the planet (and derive that of the star) a_p = 1.0 * AU a_star = (M_p / M_star) * a_p # M_p a_p = -M_star a_star (center of mass) ecc = 0.0 theta = 0.0 # create the solar system container b = bi.Binary(M_star, M_p, a_star + a_p, ecc, theta) # set the timestep in terms of the orbital period dt = b.P / 360.0 tmax = 2.0 * b.P # maximum integration time b.integrate(dt, tmax) s = b.orbit1 p = b.orbit2 # ================================================================ # plotting # ================================================================ title_frames = 70 iframe = 0 # first plot a legend intro sequence for iframe in range(title_frames): fig = plt.figure(1) fig.clear() plt.subplots_adjust(left=0.1, right=0.95, bottom=0.15, top=0.85, wspace=0.45, hspace=0.0) ax = fig.add_subplot(121) ax.set_aspect("equal", "datalim") ax.set_axis_off() ax.scatter([0], [0], s=150, marker="x", color="k") # plot the planet's orbit and position ax.plot(p.x, p.y, color="C0") ax.scatter([p.x[0]], [p.y[0]], s=100, color="C0") # plot the star's orbit and position ax.plot(s.x, s.y, color="C1") ax.scatter([s.x[0]], [s.y[0]], s=200, color="C1") # plot a reference line ax.plot([0, 1 * AU], [-1.2 * a_p, -1.2 * a_p], color="k") ax.text(0.5 * AU, -1.4 * a_p, "1 AU", horizontalalignment='center') ax.arrow(0.0, 1.5 * a_p, 0.0, 0.2 * a_p, width=0.025 * a_p, facecolor="0.5", edgecolor="k", alpha=1.0, clip_on=0, length_includes_head=True, head_width=0.075 * a_p, head_length=0.075 * a_p) ax.text(0.0, 1.4 * a_p, "to the observer", horizontalalignment='center') ax.text(-1.8 * a_p, -1.6 * a_p, "time = %6.3f yr" % (p.t[0] / year)) ax.set_xlim(-1.5 * a_p, 1.5 * a_p) ax.set_ylim(-1.5 * a_p, 1.5 * a_p) ax = fig.add_subplot(122) ax.scatter([0.1], [0.8], s=200, color="C1") ax.text(0.2, 0.8, "star", color="C1") ax.scatter([0.1], [0.6], s=100, color="C0") ax.text(0.2, 0.6, "planet", color="C0") ax.text(0.2, 0.5, "(note: planet's mass exaggerated", size="small", color="k") ax.text(0.2, 0.45, " to enhance effect)", size="small", color="k") ax.scatter([0.1], [0.3], s=150, marker="x", color="k") ax.text(0.2, 0.3, "center of mass", color="k") ax.set_xlim(0, 1) ax.set_ylim(0, 1) ax.set_axis_off() fig.set_size_inches(12.8, 7.2) plt.savefig("radial_velocity_{:04d}.png".format(iframe)) # now plot the actual data print("starting orbit part, iframe = ", iframe) for n in range(len(s.t)): print("iframe = ", iframe) fig = plt.figure(1) fig.clear() plt.subplots_adjust(left=0.1, right=0.95, bottom=0.15, top=0.85, wspace=0.45, hspace=0.0) ax = fig.add_subplot(121) ax.set_aspect("equal", "datalim") ax.set_axis_off() ax.scatter([0], [0], s=150, marker="x", color="k") # plot the planet's orbit and position ax.plot(p.x, p.y, color="C0") ax.scatter([p.x[n]], [p.y[n]], s=100, color="C0") # plot the star's orbit and position ax.plot(s.x, s.y, color="C1") ax.scatter([s.x[n]], [s.y[n]], s=200, color="C1") # plot a reference line ax.plot([0, 1 * AU], [-1.2 * a_p, -1.2 * a_p], color="k") ax.text(0.5 * AU, -1.4 * a_p, "1 AU", horizontalalignment='center') ax.arrow(0.0, 1.5 * a_p, 0.0, 0.2 * a_p, width=0.025 * a_p, facecolor="0.5", edgecolor="k", alpha=1.0, clip_on=0, length_includes_head=True, head_width=0.075 * a_p, head_length=0.075 * a_p) ax.text(0.0, 1.4 * a_p, "to the observer", horizontalalignment='center') ax.text(-1.8 * a_p, -1.6 * a_p, "time = %6.3f yr" % (s.t[n] / year)) ax.set_xlim(-1.5 * a_p, 1.5 * a_p) ax.set_ylim(-1.5 * a_p, 1.5 * a_p) ax = fig.add_subplot(122) # plot km/s vs years # note: radial velocity convention is that if it is moving # toward us, then the velocity is negative. Since the observer # is at +Y, we want to plot -vy as the radial velocity. ax.plot(s.t / b.P, -s.vy / 1.e5, color="C1") ax.scatter([s.t[n] / b.P], [-s.vy[n] / 1.e5], color="C1", s=50) # plot a reference line at vy = 0 ax.plot([0.0, tmax / b.P], [0.0, 0.0], "k--") ax.axis([ 0.0, tmax / b.P, int(np.min(s.vy)) / 1.e5 - 1, int(np.max(s.vy)) / 1.e5 + 1 ]) ax.set_xlabel("t/period") ax.set_ylabel("radial velocity [km/s]") fig.set_size_inches(12.8, 7.2) plt.savefig("radial_velocity_%04d.png" % iframe) iframe += 1
def doit(): # set the masses M_star1 = 50 * M_sun # star 1's mass M_star2 = M_sun # star 2's mass # set the semi-major axis of the star 2 (and derive that of star 1) # M_star2 a_star2 = -M_star1 a_star1 (center of mass) a_star2 = 1.0 * AU a_star1 = (M_star2 / M_star1) * a_star2 # set the eccentricity ecc = 0.0 # set the angle to rotate the semi-major axis wrt the observer theta = np.pi / 6.0 # create the solar system container b = bi.Binary(M_star1, M_star2, a_star1 + a_star2, ecc, theta) # set the timestep in terms of the orbital period dt = b.P / 360.0 tmax = 2.0 * b.P # maximum integration time b.integrate(dt, tmax) s1 = b.orbit1 s2 = b.orbit2 # ================================================================ # plotting # ================================================================ iframe = 0 for n in range(len(s1.t)): fig = plt.figure(1) fig.clear() ax = fig.add_subplot(111) plt.subplots_adjust(left=0.05, right=0.95, bottom=0.05, top=0.95) ax.set_aspect("equal", "datalim") ax.set_axis_off() # if e = 0 and M_star1 = M_star2, then the orbits lie on top of one # another, so plot only a single orbital line. # plot star 1's orbit and position symsize = 500 if not (b.M1 == b.M2 and b.e == 0.0): ax.plot(s1.x, s1.y, color="C1") else: ax.plot(s1.x, s1.y, color="k") ax.scatter([s1.x[n]], [s1.y[n]], s=symsize, color="C1", zorder=100) # plot star 2's orbit and position symsize = 1000 * (b.M2 / b.M1) if not (b.M1 == b.M2 and b.e == 0.0): plt.plot(s2.x, s2.y, color="C0") plt.scatter([s2.x[n]], [s2.y[n]], s=symsize, color="C0", zorder=100) plt.scatter([0], [0], s=150, marker="x", color="k", zorder=1000) plt.axis( [-1.1 * a_star2, 1.1 * a_star2, -1.1 * a_star2, 1.1 * a_star2]) fig.set_size_inches(12.8, 7.2) plt.savefig("planetary_orbit_{:04d}.png".format(iframe)) iframe += 1
def radial_velocity(): # set the masses M_star1 = 2.0 * M_sun # star 1's mass M_star2 = M_sun # star 2's mass # set the semi-major axis of the star 2 (and derive that of star 1) # M_star2 a_star2 = -M_star1 a_star1 (center of mass) a_star2 = 10.0 * AU a_star1 = (M_star2 / M_star1) * a_star2 # set the eccentricity ecc = 0.4 # set the angle to rotate the semi-major axis wrt the observer theta = np.pi / 6.0 # display additional information annotate = False # create the binary object b = bi.Binary(M_star1, M_star2, a_star1 + a_star2, ecc, theta, annotate=annotate) # set the timestep in terms of the orbital period dt = b.P / 360.0 tmax = 2.0 * b.P # maximum integration time s1, s2 = b.integrate(dt, tmax) # ================================================================ # plotting # ================================================================ plt.rc('text', usetex=True) plt.rc('font', family='serif') iframe = 0 for n in range(len(s1.t)): plt.clf() plt.subplots_adjust(left=0.1, right=0.9, bottom=0.1, top=0.9) a = plt.gca() a.set_aspect("equal", "datalim") plt.axis("off") plt.scatter([0], [0], s=150, marker="x", color="k") # if e = 0 and M_star1 = M_star2, then the orbits lie on top of one # another, so plot only a single orbital line. # plot star 1's orbit and position symsize = 200 if not (b.M1 == b.M2 and b.e == 0.0): plt.plot(s1.x, s1.y, color="r") else: plt.plot(s1.x, s1.y, color="k") plt.scatter([s1.x[n]], [s1.y[n]], s=symsize, color="r") # plot star 2's orbit and position symsize = 200 * (b.M2 / b.M1) if not (b.M1 == b.M2 and b.e == 0.0): plt.plot(s2.x, s2.y, color="g") plt.scatter([s2.x[n]], [s2.y[n]], s=symsize, color="g") if annotate: # plot a reference line plt.plot([0, 1 * AU], [-1.2 * b.a2, -1.2 * b.a2], color="k") plt.text(0.5 * AU, -1.4 * b.a2, "1 AU", horizontalalignment='center') # display time plt.text(-1.4 * b.a2, -1.3 * b.a2, "time = %6.3f yr" % (s1.t[n] / year)) # display information about stars plt.text(-1.4 * b.a2, 1.3 * b.a2, r"mass ratio: %3.2f" % (b.M1 / b.M2), color="k") plt.text(-1.4 * b.a2, 1.1 * b.a2, r"eccentricity: %3.2f" % (b.e), color="k") # energies if annotate: KE1 = 0.5 * b.M1 * (s1.vx[n]**2 + s1.vy[n]**2) KE2 = 0.5 * b.M2 * (s2.vx[n]**2 + s2.vy[n]**2) PE = -G*b.M1*b.M2/ \ np.sqrt((s1.x[n] - s2.x[n])**2 + (s1.y[n] - s2.y[n])**2) print(KE1, KE2, PE, KE1 + KE2 + PE) # KE 1 sig, ex = find_scinotat(KE1) plt.text(0, 1.3 * b.a2, r"$K_1 =$") plt.text(0.3 * b.a2, 1.3 * b.a2, r"$%+4.2f \times 10^{%2d}$ erg" % (sig, ex)) sig, ex = find_scinotat(KE2) plt.text(0, 1.15 * b.a2, r"$K_2 =$") plt.text(0.3 * b.a2, 1.15 * b.a2, r"$%+4.2f \times 10^{%2d}$ erg" % (sig, ex)) sig, ex = find_scinotat(PE) plt.text(0, 1.0 * b.a2, r"$U =$") plt.text(0.3 * b.a2, 1.0 * b.a2, r"$%+4.2f \times 10^{%2d}$ erg" % (sig, ex)) sig, ex = find_scinotat(KE1 + KE2 + PE) plt.text(0, 0.85 * b.a2, r"$E =$") plt.text(0.3 * b.a2, 0.85 * b.a2, r"$%+4.2f \times 10^{%2d}$ erg" % (sig, ex)) plt.axis([-1.4 * b.a2, 1.4 * b.a2, -1.4 * b.a2, 1.4 * b.a2]) f = plt.gcf() f.set_size_inches(7.2, 7.2) plt.savefig("binary_star_%04d.png" % iframe) iframe += 1