def static(lmax=5, res=300): """Plot a static PDF figure.""" # Set up the plot fig, ax = pl.subplots(lmax + 1, 2 * lmax + 1, figsize=(9, 6)) fig.subplots_adjust(hspace=0) for axis in ax.flatten(): axis.set_xticks([]) axis.set_yticks([]) axis.spines['top'].set_visible(False) axis.spines['right'].set_visible(False) axis.spines['bottom'].set_visible(False) axis.spines['left'].set_visible(False) for l in range(lmax + 1): ax[l, 0].set_ylabel(r"$l = %d$" % l, rotation='horizontal', labelpad=30, y=0.38, fontsize=12) for j, m in enumerate(range(-lmax, lmax + 1)): if m < 0: ax[-1, j].set_xlabel(r"$m {=} \mathrm{-}%d$" % -m, labelpad=30, fontsize=11) else: ax[-1, j].set_xlabel(r"$m = %d$" % m, labelpad=30, fontsize=11) # Plot it x = np.linspace(-1, 1, res) y = np.linspace(-1, 1, res) X, Y = np.meshgrid(x, y) map = Map(lmax) # Loop over the orders and degrees for i, l in enumerate(range(lmax + 1)): for j, m in enumerate(range(-l, l + 1)): # Offset the index for centered plotting j += lmax - l # Compute the spherical harmonic # with no rotation map.reset() map[l, m] = 1 flux = [map(x=X[j], y=Y[j]) for j in range(res)] # Plot the spherical harmonic ax[i, j].imshow(flux, cmap='plasma', interpolation="none", origin="lower", extent=(-1, 1, -1, 1)) ax[i, j].set_xlim(-1.1, 1.1) ax[i, j].set_ylim(-1.1, 1.1) # Save! fig.savefig("ylms.pdf", bbox_inches="tight") pl.close()
ax[l, 0].set_ylabel(r"$l = %d$" % l, rotation='horizontal', labelpad=30, y=0.38, fontsize=12) 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)
class animated(): """Plot an animated GIF showing rotation of the Ylms.""" def __init__(self, lmax=5, res=300, dpi=100, fps=10, frames=50, axis=[0., 1., 0.]): """Initialize.""" self.lmax = lmax self.map = Map(lmax) self.res = res self.axis = axis self.frames = frames x = np.linspace(-1, 1, res) y = np.linspace(-1, 1, res) self.X, self.Y = np.meshgrid(x, y) # Set up the plot self.fig, self.ax = pl.subplots(self.lmax + 1, 2 * self.lmax + 1, figsize=(9, 6)) self.fig.subplots_adjust(hspace=0) for axis in self.ax.flatten(): axis.set_xticks([]) axis.set_yticks([]) axis.spines['top'].set_visible(False) axis.spines['right'].set_visible(False) axis.spines['bottom'].set_visible(False) axis.spines['left'].set_visible(False) for l in range(self.lmax + 1): self.ax[l, 0].set_ylabel(r"$l = %d$" % l, rotation='horizontal', labelpad=30, y=0.38, fontsize=12) for j, m in enumerate(range(-self.lmax, self.lmax + 1)): self.ax[-1, j].set_xlabel(r"$m = %d$" % m, labelpad=30, fontsize=12) # Loop over the orders and degrees self.img = [] for i, l in enumerate(range(self.lmax + 1)): for j, m in enumerate(range(-l, l + 1)): # Offset the index for centered plotting j += self.lmax - l # Compute the spherical harmonic self.map.reset() self.map[l, m] = 1 flux = [ self.map(theta=0, x=self.X[j], y=self.Y[j]) for j in range(res) ] # Plot the spherical harmonic img = self.ax[i, j].imshow(flux, cmap='plasma', interpolation="none", origin="lower") self.img.append(img) # Set up the animation self.theta = np.linspace(0, 360, frames, endpoint=False) self.animation = animation.FuncAnimation(self.fig, self.animate, frames=self.frames, interval=50, repeat=True, blit=True) # Save self.animation.save('ylms.gif', writer='imagemagick', fps=fps, dpi=dpi) pl.close() def animate(self, j): """Run the animation.""" print("Rendering frame %d/%d..." % (j + 1, self.frames)) # Rotate the spherical harmonics n = 0 theta = self.theta[j] for i, l in enumerate(range(self.lmax + 1)): for j, m in enumerate(range(-l, l + 1)): self.map.reset() self.map[l, m] = 1 self.map.axis = self.axis flux = self.map(theta=theta, x=self.X, y=self.Y) self.img[n].set_data(flux) n += 1 return self.img
ax[l, 0].set_ylabel(r"$l = %d$" % l, rotation='horizontal', labelpad=30, y=0.38, fontsize=12) for j, m in enumerate(range(lmax + 1)): ax[-1, j].set_xlabel(r"$m = %d$" % m, labelpad=30, fontsize=12) # Occultation params map = 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)): map.reset() map[0, 0] = 0 map[l, m] = 1 flux = map.flux(theta=0, xo=xo, yo=yo, ro=ro) ax[i, j].plot(xo, flux, lw=1, zorder=zorder, color=color) fluxn = map.flux(theta=0, xo=xon, yo=yo, ro=ro, numerical=True) 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)