コード例 #1
0
    def get_animation(self, s=300., fs=20., prop_type='real', figsize=None):
        '''
        Get time evolution animation.

        :param s: Default value 300. Circle size.
        :param fs: Default value 20. Fontsize.
        :param figsize: Tuple. Default value None. Figsize.
        :param prop_type: Default value None. Figsize.

        :returns:
          * **ani** -- Animation.
        '''
        error_handling.empty_ndarray(self.prop, 'get_propagation or get_pumping')
        error_handling.positive_real(s, 's')
        error_handling.positive_real(fs, 'fs')
        error_handling.prop_type(prop_type)
        error_handling.tuple_2elem(figsize, 'figsize')
        if os.name == 'posix':
            blit = False
        else:
            blit = True
        if prop_type == 'real':
            color = self.prop.real
            max_val = max(np.max(color), -np.min(color))
            ticks = [-max_val, max_val]
            cmap = 'seismic'
        elif prop_type == 'imag':
            color = self.prop.imag
            max_val = max(np.max(color), -np.min(color))
            ticks = [-max_val, max_val]
            cmap = 'seismic'
        else:
            color = np.abs(self.prop) ** 2
            ticks = [0., np.max(color)]
            cmap = 'Reds'
        fig, ax = plt.subplots(figsize=figsize)
        plt.xlim([self.lat.coor['x'][0]-1., self.lat.coor['x'][-1]+1.])
        plt.ylim([self.lat.coor['y'][0]-1., self.lat.coor['y'][-1]+1.])
        scat = plt.scatter(self.lat.coor['x'], self.lat.coor['y'], c=color[:, 0],
                                   s=s, vmin=ticks[0], vmax=ticks[1],
                                   cmap=plt.get_cmap(cmap))
        frame = plt.gca()
        frame.axes.get_xaxis().set_ticks([])
        frame.axes.get_yaxis().set_ticks([])
        ax.set_aspect('equal')
        if prop_type == 'norm':
            cbar = fig.colorbar(scat, ticks=ticks)
            cbar.ax.set_yticklabels(['0','max'])
        else:
            cbar = fig.colorbar(scat, ticks=[ticks[0], 0, ticks[1]])
            cbar.ax.set_yticklabels(['min', '0','max'])

        def update(i, color, scat):
            scat.set_array(color[:, i])
            return scat,

        ani = animation.FuncAnimation(fig, update, frames=self.steps,
                                                  fargs=(color, scat), blit=blit, repeat=False)
        return ani
コード例 #2
0
ファイル: propagation.py プロジェクト: cpoli/tbee
    def plt_propagation_1d(self, prop_type="real", fs=20, figsize=None):
        """
        Plot time evolution for 1D systems. 

        :param fs: Default value 20. Fontsize.
        """
        error_handling.empty_ndarray(self.prop, "get_propagation or get_pumping")
        error_handling.positive_real(fs, "fs")
        error_handling.prop_type(prop_type)
        error_handling.tuple_2elem(figsize, "figsize")
        fig, ax = plt.subplots(figsize=figsize)
        plt.ylabel("n", fontsize=fs)
        plt.xlabel("z", fontsize=fs)
        if prop_type == "real":
            color = self.prop_smooth_1d(self.prop.real)
            max_val = max(np.max(color), -np.min(color))
            ticks = [-max_val, max_val]
            cmap = "seismic"
        elif prop_type == "imag":
            color = self.prop_smooth_1d(self.prop.imag)
            max_val = max(np.max(color), -np.min(color))
            ticks = [-max_val, max_val]
            cmap = "seismic"
        else:
            color = self.prop_smooth_1d(np.abs(self.prop) ** 2)
            ticks = [0.0, np.max(color[:, -1])]
            cmap = plt.cm.hot
        extent = (-0, self.steps * self.dz, self.lat.sites - 0.5, -0.5)
        aspect = "auto"
        interpolation = "nearest"
        im = plt.imshow(
            color, cmap=cmap, aspect=aspect, interpolation=interpolation, extent=extent, vmin=ticks[0], vmax=ticks[-1]
        )
        for label in ax.xaxis.get_majorticklabels():
            label.set_fontsize(fs)
        for label in ax.yaxis.get_majorticklabels():
            label.set_fontsize(fs)
        ax.get_yaxis().set_major_locator(plt.MaxNLocator(integer=True))
        if prop_type == "norm":
            cbar = fig.colorbar(im, ticks=ticks)
            cbar.ax.set_yticklabels(["0", "max"])
        else:
            cbar = fig.colorbar(im, ticks=[ticks[0], 0, ticks[1]])
            cbar.ax.set_yticklabels(["min", "0", "max"])
        cbar.ax.tick_params(labelsize=fs)
        return fig
コード例 #3
0
    def plt_propagation_1d(self, prop_type='real', fs=20, figsize=None):
        '''
        Plot time evolution for 1D systems. 

        :param fs: Default value 20. Fontsize.
        '''
        error_handling.empty_ndarray(self.prop, 'get_propagation or get_pumping')
        error_handling.positive_real(fs, 'fs')
        error_handling.prop_type(prop_type)
        error_handling.tuple_2elem(figsize, 'figsize')
        fig, ax = plt.subplots(figsize=figsize)
        plt.ylabel('n', fontsize=fs)
        plt.xlabel('z', fontsize=fs)
        if prop_type == 'real':
            color = self.prop_smooth_1d(self.prop.real)
            max_val = max(np.max(color), -np.min(color))
            ticks = [-max_val, max_val]
            cmap = 'seismic'
        elif prop_type == 'imag':
            color = self.prop_smooth_1d(self.prop.imag)
            max_val = max(np.max(color), -np.min(color))
            ticks = [-max_val, max_val]
            cmap = 'seismic'
        else:
            color = self.prop_smooth_1d(np.abs(self.prop) ** 2)
            ticks = [0., np.max(color[:, -1])]
            cmap = plt.cm.hot
        extent = (-0, self.steps*self.dz, self.lat.sites-.5, -.5)
        aspect = 'auto'
        interpolation = 'nearest'
        im = plt.imshow(color, cmap=cmap, aspect=aspect,
                                  interpolation=interpolation, extent=extent,
                                  vmin=ticks[0], vmax=ticks[-1])
        for label in ax.xaxis.get_majorticklabels():
            label.set_fontsize(fs)
        for label in ax.yaxis.get_majorticklabels():
            label.set_fontsize(fs)
        ax.get_yaxis().set_major_locator(plt.MaxNLocator(integer=True))
        if prop_type == 'norm':
            cbar = fig.colorbar(im, ticks=ticks)
            cbar.ax.set_yticklabels(['0','max'])
        else:
            cbar = fig.colorbar(im, ticks=[ticks[0], 0, ticks[1]])
            cbar.ax.set_yticklabels(['min', '0','max'])
        cbar.ax.tick_params(labelsize=fs)
        return fig
コード例 #4
0
ファイル: propagation.py プロジェクト: cpoli/tbee
    def get_animation_nb(self, s=300.0, fs=20.0, prop_type="real", figsize=None):
        """
        Get time evolution animation for iPython notebooks.

        :param s: Default value 300. Circle shape.
        :param fs: Default value 20. Fontsize.

        :returns:
           * **ani** -- Animation.
        """
        """
        Get time evolution animation.

        :param s: Default value 300. Circle size.
        :param fs: Default value 20. Fontsize.
        :param figsize: Tuple. Default value None. Figsize.
        :param prop_type: Default value None. Figsize.

        :returns:
          * **ani** -- Animation.
        """
        error_handling.empty_ndarray(self.prop, "get_propagation or get_pumping")
        error_handling.positive_real(s, "s")
        error_handling.positive_real(fs, "fs")
        error_handling.prop_type(prop_type)
        error_handling.tuple_2elem(figsize, "figsize")
        if prop_type == "real" or prop_type == "imag":
            color = self.prop.real
            max_val = max(np.max(color[:, -1]), -np.min(color[:, -1]))
            ticks = [-max_val, max_val]
            cmap = "seismic"
        else:
            color = np.abs(self.prop) ** 2
            ticks = [0.0, np.max(color)]
            cmap = "Reds"
        fig = plt.figure()
        ax = plt.axes(
            xlim=(np.min(self.lat.coor["x"] - 0.5), np.max(self.lat.coor["x"] + 0.5)),
            ylim=(np.min(self.lat.coor["y"] - 0.5), np.max(self.lat.coor["y"] + 0.5)),
        )
        ax.set_aspect("equal")
        frame = plt.gca()
        frame.axes.get_xaxis().set_ticks([])
        frame.axes.get_yaxis().set_ticks([])
        scat = plt.scatter(
            self.lat.coor["x"], self.lat.coor["y"], c=color[:, 0], s=s, vmin=ticks[0], vmax=ticks[1], cmap=cmap
        )
        if prop_type == "real" or prop_type == "imag":
            cbar = fig.colorbar(scat, ticks=[ticks[0], 0, ticks[1]])
            cbar.ax.set_yticklabels(["min", "0", "max"])
        else:
            cbar = fig.colorbar(scat, ticks=[0, ticks[1]])
            cbar.ax.set_yticklabels(["0", "max"])

        def init():
            scat.set_array(color[:, 0])
            return (scat,)

        def animate(i):
            scat.set_array(color[:, i])
            return (scat,)

        return animation.FuncAnimation(fig, animate, init_func=init, frames=self.steps, interval=120, blit=True)
コード例 #5
0
ファイル: propagation.py プロジェクト: cpoli/tbee
    def get_animation(self, s=300.0, fs=20.0, prop_type="real", figsize=None):
        """
        Get time evolution animation.

        :param s: Default value 300. Circle size.
        :param fs: Default value 20. Fontsize.
        :param figsize: Tuple. Default value None. Figsize.
        :param prop_type: Default value None. Figsize.

        :returns:
          * **ani** -- Animation.
        """
        error_handling.empty_ndarray(self.prop, "get_propagation or get_pumping")
        error_handling.positive_real(s, "s")
        error_handling.positive_real(fs, "fs")
        error_handling.prop_type(prop_type)
        error_handling.tuple_2elem(figsize, "figsize")
        if os.name == "posix":
            blit = False
        else:
            blit = True
        if prop_type == "real":
            color = self.prop.real
            max_val = max(np.max(color), -np.min(color))
            ticks = [-max_val, max_val]
            cmap = "seismic"
        elif prop_type == "imag":
            color = self.prop.imag
            max_val = max(np.max(color), -np.min(color))
            ticks = [-max_val, max_val]
            cmap = "seismic"
        else:
            color = np.abs(self.prop) ** 2
            ticks = [0.0, np.max(color)]
            cmap = "Reds"
        fig, ax = plt.subplots(figsize=figsize)
        plt.xlim([self.lat.coor["x"][0] - 1.0, self.lat.coor["x"][-1] + 1.0])
        plt.ylim([self.lat.coor["y"][0] - 1.0, self.lat.coor["y"][-1] + 1.0])
        scat = plt.scatter(
            self.lat.coor["x"],
            self.lat.coor["y"],
            c=color[:, 0],
            s=s,
            vmin=ticks[0],
            vmax=ticks[1],
            cmap=plt.get_cmap(cmap),
        )
        frame = plt.gca()
        frame.axes.get_xaxis().set_ticks([])
        frame.axes.get_yaxis().set_ticks([])
        ax.set_aspect("equal")
        if prop_type == "norm":
            cbar = fig.colorbar(scat, ticks=ticks)
            cbar.ax.set_yticklabels(["0", "max"])
        else:
            cbar = fig.colorbar(scat, ticks=[ticks[0], 0, ticks[1]])
            cbar.ax.set_yticklabels(["min", "0", "max"])

        def update(i, color, scat):
            scat.set_array(color[:, i])
            return (scat,)

        ani = animation.FuncAnimation(fig, update, frames=self.steps, fargs=(color, scat), blit=blit, repeat=False)
        return ani
コード例 #6
0
    def get_animation_nb(self, s=300., fs=20., prop_type='real', figsize=None):
        '''
        Get time evolution animation for iPython notebooks.

        :param s: Default value 300. Circle shape.
        :param fs: Default value 20. Fontsize.

        :returns:
           * **ani** -- Animation.
        '''
        '''
        Get time evolution animation.

        :param s: Default value 300. Circle size.
        :param fs: Default value 20. Fontsize.
        :param figsize: Tuple. Default value None. Figsize.
        :param prop_type: Default value None. Figsize.

        :returns:
          * **ani** -- Animation.
        '''
        error_handling.empty_ndarray(self.prop, 'get_propagation or get_pumping')
        error_handling.positive_real(s, 's')
        error_handling.positive_real(fs, 'fs')
        error_handling.prop_type(prop_type)
        error_handling.tuple_2elem(figsize, 'figsize')
        if prop_type == 'real' or prop_type == 'imag':
            color = self.prop.real
            max_val = max(np.max(color[:, -1]), -np.min(color[:, -1]))
            ticks = [-max_val, max_val]
            cmap = 'seismic'
        else:
            color = np.abs(self.prop) ** 2
            ticks = [0., np.max(color)]
            cmap = 'Reds'
        fig = plt.figure()
        ax = plt.axes(xlim=(np.min(self.lat.coor['x']-.5), np.max(self.lat.coor['x']+.5)), 
                             ylim=(np.min(self.lat.coor['y']-.5), np.max(self.lat.coor['y']+.5)))
        ax.set_aspect('equal')
        frame = plt.gca()
        frame.axes.get_xaxis().set_ticks([])
        frame.axes.get_yaxis().set_ticks([])
        scat = plt.scatter(self.lat.coor['x'], self.lat.coor['y'], c=color[:, 0],
                                    s=s, vmin=ticks[0], vmax=ticks[1],
                                    cmap=cmap)
        if prop_type == 'real' or prop_type == 'imag':
            cbar = fig.colorbar(scat, ticks=[ticks[0], 0, ticks[1]])
            cbar.ax.set_yticklabels(['min', '0','max'])
        else:
            cbar = fig.colorbar(scat, ticks=[0, ticks[1]])
            cbar.ax.set_yticklabels(['0','max'])

        def init():
            scat.set_array(color[:, 0])
            return scat,

        def animate(i):
            scat.set_array(color[:, i])    
            return scat,

        return animation.FuncAnimation(fig, animate, init_func=init,
                                   frames=self.steps, interval=120, blit=True)