viz_utils/eoa_viz.py
def plot_3d_data_npdict(self, np_variables:list, var_names:list, z_levels= [], title='',
                          file_name_prefix='', cmap=None, z_names = [],
                          show_color_bar=True, plot_mode=PlotMode.RASTER, mincbar=np.nan, maxcbar=np.nan):
        """
        Plots multiple z_levels for multiple fields.
        It uses rows for each depth, and columns for each variable
        """
        create_folder(self._output_folder)
        orig_cmap = cmap

        # If the user do not requires any z-leve, then all are plotted
        if len(z_levels) == 0:
            z_levels = range(np_variables[var_names[0]].shape[0])

        cols = np.min((self._max_imgs_per_row, len(var_names)))
        if cols == len(var_names):
            rows = len(z_levels)
        else:
            rows = int(len(z_levels) * np.ceil(len(var_names)/cols))

        fig, _axs = plt.subplots(rows, cols,
                                 figsize=self.get_proper_size(rows, cols),
                                 subplot_kw={'projection': self._projection})

        for c_zlevel, c_slice in enumerate(z_levels):  # Iterates over the z-levels
            # Verify the index of the z_levels are the original ones.
            if len(z_names) != 0:
                c_slice_txt = z_names[c_slice]
            else:
                c_slice_txt = c_slice

            c_mincbar = np.nan
            c_maxcbar = np.nan
            for idx_var, c_var in enumerate(var_names): # Iterate over the fields
                if rows*cols == 1:  # Single figure
                    ax = _axs
                else:
                    ax = _axs.flatten()[c_zlevel*len(var_names) + idx_var]

                # Here we chose the min and max colorbars for each field
                if not(np.all(np.isnan(mincbar))):
                    if type(mincbar) is list:
                        c_mincbar = mincbar[idx_var]
                    else:
                        c_mincbar = mincbar
                if not(np.all(np.isnan(maxcbar))):
                    if type(mincbar) is list:
                        c_maxcbar = maxcbar[idx_var]
                    else:
                        c_maxcbar = maxcbar

                # By default we select the colorbar from the name of the variable
                if self._auto_colormap and orig_cmap is None:
                    cmap = select_colormap(c_var)
                else:
                    # If there is an array of colormaps we select the one for this field
                    if type(orig_cmap) is list:
                        cmap = orig_cmap[idx_var]
                    else:
                        # If it is just one cmap, then we use it for all the fields
                        cmap = orig_cmap

                im = self.plot_slice_eoa(np_variables[c_var][c_slice,:,:], ax, cmap=cmap, mode=plot_mode,
                                         mincbar=c_mincbar, maxcbar=c_maxcbar)

                if self._show_var_names:
                    c_title = F'{var_names[idx_var]} {title}'
                else:

                    c_title = F'{title}'
                if len(z_levels) > 1:
                    c_title += F"Z - level: {c_slice_txt}"

                ax.set_title(c_title, fontsize=self._font_size)

                self.add_colorbar(fig, im, ax, show_color_bar)

        plt.tight_layout(pad=.5)
        file_name = F'{file_name_prefix}'
        pylab.savefig(join(self._output_folder, F'{file_name}.png'), bbox_inches='tight')
        self._close_figure()

        Plots multiple z_levels for multiple fields.
        It uses rows for each depth, and columns for each variable
        
Plots multiple z_levels for multiple fields.
It uses rows for each depth, and columns for each variable
Plots multiple z_levels for multiple fields . It uses rows for each depth and columns for each variable
def plot_3d_data_npdict(self, np_variables:list, var_names:list, z_levels= [], title='',
                          file_name_prefix='', cmap=None, z_names = [],
                          show_color_bar=True, plot_mode=PlotMode.RASTER, mincbar=np.nan, maxcbar=np.nan):
        create_folder(self._output_folder)
        orig_cmap = cmap
        if len(z_levels) == 0:
            z_levels = range(np_variables[var_names[0]].shape[0])
        cols = np.min((self._max_imgs_per_row, len(var_names)))
        if cols == len(var_names):
            rows = len(z_levels)
        else:
            rows = int(len(z_levels) * np.ceil(len(var_names)/cols))
        fig, _axs = plt.subplots(rows, cols,
                                 figsize=self.get_proper_size(rows, cols),
                                 subplot_kw={'projection': self._projection})
        for c_zlevel, c_slice in enumerate(z_levels):  
            if len(z_names) != 0:
                c_slice_txt = z_names[c_slice]
            else:
                c_slice_txt = c_slice
            c_mincbar = np.nan
            c_maxcbar = np.nan
            for idx_var, c_var in enumerate(var_names): 
                if rows*cols == 1:  
                    ax = _axs
                else:
                    ax = _axs.flatten()[c_zlevel*len(var_names) + idx_var]
                if not(np.all(np.isnan(mincbar))):
                    if type(mincbar) is list:
                        c_mincbar = mincbar[idx_var]
                    else:
                        c_mincbar = mincbar
                if not(np.all(np.isnan(maxcbar))):
                    if type(mincbar) is list:
                        c_maxcbar = maxcbar[idx_var]
                    else:
                        c_maxcbar = maxcbar
                if self._auto_colormap and orig_cmap is None:
                    cmap = select_colormap(c_var)
                else:
                    if type(orig_cmap) is list:
                        cmap = orig_cmap[idx_var]
                    else:
                        cmap = orig_cmap
                im = self.plot_slice_eoa(np_variables[c_var][c_slice,:,:], ax, cmap=cmap, mode=plot_mode,
                                         mincbar=c_mincbar, maxcbar=c_maxcbar)
                if self._show_var_names:
                    c_title = F'{var_names[idx_var]} {title}'
                else:
                    c_title = F'{title}'
                if len(z_levels) > 1:
                    c_title += F"Z - level: {c_slice_txt}"
                ax.set_title(c_title, fontsize=self._font_size)
                self.add_colorbar(fig, im, ax, show_color_bar)
        plt.tight_layout(pad=.5)
        file_name = F'{file_name_prefix}'
        pylab.savefig(join(self._output_folder, F'{file_name}.png'), bbox_inches='tight')
        self._close_figure()
def plot_3d_data_npdict ( self , np_variables : list , var_names : list , z_levels = [ ] , title = '' , file_name_prefix = '' , cmap = None , z_names = [ ] , show_color_bar = True , plot_mode = PlotMode . RASTER , mincbar = np . nan , maxcbar = np . nan ) : create_folder ( self . _output_folder ) orig_cmap = cmap if len ( z_levels ) == 0 : z_levels = range ( np_variables [ var_names [ 0 ] ] . shape [ 0 ] ) cols = np . min ( ( self . _max_imgs_per_row , len ( var_names ) ) ) if cols == len ( var_names ) : rows = len ( z_levels ) else : rows = int ( len ( z_levels ) * np . ceil ( len ( var_names ) / cols ) ) fig , _axs = plt . subplots ( rows , cols , figsize = self . get_proper_size ( rows , cols ) , subplot_kw = { 'projection' : self . _projection } ) for c_zlevel , c_slice in enumerate ( z_levels ) : if len ( z_names ) != 0 : c_slice_txt = z_names [ c_slice ] else : c_slice_txt = c_slice c_mincbar = np . nan c_maxcbar = np . nan for idx_var , c_var in enumerate ( var_names ) : if rows * cols == 1 : ax = _axs else : ax = _axs . flatten ( ) [ c_zlevel * len ( var_names ) + idx_var ] if not ( np . all ( np . isnan ( mincbar ) ) ) : if type ( mincbar ) is list : c_mincbar = mincbar [ idx_var ] else : c_mincbar = mincbar if not ( np . all ( np . isnan ( maxcbar ) ) ) : if type ( mincbar ) is list : c_maxcbar = maxcbar [ idx_var ] else : c_maxcbar = maxcbar if self . _auto_colormap and orig_cmap is None : cmap = select_colormap ( c_var ) else : if type ( orig_cmap ) is list : cmap = orig_cmap [ idx_var ] else : cmap = orig_cmap im = self . plot_slice_eoa ( np_variables [ c_var ] [ c_slice , : , : ] , ax , cmap = cmap , mode = plot_mode , mincbar = c_mincbar , maxcbar = c_maxcbar ) if self . _show_var_names : c_title = F'{var_names[idx_var]} {title}' else : c_title = F'{title}' if len ( z_levels ) > 1 : c_title += F"Z - level: {c_slice_txt}" ax . set_title ( c_title , fontsize = self . _font_size ) self . add_colorbar ( fig , im , ax , show_color_bar ) plt . tight_layout ( pad = .5 ) file_name = F'{file_name_prefix}' pylab . savefig ( join ( self . _output_folder , F'{file_name}.png' ) , bbox_inches = 'tight' ) self . _close_figure ( )
Plots multiple z_levels for multiple fields.
Plots multiple z_levels for multiple fields .
"""
        Plots multiple z_levels for multiple fields.
        It uses rows for each depth, and columns for each variable
        """ # If the user do not requires any z-leve, then all are plotted # Iterates over the z-levels # Verify the index of the z_levels are the original ones. # Iterate over the fields # Single figure # Here we chose the min and max colorbars for each field # By default we select the colorbar from the name of the variable # If there is an array of colormaps we select the one for this field # If it is just one cmap, then we use it for all the fields
self
np_variables
list
var_names
list
z_levels
title
file_name_prefix
cmap
z_names
show_color_bar
plot_mode
mincbar
maxcbar