def test_occultations(): """Test occultation light curves.""" # Let's do the l = 3 Earth m = Map(3) m.load_image('earth') # Rotate the map about a random axis ux = np.random.random() uy = np.random.random() * (1 - ux) uz = np.sqrt(1 - ux ** 2 - uy ** 2) axis = [ux, uy, uz] npts = 30 theta = np.linspace(0, 360, npts, endpoint=False) # Small occultor ro = 0.3 xo = np.linspace(-1 - ro - 0.1, 1 + ro + 0.1, npts) yo = 0 # Analytical and numerical fluxes sF = np.array(m.flux(axis=axis, theta=theta, xo=xo, yo=yo, ro=ro)) nF = np.array(m._flux_numerical(axis=axis, theta=theta, xo=xo, yo=yo, ro=ro, tol=1e-6)) # Compute the (relative) error error = np.max(np.abs(sF - nF)) # Our numerical integration scheme isn't the most accurate, # so let's be lenient here! assert error < 1e-2
for j, m in enumerate(range(lmax + 1)): ax[-1, j].set_xlabel(r"$m = %d$" % m, labelpad=30, fontsize=12) # Occultation params y = Map(lmax) ro = 0.25 xo = np.linspace(-1.5, 1.5, nt) xon = np.linspace(-1.5, 1.5, nn) for yo, zorder, color in zip([0.25, 0.75], [1, 0], ['C0', 'C1']): for i, l in enumerate(range(lmax + 1)): for j, m in enumerate(range(l + 1)): y.reset() y.set_coeff(l, m, 1) flux = y.flux(axis=[1, 0, 0], theta=0, xo=xo, yo=yo, ro=ro) ax[i, j].plot(xo, flux, lw=1, zorder=zorder, color=color) fluxn = y._flux_numerical(axis=[1, 0, 0], theta=0, xo=xon, yo=yo, ro=ro, tol=1e-5) ax[i, j].plot(xon, fluxn, '.', ms=2, zorder=zorder, color=color) # Hack a legend axleg = pl.axes([0.7, 0.7, 0.15, 0.15]) axleg.plot([0, 0], [1, 1], label=r'$y_0 = 0.25$') axleg.plot([0, 0], [1, 1], label=r'$y_0 = 0.75$') axleg.axis('off') leg = axleg.legend(title=r'Occultations', fontsize=18) leg.get_title().set_fontsize('20') leg.get_frame().set_linewidth(0.0) # Save! fig.savefig("ylmlightcurves.pdf", bbox_inches='tight') pl.close(fig)
# Rotate about this vector ux = np.array([1., 0., 0.]) uy = np.array([0., 1., 0.]) y = Map(lmax) theta = np.linspace(0, 360, nt, endpoint=False) thetan = np.linspace(0, 360, nn, endpoint=False) for i, l in enumerate(range(lmax + 1)): for j, m in enumerate(range(l + 1)): nnull = 0 for axis, zorder, color in zip([ux, uy], [1, 0], ['C0', 'C1']): y.reset() y.set_coeff(l, m, 1) flux = y.flux(axis=axis, theta=theta) ax[i, j].plot(theta, flux, lw=1, zorder=zorder, color=color) fluxn = y._flux_numerical(axis=axis, theta=thetan, tol=1e-5) ax[i, j].plot(thetan, fluxn, '.', ms=2, zorder=zorder, color=color) if np.max(np.abs(flux)) < 1e-10: nnull += 1 # If there's no light curve, make sure our plot range # isn't too tight, as it will zoom in on floating point error if nnull == 2: ax[i, j].set_ylim(-1, 1) # Force the scale for the constant map ax[0, 0].set_ylim(0.886 + 1, 0.886 - 1) # Hack a legend axleg = pl.axes([0.7, 0.7, 0.15, 0.15]) axleg.plot([0, 0], [1, 1], label=r'$\vec{u} = \hat{x}$') axleg.plot([0, 0], [1, 1], label=r'$\vec{u} = \hat{y}$') axleg.axis('off')
for continent, label in zip(continents, labels): m.load_image(continent) m.rotate([0, 1, 0], -180) F = m.flux(axis=[0, 1, 0], theta=theta) F -= np.nanmin(F) ax.plot(theta - 180, F, label=label) # Compute and plot the total phase curve m.load_image('earth.jpg') m.rotate([0, 1, 0], -180) total = m.flux(axis=[0, 1, 0], theta=theta) total /= np.max(total) ax.plot(theta - 180, total, 'k-', label='Total') # Compute and plot the total phase curve (numerical) totalnum = m._flux_numerical(axis=[0, 1, 0], theta=thetanum, tol=1e-5) totalnum /= np.max(totalnum) ax.plot(thetanum - 180, totalnum, 'k.') # Appearance ax.set_xlim(-180, 180) ax.set_ylim(-0.05, 1.2) ax.set_xticks([-180, -135, -90, -45, 0, 45, 90, 135, 180]) ax.set_yticks([0.0, 0.2, 0.4, 0.6, 0.8, 1.0]) ax.legend(loc='best', fontsize=11, ncol=2) ax.set_xlabel('Sub-observer longitude [deg]', fontsize=18) ax.set_ylabel('Normalized flux', fontsize=18) for tick in ax.get_xticklabels() + ax.get_yticklabels(): tick.set_fontsize(16) # Plot the earth images
# Say the occultation occurs over ~1 radian of the Earth's rotation # That's equal to 24 / (2 * pi) hours # (Remember, though, that `starry` accepts **DEGREES** as input!) time = np.linspace(0, 24 / (2 * np.pi), npts) timenum = np.linspace(0, 24 / (2 * np.pi), nptsnum) theta0 = 0 theta = np.linspace(theta0, theta0 + 180. / np.pi, npts, endpoint=True) thetanum = np.linspace(theta0, theta0 + 180. / np.pi, nptsnum, endpoint=True) # Compute and plot the flux F = m.flux(axis=[0, 1, 0], theta=theta, xo=xo, yo=yo, ro=ro) F /= np.max(F) ax_lc.plot(time, F, 'k-', label='Total') # Compute and plot the numerical flux Fnum = m._flux_numerical(axis=[0, 1, 0], theta=thetanum, xo=xonum, yo=yonum, ro=ro, tol=1e-5) Fnum /= np.max(Fnum) ax_lc.plot(timenum, Fnum, 'k.') # Plot the earth images x, y = np.meshgrid(np.linspace(-1, 1, res), np.linspace(-1, 1, res)) for n in range(nim): i = int(np.linspace(0, npts - 1, nim)[n]) I = [m.evaluate(axis=[0, 1, 0], theta=theta[i], x=x[j], y=y[j]) for j in range(res)] ax_im[n].imshow(I, origin="lower", interpolation="none", cmap='plasma', extent=(-1, 1, -1, 1)) xm = np.linspace(xo[i] - ro + 1e-5, xo[i] + ro - 1e-5, res) ax_im[n].fill_between(xm, yo[i] - np.sqrt(ro ** 2 - (xm - xo[i]) ** 2), yo[i] + np.sqrt(ro ** 2 - (xm - xo[i]) ** 2), color='w')