Пример #1
0
    def plot_contour(self,
                     comp,
                     plane,
                     axis_val,
                     time=None,
                     fig=None,
                     ax=None,
                     pcolor_kw=None,
                     **kwargs):
        fig, ax = cplt.create_fig_ax_with_squeeze(fig, ax, **kwargs)
        pcolor_kw = cplt.update_pcolor_kw(pcolor_kw)

        time = self.check_times(time)
        comp = self.check_comp(comp)

        plane, coord = self.CoordDF.check_plane(plane)

        axis_index = self.CoordDF.index_calc(coord, axis_val)
        flow_slice = indexing.contour_indexer(self[time, comp], axis_index,
                                              coord)

        x_coord = self.CoordDF[plane[0]]
        y_coord = self.CoordDF[plane[1]]

        X, Y = np.meshgrid(x_coord, y_coord)

        ax = ax.pcolormesh(X, Y, flow_slice.squeeze(), **pcolor_kw)

        return fig, ax
    def plot_contour(self,comp,modes,fig=None,ax=None,pcolor_kw=None,**kwargs):
        
        kwargs = cplt.update_subplots_kw(kwargs,figsize=[7,5])
        fig, ax = cplt.create_fig_ax_with_squeeze(fig=fig,ax=ax,**kwargs)
        coeffs = self.POD_coeffs[sorted(modes)]
        reconstruct_arrays = np.multiply(self.POD.POD_modesDF[comp][:,:,modes],coeffs)
        
        flow_reconstruct = np.sum(reconstruct_arrays,axis=-1)

        x_array = self.avg_data.CoordDF[self.POD._plane[0]]
        y_array = self.avg_data.CoordDF[self.POD._plane[1]]

        X, Z = np.meshgrid(x_array, y_array)
        pcolor_kw = cplt.update_pcolor_kw(pcolor_kw)

        ax1 = ax.pcolormesh(X,Z,flow_reconstruct,**pcolor_kw)
        ax1.axes.set_xlabel(r"$%s/\delta$" % self.POD._plane[0])
        ax1.axes.set_ylabel(r"$%s/\delta$" % self.POD._plane[1])

        ax1.axes.set_aspect('equal')

        cbar=fig.colorbar(ax1,ax=ax)
        cbar.set_label(r"$%s^\prime$"%comp)

        fig.tight_layout()

        return fig, ax1
Пример #3
0
    def spectrum_contour(self,
                         comp,
                         axis_vals,
                         axis_mode='half_channel',
                         fig=None,
                         ax=None,
                         pcolor_kw=None,
                         **kwargs):
        if not comp in ('x', 'z'):
            raise ValueError(" Variable `comp' must eiher be 'x' or 'z'\n")

        axis_vals = misc_utils.check_list_vals(axis_vals)
        y_index_axis_vals = indexing.y_coord_index_norm(
            self._avg_data, axis_vals, None, axis_mode)
        Ruu_all = self.autocorrDF[comp]  #[:,axis_vals,:]
        shape = Ruu_all.shape
        Ruu = np.zeros((shape[0], len(axis_vals), shape[2]))
        for i, vals in zip(range(shape[2]), y_index_axis_vals):
            Ruu[:, :, i] = Ruu_all[:, vals, i]

        kwargs = cplt.update_subplots_kw(kwargs,
                                         figsize=[10, 4 * len(axis_vals)])
        fig, ax = cplt.create_fig_ax_without_squeeze(len(axis_vals),
                                                     fig=fig,
                                                     ax=ax,
                                                     **kwargs)

        coord = self._meta_data.CoordDF[comp].copy()[:shape[0]]
        x_axis = self._avg_data._return_xaxis()

        pcolor_kw = cplt.update_pcolor_kw(pcolor_kw)

        for i in range(len(axis_vals)):
            wavenumber_spectra = np.zeros((int(0.5 * shape[0]) + 1, shape[2]),
                                          dtype=np.complex128)
            for j in range(shape[2]):
                wavenumber_spectra[:, j] = fft.rfft(Ruu[:, i, j])
            comp_size = shape[0]
            wavenumber_comp = 2 * np.pi * fft.rfftfreq(comp_size,
                                                       coord[1] - coord[0])

            X, Y = np.meshgrid(x_axis, wavenumber_comp)
            ax[i] = ax[i].pcolormesh(X, Y, np.abs(wavenumber_spectra),
                                     **pcolor_kw)

            ax[i].axes.set_ylabel(r"$\kappa_%s$" % comp)

            title = r"$%s=%.3g$"%("y" if axis_mode=='half_channel' \
                        else r"\delta_u" if axis_mode=='disp_thickness' \
                        else r"\theta" if axis_mode=='mom_thickness' else "y^+", axis_vals[i] )

            ax[i].axes.set_ylim(
                [np.amin(wavenumber_comp[1:]),
                 np.amax(wavenumber_comp)])
            ax[i].axes.set_title(title)  # ,fontsize=15,loc='left')

            fig.colorbar(ax[i], ax=ax[i].axes)

        return fig, ax
Пример #4
0
    def autocorr_contour_x(self,
                           comp,
                           axis_vals,
                           axis_mode='half_channel',
                           norm=True,
                           fig=None,
                           ax=None,
                           pcolor_kw=None,
                           **kwargs):
        if not comp in ('x', 'z'):
            raise ValueError(" Variable `comp' must eiher be 'x' or 'z'\n")

        axis_vals = misc_utils.check_list_vals(axis_vals)

        y_index_axis_vals = indexing.y_coord_index_norm(
            self._avg_data, axis_vals, None, axis_mode)

        Ruu_all = self.autocorrDF[comp].copy()
        shape = Ruu_all.shape

        Ruu = np.zeros((shape[0], len(axis_vals), shape[2]))
        for i, vals in zip(range(shape[2]), y_index_axis_vals):
            Ruu[:, :, i] = Ruu_all[:, vals, i]

        if norm:
            Ruu_0 = Ruu[0].copy()
            for i in range(shape[0]):
                Ruu[i] /= Ruu_0

        kwargs = cplt.update_subplots_kw(kwargs,
                                         figsize=[10, 4 * len(axis_vals)])
        fig, ax = cplt.create_fig_ax_without_squeeze(len(axis_vals),
                                                     fig=fig,
                                                     ax=ax,
                                                     **kwargs)

        x_axis = self._avg_data._return_xaxis()
        coord = self._meta_data.CoordDF[comp].copy()[:shape[0]]
        pcolor_kw = cplt.update_pcolor_kw(pcolor_kw)
        ax_out = []
        for i in range(len(axis_vals)):

            X, Y = np.meshgrid(x_axis, coord)
            ax[i] = ax[i].pcolormesh(X, Y, Ruu[:, i], **pcolor_kw)
            ax[i].axes.set_ylabel(r"$\Delta %s/\delta$" % comp)
            title = r"$%s=%.3g$"%("y" if axis_mode=='half_channel' \
                        else r"\delta_u" if axis_mode=='disp_thickness' \
                        else r"\theta" if axis_mode=='mom_thickness' else r"y^+", axis_vals[i] )
            ax[i].axes.set_title(title, loc='left')
            fig.colorbar(ax[i], ax=ax[i].axes)

        fig.tight_layout()

        return fig, ax
Пример #5
0
    def plot_mode_contour(self,
                          comp,
                          modes,
                          fig=None,
                          ax=None,
                          pcolor_kw=None,
                          **kwargs):
        modes = misc_utils.check_list_vals(modes)
        ax_layout = len(modes)
        figsize = [10, 3 * len(modes)]
        kwargs = cplt.update_subplots_kw(kwargs, figsize=figsize)
        fig, ax = cplt.create_fig_ax_without_squeeze(ax_layout,
                                                     fig=fig,
                                                     ax=ax,
                                                     **kwargs)

        pcolor_kw = cplt.update_pcolor_kw(pcolor_kw)
        x_coords = self.avg_data.CoordDF[self._plane[0]]
        y_coords = self.avg_data.CoordDF[self._plane[1]]

        X, Y = np.meshgrid(x_coords, y_coords)
        PODmodes = self.POD_modesDF[None, comp]

        coord = list('xyz')
        coord.remove(self._plane[0])
        coord.remove(self._plane[1])

        for i, mode in enumerate(modes):

            ax[i] = ax[i].pcolormesh(X, Y, PODmodes[:, :, mode], **pcolor_kw)

            ax[i].axes.set_xlabel(r"$%s/\delta$" % self._plane[0])
            ax[i].axes.set_ylabel(r"$%s/\delta$" % self._plane[1])
            ax[i].axes.set_title(r"Mode %d" % (mode + 1), loc='left')
            ax[i].axes.set_title(r"$%s/\delta$" % coord[0], loc='right')

        return fig, ax
Пример #6
0
    def create_video(cls,
                     axis_vals,
                     comp,
                     avg_data=None,
                     contour=True,
                     plane='xz',
                     meta_data=None,
                     path_to_folder='.',
                     time_range=None,
                     abs_path=True,
                     tgpost=False,
                     x_split_list=None,
                     plot_kw=None,
                     lim_min=None,
                     lim_max=None,
                     ax_func=None,
                     fluct_func=None,
                     fluct_args=(),
                     fluct_kw={},
                     fig=None,
                     ax=None,
                     **kwargs):

        times = misc_utils.time_extract(path_to_folder, abs_path)
        max_time = np.amax(times) if time_range is None else time_range[1]

        if avg_data is None and not tgpost:
            time0 = time_range[0] if time_range is not None else None
            avg_data = cls._module._avg_class(max_time,
                                              meta_data,
                                              path_to_folder,
                                              time0,
                                              abs_path,
                                              tgpost=cls.tgpost)

        axis_vals = misc_utils.check_list_vals(axis_vals)

        if x_split_list is None:
            if meta_data is None:
                meta_data = cls._module._meta_class(path_to_folder,
                                                    abs_path,
                                                    tgpost=tgpost)
            x_coords = meta_data.CoordDF['x']
            x_split_list = [np.min(x_coords), np.max(x_coords)]

        if fig is None:
            if 'figsize' not in kwargs.keys():
                kwargs['figsize'] = [
                    7 * len(axis_vals), 3 * (len(x_split_list) - 1)
                ]
            fig = cplt.figure(**kwargs)
        if contour:
            plot_kw = cplt.update_pcolor_kw(plot_kw)

        def func(fig, time):
            axes = fig.axes
            for ax in axes:
                ax.remove()

            fluct_data = cls(time,
                             avg_data,
                             path_to_folder=path_to_folder,
                             abs_path=abs_path)

            if contour:
                fig, ax = fluct_data.plot_contour(comp,
                                                  axis_vals,
                                                  plane=plane,
                                                  PhyTime=time,
                                                  x_split_list=x_split_list,
                                                  fig=fig,
                                                  pcolor_kw=plot_kw)
            else:
                fig, ax = fluct_data.plot_fluct3D_xz(axis_vals, comp, time,
                                                     x_split_list, fig,
                                                     **plot_kw)
            ax[0].axes.set_title(r"$t^*=%.3g$" % time, loc='left')
            if fluct_func is not None:
                fluct_func(fig, ax, time, *fluct_args, **fluct_kw)
            if ax_func is not None:
                ax = ax_func(ax)
            for im in ax:
                im.set_clim(vmin=lim_min)
                im.set_clim(vmax=lim_max)

            fig.tight_layout()
            return ax

        return cplt.create_general_video(fig,
                                         path_to_folder,
                                         abs_path,
                                         func,
                                         time_range=time_range)
Пример #7
0
    def autocorr_contour_y(self,
                           comp,
                           axis_vals,
                           Y_plus=False,
                           Y_plus_0=False,
                           Y_plus_max=None,
                           norm=True,
                           show_positive=True,
                           fig=None,
                           ax=None,
                           pcolor_kw=None,
                           **kwargs):
        if comp not in ('x', 'z'):
            raise ValueError(" Variable `comp' must eiher be 'x' or 'z'\n")

        if not hasattr(axis_vals, '__iter__'):
            axis_vals = [axis_vals]
        axis_index = [
            self._avg_data._return_index(x) for x in axis_vals
        ]  #CT.coord_index_calc(self._meta_data.CoordDF,'x',axis_vals)

        shape = self.autocorrDF[comp].shape
        Ruu = self.autocorrDF[comp][:, :, axis_index].copy()

        if norm:
            Ruu_0 = Ruu[0].copy()
            for i in range(shape[0]):
                Ruu[i] /= Ruu_0

        kwargs = cplt.update_subplots_kw(kwargs,
                                         figsize=[10, 4 * len(axis_vals)])
        fig, ax = cplt.create_fig_ax_without_squeeze(len(axis_vals),
                                                     fig=fig,
                                                     ax=ax,
                                                     **kwargs)

        pcolor_kw = cplt.update_pcolor_kw(pcolor_kw)
        max_val = -np.float('inf')
        min_val = np.float('inf')

        for i, _ in enumerate(axis_vals):
            y_coord = self._meta_data.CoordDF['y'].copy()
            coord = self._meta_data.CoordDF[comp].copy()[:shape[0]]
            if Y_plus:
                avg_time = self._avg_data.flow_AVGDF.index[0][0]
                _, delta_v_star = self._avg_data.wall_unit_calc(avg_time)
                y_coord = y_coord[:int(y_coord.size / 2)]
                if i == 0:
                    Ruu = Ruu[:, :y_coord.size]
                if Y_plus_0:
                    y_coord = (1 - np.abs(y_coord)) / delta_v_star[0]
                else:
                    y_coord = (1 -
                               np.abs(y_coord)) / delta_v_star[axis_index[i]]

            min_val = min(min_val, np.amin(np.squeeze(Ruu[:, :, i])))
            max_val = max(max_val, np.amax(np.squeeze(Ruu[:, :, i])))

            X, Y = np.meshgrid(coord, y_coord)
            ax[i] = ax[i].pcolormesh(X, Y,
                                     np.squeeze(Ruu[:, :, i]).T, **pcolor_kw)

            ax[i].axes.set_xlabel(r"$\Delta %s/\delta$" % comp)
            if Y_plus and Y_plus_0:
                ax[i].axes.set_ylabel(r"$Y^{+0}$")
            elif Y_plus and not Y_plus_0:
                ax[i].axes.set_ylabel(r"$Y^{+}$")
            else:
                ax[i].axes.set_ylabel(r"$y/\delta$")

            if Y_plus_max is not None:
                ax[i].axes.set_ylim(top=Y_plus_max)

            fig.colorbar(ax[i], ax=ax[i].axes)
            fig.tight_layout()

        for a in ax:
            a.set_clim(min_val, max_val)

        if not show_positive:
            for a in ax:
                cmap = a.get_cmap()
                min_val, max_val = a.get_clim()
                new_color = cmap(np.linspace(0, 1, 256))[::-1]
                new_color[-1] = np.array([1, 1, 1, 1])
                a.set_cmap(mpl.colors.ListedColormap(new_color))
                a.set_clim(min_val, 0)

        return fig, ax