def rotate_plot_atoms(atoms, radii=1.0, rotation_list=None, interval=40, jsHTML=False): """Plots the *atoms* object through the *rotation_list*. If properly structured, this would result in the atoms rotating. This function makes use of ASE's plot_atoms function. In Jupyter notebook, the *notebook* backend should be used. (%matplotlib notebook) Parameters: atoms: Atoms instance radii: float interval: int cut_off: float rotation_list: list A list of rotation coordinates accepted by plot_atoms. """ if rotation_list is None: rotation_list = ['90x, {}y, 0z'.format(x) for x in range(360)] def update_plot_atoms(num): cur_rotation = rotation_list[num] ax.cla() ax.set_axis_off() plot_atoms(atoms, ax=ax, radii=radii, rotation=cur_rotation) return ax, fig, ax = plt.subplots() ax.set_axis_off() ani = animation.FuncAnimation(fig, update_plot_atoms, len(rotation_list), interval=40, blit=False, repeat=True) if jsHTML: from IPython.display import HTML ani = HTML(ani.to_jshtml()) return ani
def animate(self, NSB=None): """ Show an interactive animation of camera frames. Parameters ---------- NSB : float Night sky background in MHz/m$^2$/deg$^2$. If not given, the one defined in Image is used. Returns ------- ani : HTML object. """ N_pix = self.N_pix N_pix_r = self.N_pix_r N_frames = self.N_frames frames = self.frames # Image size N = 2 * N_pix_r +1 # If no signal, an empty plot is generated if N_frames == 0: fig = plt.figure(figsize=(5, 5)) plt.text(0.4, 0.5, 'No signal') return fig # The NSB defined in image is used if NSB is None: NSB_pix = self.NSB_pix # The input NSB is used else: telescope = self.signal.telescope int_time = self.int_time sol_angle_pix = self.sol_angle_pix NSB_pix = (NSB * 90.**2 / math.pi**2 * telescope.area * sol_angle_pix * int_time) fig = plt.figure() extent = (-N_pix_r-0.5, N_pix_r+0.5, -N_pix_r-0.5, N_pix_r+0.5) # Same color scale for all frames vmax = frames.max() vmin = 0. # List of AxesSubplot objects to pass to ArtistAnimation function ims = [] for i, f in enumerate(frames): # Noise of a single frame noise = np.array( np.random.poisson(NSB_pix, (N, N)), float) f += noise im = plt.imshow(f, extent=extent, vmin=vmin, vmax=vmax) ims.append([im]) # One only colorbar cbar = fig.colorbar(im) cbar.ax.set_ylabel('Photoelectrons'); ani = animation.ArtistAnimation(fig, ims, interval=100, blit=True, repeat_delay=500) # Interactive HTML object ani = HTML(ani.to_jshtml()) return ani