gpm.visualization package

Contents

gpm.visualization package#

Submodules#

gpm.visualization.animation module#

This module contains tools for creating animations.

gpm.visualization.animation.check_frame_settings(frame_duration, frame_rate, return_duration=False)[source][source]#
gpm.visualization.animation.check_input_files(image_filepaths)[source][source]#

Check valid input file paths.

gpm.visualization.animation.check_mp4_codec(codec)[source][source]#
gpm.visualization.animation.check_mp4_optimization(optimization)[source][source]#
gpm.visualization.animation.check_valid_dither(dither)[source][source]#
gpm.visualization.animation.create_apng(image_filepaths, apng_fpath, sort=False, frame_duration=None, frame_rate=None, loop=0)[source][source]#

Create an Animated PNG.

Either specify frame_rate or frame_duration.

Parameters:
  • image_filepaths (list of str) – List of filepaths of input images. The images will be used to create the GIF.

  • apng_fpath (str) – Filepath of the output APNG.

  • frame_duration (int, optional) – Duration in milliseconds (ms) of each GIF frame. The default is 250 ms.

  • frame_rate (int, optional) – The number of individual frames displayed in one second. The default is 4.

  • loop (int, optional) – Number of times the APNG should loop. Set to 0 for infinite loop. The default is 0.

Notes

PowerPoint currently does not support APNGs.

Examples

>>> filepaths = ["image1.png", "image2.png", "image3.png"]
>>> apng_fpath = "output.png"
>>> create_apng(filepaths, apng_fpath, sort=False, frame_duration=200, loop=0)
gpm.visualization.animation.create_ffmpeg_gif(image_filepaths, gif_fpath, sort=False, frame_duration=None, frame_rate=None, loop=0, width=None, height=None, interpolation='lanczos', stats_mode='single', dither=None, bayer_scale=1, delete_inputs=False, verbose=True)[source][source]#

Create a GIF from a list of image filepaths using ffmpeg.

Either specify frame_rate or frame_duration.

Parameters:
  • image_filepaths (list of str) – List of filepaths of input images. The images will be used to create the GIF.

  • gif_fpath (str) – Filepath of the output GIF.

  • sort (bool, optional) – If True, sort the input images in ascending order. Default is False.

  • frame_duration (int, optional) – Duration in milliseconds (ms) of each GIF frame. The default is 250 ms.

  • frame_rate (int, optional) – The number of individual frames displayed in one second. The default is 4.

  • width (int, optional) – The width of the output GIF. If None and height is provided, is set to -1 to preserve aspect ratio. If None and height is also None, the output has same size as the input images.

  • height (int, optional) – The height of the output GIF. If None and width is provided, is set to -1 to preserve aspect ratio. If None and width is also None, the output has same size as the input images.

  • interpolation (str, optional) – Interpolation method to use if need to rescale the input image. Valid values are 'bilinear', 'lanczos', 'bicubic'. The default is 'lanczos'.

  • loop (int, optional) – Number of times the GIF should loop. Set to 0 for infinite loop. The default is 0.

  • per_frame_palette (bool, optional) – If True, enable definition of a palette for each GIF frame. The default is True.

  • stats_mode (str, optional) – The method to establish the color palette. Valid values are 'single',``’full’, ``'diff'. If 'full', compute a single palette over all frames. If 'single', compute a palette for each frame. If 'diff', compute histograms only for pixels that differs from previous frame. The 'diff' mode might be relevant to give more importance to the moving part of your input if the background is static. The default is 'single'.

  • dither (str or None, optional) – Dithering method to apply during color quantization. Available options are: None or 'none' (no dithering), 'bayer', 'floyd_steinberg', 'heckbert', 'sierra2', 'sierra2_4a', 'sierra_lite'. The default is None.

  • delete_inputs (bool, optional) – If True, delete the original input images after creating the GIF. The default is False.

Notes

This function uses ffmpeg to create the GIF. Ensure that ffmpeg is installed and accessible in the system’s PATH.

Examples

>>> filepaths = ["image1.png", "image2.png", "image3.png"]
>>> gif_fpath = "output.gif"
>>> create_ffmpeg_gif(filepaths, gif_fpath, sort=True, frame_duration=200)
gpm.visualization.animation.create_ffmpeg_mp4(image_filepaths, mp4_fpath, sort=False, frame_duration=None, frame_rate=None, codec='libx264', optimization='placebo', delete_inputs=False, verbose=True)[source][source]#

Create a MP4 from a list of image filepaths using ffmpeg.

Either specify frame_rate or frame_duration. YouTube and Vimeo don’t really appreciate video with < 0.5 FPS Only MP4 videos with H.264 codec are supported across all Powerpoint versions.

Parameters:
  • image_filepaths (list of str) – List of filepaths of input images. The images will be used to create the MP4.

  • mp4_fpath (str) – Filepath of the output MP4.

  • sort (bool, optional) – If True, sort the input images in ascending order. The default is False.

  • frame_duration (int, optional) – Duration in milliseconds (ms) of each MP4 frame. The default is 250 ms.

  • frame_rate (int, optional) – The number of individual frames displayed in one second. The default is 4.

  • codec (str, optional) – MP4 codec. Valid codecs are "libx264", "libx265", "mpeg4", "vp9", "av1". The default is "libx264". The 'libx264' (H.264 AVC codec) is widely used for compatibility and good compression. The 'libx265' (H.265 HEVC codec) offers better compression than H.264 but requires more processing power. The 'vp9' codec, is developed by Google, and is known for its high compression efficiency. The 'av1' codec is a newer open-source codec that aims to provide even better compression efficiency than H.265 and VP9. It’s gaining popularity but may have varying levels of support on different devices and software. Video generation is slow and rendering on VLC and many others video players is not well supported. The 'mpeg4' (MPEG-4 Part 2) codec is older and less efficient than H.264 and H.265 but is still compatible with many devices and software

  • optimization (str, optional) – Whether to optimize video encoding by using '-preset <optimization>'. The default optimizazion used by FFMPEG is 'medium'. If 'placebo' (the default of this function), the optimization slows down the file creation and increases the file size, but provides the best possible video quality.

  • delete_inputs (bool, optional) – If True, it delete the original input images after creating the MP4. The default is False.

Notes

This function uses ffmpeg to create the MP4. Ensure that FFMPEG is installed and accessible in the system’s PATH.

Examples

>>> filepaths = ["image1.png", "image2.png", "image3.png"]
>>> mp4_fpath = "output.mp4"
>>> create_ffmpeg_gif(filepaths, mp4_fpath, sort=True, frame_duration=200)
gpm.visualization.animation.create_gifski_gif(image_filepaths, gif_fpath, sort=False, frame_duration=None, frame_rate=None, loop=0, quality=100, motion_quality=100, lossy_quality=100, optimize=True, delete_inputs=False, verbose=True)[source][source]#

Create a GIF from a list of image filepaths using gifski.

Gifski generates per-frame optimized palettes, combines palettes across frames and achieve thousands of colors per frame for maximum quality.

Either specify frame_rate or frame_duration.

Parameters:
  • image_filepaths (list of str) – List of filepaths of input images. The images will be used to create the GIF.

  • gif_fpath (str) – Filepath of the output GIF.

  • sort (bool, optional) – If True, sort the input images in ascending order. The default is False.

  • frame_duration (int, optional) – Duration in milliseconds (ms) of each GIF frame. The default is 250 ms.

  • frame_rate (int, optional) – The number of individual frames displayed in one second. The default is 4.

  • quality (str, optional) – Controls the overall output quality. The default is 100. Lower values reduces quality but may reduce file size.

  • motion_quality (str, optional) – Controls motion quality. The default is 100. Lower values reduce motion quality.

  • lossy_quality (str, optional) – Controls PNG quantization quality. The default is 100. Lower values introduce noise and streaks.

  • optimize (bool, optional) – If True, it improves the GIF quality. If False, it speeds up the GIF creation at quality expense.

  • loop (int, optional) – Number of times the GIF should loop. Set to 0 for infinite loop. The default is 0.

  • delete_inputs (bool, optional) – If True, delete the original input images after creating the GIF. The default is False.

Notes

This function uses gifski to create the GIF. Ensure that gifski is installed and accessible in the system’s PATH.

On Linux systems, it can be installed using sudo snap install gifski.

More GIFski information at: ImageOptim/gifski

More PNG quantization information at: https://pngquant.org/

Examples

>>> filepaths = ["image1.png", "image2.png", "image3.png"]
>>> gif_fpath = "output.gif"
>>> create_gifski_gif(filepaths, gif_fpath, sort=True, frame_duration=200)
gpm.visualization.animation.create_pillow_gif(image_filepaths, gif_fpath, sort=False, frame_duration=None, frame_rate=None, loop=0)[source][source]#

Create a GIF from a list of image filepaths.

Either specify frame_rate or frame_duration.

Parameters:
  • image_filepaths (list) – List of image file paths.

  • gif_fpath (str) – File path where to save the gif.

  • sort (bool, optional) – If True, sort the input images in ascending order. The default is False.

  • frame_duration (int, optional) – Duration in milliseconds (ms) of each GIF frame. The default is 250 ms.

  • frame_rate (int, optional) – The number of individual frames displayed in one second. The default is 4.

  • loop (int, optional) – Number of times the APNG should loop. Set to 0 for infinite loop. The default is 0.

gpm.visualization.animation.get_image_size(image_path)[source][source]#

gpm.visualization.cross_section module#

This module contains functions to visualize cross-sections.

gpm.visualization.cross_section.get_cross_track_horizontal_distance(xr_obj)[source][source]#

Retrieve the horizontal_distance from the nadir.

Requires a cross-section with cross_track as horizontal spatial dimension !

gpm.visualization.cross_section.plot_cross_section(da, x=None, y=None, ax=None, add_colorbar=True, zoom=True, check_contiguity=False, interpolation='nearest', fig_kwargs=None, cbar_kwargs=None, **plot_kwargs)[source][source]#

Plot GPM cross-section.

If RGB DataArray, all other plot_kwargs are ignored !

gpm.visualization.cross_section.plot_transect_line(xr_obj, ax=None, add_direction=True, add_background=True, add_gridlines=True, add_labels=True, fig_kwargs=None, subplot_kwargs=None, text_kwargs=None, line_kwargs=None, **common_kwargs)[source][source]#

gpm.visualization.eda module#

This module contains plotting functions for exploratory data visualization.

gpm.visualization.eda.plot_boxplot(df_stats, ax=None, label=None, showfliers=False, showwhisker=False, showmeans=False, positions=None, widths=0.6, add_median_points=False, add_median_line=False, median_points_kwargs=None, median_line_kwargs=None, boxprops=None, whiskerprops=None, medianprops=None, **kwargs)[source][source]#

Draw a box and whisker plot from pre-computed statistics.

The box extends from the first quartile q25 to the third quartile q75 of the data, with a line at the median (median). The whiskers extend from whislow to whishi. Flier points are markers past the end of the whiskers. See https://en.wikipedia.org/wiki/Box_plot for reference.

      whislow    q25    med    q75    whishi
                  |-----:-----|
  o      |--------|     :     |--------|    o  o
                  |-----:-----|
flier                                      fliers

Note

This is a low-level drawing function for when you already have the statistical parameters. If you want a boxplot based on a dataset, use matplotlib.axes.Axes.boxplot instead.

Parameters:
  • df_stats (pandas.DataFrame) –

    The dataframe index controls the boxplot position along the xaxis, unless ‘positions’ is specified. Required columns are: - ‘mean’: - ‘median’: - ‘q10’: - ‘q25’: - ‘q75’: - ‘q90’: - ‘iqr’: Needed if showwhisker=True. - ‘min’: Needed if showfliers=True. - ‘max’: Needed if showfliers=True. - ‘n’:

    A DatetimeIndex or a ‘time’ column enable to display the x axis with the desired date (irregular vs uniformly spaced)

  • label (str, optional) – Column of the dataframe to be used as tick label for the boxplot

  • positions (array-like, optional) – The positions of the boxes. If not specified, the ticks and limits are automatically set as function of the dataframe index.

  • widths (float or array-like, optional) – The widths of the boxes. The default is clip(0.15*(distance between extreme positions), 0.15, 0.5).

  • capwidths (float or array-like) – Either a scalar or a vector and sets the width of each cap. The default is 0.5*(width of the box), see widths.

  • orientation (str, optional) – Either ‘vertical’ or ‘horizontal’. If ‘horizontal’, plots the boxes horizontally. Otherwise, plots the boxes vertically. The default is ‘vertical’.

  • patch_artist (bool, optional) – If False produces boxes with the .Line2D artist. If True produces boxes with the ~matplotlib.patches.Patch artist. The default is False.

  • shownotches (bool, optional) – Whether to draw the CI notches, the mean value (both default to False), the caps, the box, and the fliers (all three default to True).

  • showmeans (bool, optional) – Whether to draw the CI notches, the mean value (both default to False), the caps, the box, and the fliers (all three default to True).

  • showcaps (bool, optional) – Whether to draw the CI notches, the mean value (both default to False), the caps, the box, and the fliers (all three default to True).

  • showbox (bool, optional) – Whether to draw the CI notches, the mean value (both default to False), the caps, the box, and the fliers (all three default to True).

  • showfliers (bool, optional) – Whether to draw the CI notches, the mean value (both default to False), the caps, the box, and the fliers (all three default to True).

  • boxprops (dict, optional) – Artist properties for the boxes, whiskers, caps, fliers, medians, and means.

  • whiskerprops (dict, optional) – Artist properties for the boxes, whiskers, caps, fliers, medians, and means.

  • capprops (dict, optional) – Artist properties for the boxes, whiskers, caps, fliers, medians, and means.

  • flierprops (dict, optional) – Artist properties for the boxes, whiskers, caps, fliers, medians, and means.

  • medianprops (dict, optional) – Artist properties for the boxes, whiskers, caps, fliers, medians, and means.

  • meanprops (dict, optional) – Artist properties for the boxes, whiskers, caps, fliers, medians, and means.

  • manage_ticks (bool, optional) – If True (the default), the tick locations and labels will be adjusted to match the boxplot positions.

  • zorder (float, optional) – The zorder of the resulting boxplot.

Return type:

matplotlib.Axes

gpm.visualization.facetgrid module#

This module contains the FacetGrid classes.

class gpm.visualization.facetgrid.CartopyFacetGrid(data, projection, col: Hashable | None = None, row: Hashable | None = None, col_wrap: int | None = None, axes_pad: tuple[float, float] | None = None, add_colorbar: bool = True, cbar_kwargs: dict | None = None, fig_kwargs: dict | None = None, facet_height: float = 3.0, facet_aspect: float = 1.0)[source][source]#

Bases: CustomFacetGrid

Cartopy FacetGrid class.

Parameters:
  • data (xarray.DataArray or xarray.Dataset) – xarray object to be plotted.

  • projection (cartopy.crs.CRS) – Cartopy projection.

  • row (str) – Dimension names that define subsets of the data, which will be drawn on separate facets in the grid.

  • col (str) – Dimension names that define subsets of the data, which will be drawn on separate facets in the grid.

  • col_wrap (int, optional) – “Wrap” the grid the for the column variable after this number of columns, adding rows if col_wrap is less than the number of facets.

  • axes_pad (tuple or float, optional) – Padding or (horizontal padding, vertical padding) between axes, in inches. The default is (0.1, 0.3) inches.

  • add_colorbar (bool, optional) – Whether to add a colorbar to the figure. The default is True.

  • cbar_kwargs (dict, optional) – Dictionary of keyword arguments to pass to the colorbar. The pad argument controls the space between the image axes and the colorbar axes. The pad default is 0.2. The size argument control the colorbar size. The default value is '3%'. For other arguments, see matplotlib.figure.Figure.colorbar.

  • facet_height (float, optional) – Height (in inches) of each facet. The default is 3. This parameter is used only if the figsize argument is not specified in fig_kwargs.

  • facet_aspect (float, optional) – Aspect ratio of each facet. The default is 1. The facet width is determined by facet_height * facet_aspect. This parameter is used only if the figsize argument is not specified in fig_kwargs.

  • fig_kwargs (dict, optional) – Dictionary of keyword arguments to pass to the Figure. Typical arguments include figsize and dpi. figsize is a tuple (width, height) of the figure in inches. If figsize is specified, it overrides facet_size and facet_aspect arguments. (see matplotlib.figure.Figure).

optimize_layout()[source][source]#

Optimize the figure size and layout of the Figure.

This function must be called only once !

set_extent(extent)[source][source]#

Modify extent of all Cartopy subplots.

class gpm.visualization.facetgrid.CustomFacetGrid(data, col: Hashable | None = None, row: Hashable | None = None, col_wrap: int | None = None, axes_pad: tuple[float, float] | None = None, aspect: bool = True, add_colorbar: bool = True, facet_height: float = 3.0, facet_aspect: float = 1.0, cbar_kwargs: dict | None = None, fig_kwargs: dict | None = None, axes_class=None)[source][source]#

Bases: FacetGrid, ABC

Class for xarray-based FacetGrid plots.

Parameters:
  • data (xarray.DataArray or xarray.Dataset) – xarray object to be plotted.

  • row (str) – Dimension names that define subsets of the data, which will be drawn on separate facets in the grid.

  • col (str) – Dimension names that define subsets of the data, which will be drawn on separate facets in the grid.

  • col_wrap (int, optional) – “Wrap” the grid the for the column variable after this number of columns, adding rows if col_wrap is less than the number of facets.

  • axes_pad (tuple or float, optional) – Padding or (horizontal padding, vertical padding) between axes, in inches. The default is (0.1, 0.3) inches.

  • aspect (bool, optional) – Whether the axes aspect ratio follows the aspect ratio of the data limits. The default is True.

  • axes_class (subclass of matplotlib.axes.Axes, optional) – The default is None.

  • add_colorbar (bool, optional) – Whether to add a colorbar to the figure. The default is True.

  • cbar_kwargs (dict, optional) – Dictionary of keyword arguments to pass to the colorbar. The pad argument controls the space between the image axes and the colorbar axes. The pad default is 0.2. The size argument control the colorbar size. The default value is ‘3%’. For other arguments, see matplotlib.figure.Figure.colorbar.

  • facet_height (float, optional) – Height (in inches) of each facet. The default is 3. This parameter is used only if the figsize argument is not specified in fig_kwargs.

  • facet_aspect (float, optional) – Aspect ratio of each facet. The default is 1. The facet width is determined by facet_height * facet_aspect. This parameter is used only if the figsize argument is not specified in fig_kwargs.

  • fig_kwargs (dict, optional) – Dictionary of keyword arguments to pass to the Figure. Typical arguments include figsize and dpi. figsize is a tuple (width, height) of the figure in inches. If figsize is specified, it overrides facet_size and facet_aspect arguments. (see matplotlib.figure.Figure).

adapt_fig_size()[source][source]#

Adjusts the figure height of the plot based on the aspect ratio of cartopy subplots.

This function is intended to be called after all plotting has been completed. It operates under the assumption that all subplots within the figure share the same aspect ratio.

The implementation is inspired by Mathias Hauser’s mplotutils set_map_layout function.

add_colorbar(**cbar_kwargs) None[source][source]#

Draw a colorbar.

map_dataarray(func, x=None, y=None, **kwargs)[source][source]#

Apply a plotting function to a 2d facet’s subset of the data.

This is more convenient and less general than FacetGrid.map

Parameters:
  • func (callable) – A plotting function with the same signature as a 2d xarray plotting method such as xarray.plot.imshow

  • x (str) – Names of the coordinates to plot on x, y axes

  • y (str) – Names of the coordinates to plot on x, y axes

  • **kwargs – additional keyword arguments to func

Returns:

FacetGrid object

Return type:

xarray.plot.facetgrid.FacetGrid

map_to_axes(func, **kwargs)[source][source]#

Map a function to each axes.

remove_bottom_ticks_and_labels()[source][source]#

Remove the bottom ticks and labels from each subplot.

remove_duplicated_axis_labels()[source][source]#

Remove axis labels which are not located on the left or bottom of the figure.

remove_left_ticks_and_labels()[source][source]#

Remove the left ticks and labels from each subplot.

remove_title_dimension_prefix(row=True, col=True)[source][source]#

Remove the dimension prefix from the subplot labels.

remove_titles(row=True, col=True)[source][source]#

Remove the plot titles.

set_title(title, horizontalalignment='center', **kwargs)[source][source]#

Add a title above all sublots.

The y argument controls the spacing to the subplots. Decreasing or increasing the y argument (from a default value of 1) reduce/increase the spacing.

class gpm.visualization.facetgrid.ImageFacetGrid(data, col: Hashable | None = None, row: Hashable | None = None, col_wrap: int | None = None, axes_pad: tuple[float, float] | None = None, aspect: bool = False, add_colorbar: bool = True, cbar_kwargs: dict | None = None, fig_kwargs: dict | None = None, facet_height: float = 3.0, facet_aspect: float = 1.0)[source][source]#

Bases: CustomFacetGrid

Image FacetGrid class.

Parameters:
  • data (xarray.DataArray or xarray.Dataset) – xarray object to be plotted.

  • row (str) – Dimension names that define subsets of the data, which will be drawn on separate facets in the grid.

  • col (str) – Dimension names that define subsets of the data, which will be drawn on separate facets in the grid.

  • col_wrap (int, optional) – “Wrap” the grid the for the column variable after this number of columns, adding rows if col_wrap is less than the number of facets.

  • axes_pad (tuple or float, optional) – Padding or (horizontal padding, vertical padding) between axes, in inches. The default is (0.1, 0.3) inches.

  • aspect (bool) – Whether the axes aspect ratio follows the aspect ratio of the data limits. The default is False.

  • add_colorbar (bool, optional) – Whether to add a colorbar to the figure. The default is True.

  • cbar_kwargs (dict, optional) – Dictionary of keyword arguments to pass to the colorbar. The pad argument controls the space between the image axes and the colorbar axes. The pad default is 0.2. The size argument control the colorbar size. The default value is '3%'. For other arguments, see matplotlib.figure.Figure.colorbar.

  • facet_height (float, optional) – Height (in inches) of each facet. The default is 3. This parameter is used only if the figsize argument is not specified in fig_kwargs.

  • facet_aspect (float, optional) – Aspect ratio of each facet. The default is 1. The facet width is determined by facet_height * facet_aspect. This parameter is used only if the figsize argument is not specified in fig_kwargs.

  • fig_kwargs (dict, optional) – Dictionary of keyword arguments to pass to the Figure. Typical arguments include figsize and dpi. figsize is a tuple (width, height) of the figure in inches. If figsize is specified, it overrides facet_size and facet_aspect arguments. (see matplotlib.figure.Figure).

gpm.visualization.facetgrid.get_cartopy_gridlines_artists(ax)[source][source]#

Retrieve the cartopy gridline artist.

gpm.visualization.facetgrid.sanitize_facetgrid_plot_kwargs(plot_kwargs)[source][source]#

Remove defaults values set by FacetGrid.map_dataarray.

gpm.visualization.grid module#

This module contains functions to visualize GPM-API GRID data.

gpm.visualization.grid.plot_grid_map(da, x=None, y=None, ax=None, interpolation='nearest', add_colorbar=True, add_background=True, add_labels=True, add_gridlines=True, fig_kwargs=None, subplot_kwargs=None, cbar_kwargs=None, **plot_kwargs)[source][source]#

Plot xarray.DataArray 2D field with cartopy.

gpm.visualization.grid.plot_grid_mesh(xr_obj, x=None, y=None, ax=None, edgecolors='k', linewidth=0.1, add_background=True, add_gridlines=True, add_labels=True, fig_kwargs=None, subplot_kwargs=None, **plot_kwargs)[source][source]#

Plot GPM grid mesh in a cartographic map.

gpm.visualization.orbit module#

This module contains functions to visualize GPM-API ORBIT data.

gpm.visualization.orbit.call_over_contiguous_scans(function)[source][source]#

Decorator to call the plotting function multiple times only over contiguous scans intervals.

gpm.visualization.orbit.infer_orbit_xy_dim(da, x, y)[source][source]#

Infer possible along-track and cross-track dimensions for the given DataArray.

Parameters:
  • da (xarray.DataArray) – The input DataArray.

  • x (str) – The name of the x coordinate.

  • y (str) – The name of the y coordinate.

Returns:

The inferred (along_track_dim, cross_track_dim) dimensions.

Return type:

tuple

gpm.visualization.orbit.plot_orbit_map(da, ax=None, x=None, y=None, add_colorbar=True, add_swath_lines=True, add_background=True, add_gridlines=True, add_labels=True, fig_kwargs=None, subplot_kwargs=None, cbar_kwargs=None, **plot_kwargs)[source][source]#

Plot xarray.DataArray 2D field with cartopy.

gpm.visualization.orbit.plot_orbit_mesh(da, ax=None, x=None, y=None, edgecolors='k', linewidth=0.1, add_background=True, add_gridlines=True, add_labels=True, fig_kwargs=None, subplot_kwargs=None, **plot_kwargs)[source][source]#

Plot GPM orbit granule mesh in a cartographic map.

gpm.visualization.orbit.plot_swath(ds, ax=None, facecolor='orange', edgecolor='black', alpha=0.4, add_background=True, add_gridlines=True, add_labels=True, fig_kwargs=None, subplot_kwargs=None, **plot_kwargs)[source][source]#

Plot GPM orbit granule.

gpm.visualization.orbit.plot_swath_lines(da, ax=None, x='lon', y='lat', linestyle='--', color='k', add_background=True, add_gridlines=True, add_labels=True, subplot_kwargs=None, fig_kwargs=None, **plot_kwargs)[source][source]#

Plot GPM orbit granule swath lines.

gpm.visualization.orbit.remove_invalid_outer_cross_track(xr_obj, coord='lon', cross_track_dim='cross_track', along_track_dim='along_track', alpha=None)[source][source]#

Remove outer cross-track scans if geolocation is always missing.

gpm.visualization.plot module#

This module contains basic functions for GPM-API data visualization.

gpm.visualization.plot.adapt_fig_size(ax, nrow=1, ncol=1)[source][source]#

Adjusts the figure height of the plot based on the aspect ratio of cartopy subplots.

This function is intended to be called after all plotting has been completed. It operates under the assumption that all subplots within the figure share the same aspect ratio.

Assumes that the first axis in the collection of axes is representative of all others. This means that all subplots are expected to have the same aspect ratio and size.

The implementation is inspired by Mathias Hauser’s mplotutils set_map_layout function.

gpm.visualization.plot.add_map_inset(ax, loc='upper left', inset_height=0.2, projection=None, inside_figure=True, border_pad=0)[source][source]#

Adds an inset map to a matplotlib axis using Cartopy, highlighting the extent of the main plot.

This function creates a smaller map inset within a larger map plot to show a global view or contextual location of the main plot’s extent.

It uses Cartopy for map projections and plotting, and it outlines the extent of the main plot within the inset to provide geographical context.

Parameters:
  • ax (matplotlib.axes.Axes or cartopy.mpl.geoaxes.GeoAxes) – The main matplotlib or cartopy axis object where the geographic data is plotted.

  • loc (str, optional) – The location of the inset map within the main plot. Options include 'lower left', 'lower right', 'upper left', and 'upper right'. The default is 'upper left'.

  • inset_height (float, optional) – The size of the inset height, specified as a fraction of the figure’s height. For example, a value of 0.2 indicates that the inset’s height will be 20% of the figure’s height. The aspect ratio (of the map inset) will govern the inset_width.

  • inside_figure (bool, optional) – Determines whether the inset is constrained to be fully inside the figure bounds. If True (default), the inset is placed fully within the figure. If False, the inset can extend beyond the figure’s edges, allowing for a half-outside placement.

  • projection (cartopy.crs.Projection, optional) – A cartopy projection. If None, am Orthographic projection centered on the extent center is used.

Returns:

ax2 – The Cartopy GeoAxesSubplot object for the inset map.

Return type:

cartopy.mpl.geoaxes.GeoAxes

Notes

The function adjusts the extent of the inset map based on the main plot’s extent, adding a slight padding for visual clarity. It then overlays a red outline indicating the main plot’s geographical extent.

Examples

>>> p = da.gpm.plot_map()
>>> add_map_inset(ax=p.axes, loc="upper left", inset_height=0.15)

This example creates a main plot with a specified extent and adds an upper-left inset map showing the global context of the main plot’s extent.

gpm.visualization.plot.add_optimize_layout_method(p)[source][source]#

Add a method to optimize the figure layout using monkey patching.

gpm.visualization.plot.check_object_format(da, plot_kwargs, check_function, **function_kwargs)[source][source]#

Check object format and valid dimension names.

gpm.visualization.plot.create_grid_mesh_data_array(xr_obj, x, y)[source][source]#

Create a 2D mesh coordinates DataArray.

Takes as input the 1D coordinate arrays from an existing xarray.DataArray or xarray.Dataset object.

The function creates a 2D grid (mesh) of x and y coordinates and initializes the data values to NaN.

Parameters:
  • xr_obj (xarray.DataArray or xarray.Dataset) – The input xarray object containing the 1D coordinate arrays.

  • x (str) – The name of the x-coordinate in xr_obj.

  • y (str) – The name of the y-coordinate in xr_obj.

Returns:

da_mesh – A 2D xarray.DataArray with mesh coordinates for x and y, and NaN values for data points.

Return type:

xarray.DataArray

Notes

The resulting xarray.DataArray has dimensions named ‘y’ and ‘x’, corresponding to the y and x coordinates respectively. The coordinate values are taken directly from the input 1D coordinate arrays, and the data values are set to NaN.

gpm.visualization.plot.get_antimeridian_mask(lons)[source][source]#

Get mask of longitude coordinates neighbors crossing the antimeridian.

gpm.visualization.plot.get_valid_pcolormesh_inputs(x, y, data, rgb=False, mask_data=True)[source][source]#

Infill invalid coordinates.

Interpolate the coordinates within the convex hull of data. Use nearest neighbour outside the convex hull of data.

This operation is required to plot with pcolormesh since it does not accept non-finite values in the coordinates.

If mask_data=True, data values with invalid coordinates are masked and a numpy masked array is returned. Masked data values are not displayed in pcolormesh ! If rgb=True, it assumes the RGB dimension is the last data dimension.

gpm.visualization.plot.infer_map_xy_coords(da, x=None, y=None)[source][source]#

Infer possible map x and y coordinates for the given DataArray.

Parameters:
  • da (xarray.DataArray) – The input DataArray.

  • x (str, optional) – The name of the x (i.e. longitude) coordinate. If None, it will be inferred.

  • y (str, optional) – The name of the y (i.e. latitude) coordinate. If None, it will be inferred.

Returns:

The inferred (x, y) coordinates.

Return type:

tuple

gpm.visualization.plot.infer_xy_labels(da, x=None, y=None, rgb=None)[source][source]#
gpm.visualization.plot.infill_invalid_coords(xr_obj, x='lon', y='lat')[source][source]#

Infill invalid coordinates.

Interpolate the coordinates within the convex hull of data. Use nearest neighbour outside the convex hull of data.

gpm.visualization.plot.initialize_cartopy_plot(ax, fig_kwargs, subplot_kwargs, add_background, add_gridlines, add_labels, infer_crs=False, xr_obj=None)[source][source]#

Initialize figure for cartopy plot if necessary.

gpm.visualization.plot.is_generator(obj)[source][source]#
gpm.visualization.plot.is_same_crs(crs1, crs2)[source][source]#

Check if same CRS.

gpm.visualization.plot.mask_antimeridian_crossing_array(arr, lon, rgb, plot_kwargs)[source][source]#

Mask the array cells crossing the antimeridian.

Here we assume not invalid lon coordinates anymore. Cartopy still bugs with several projections when data cross the antimeridian. By default, GPM-API mask data crossing the antimeridian. The GPM-API configuration default can be modified with: gpm.config.set({"viz_hide_antimeridian_data": False})

gpm.visualization.plot.plot_cartopy_background(ax)[source][source]#

Plot cartopy background.

gpm.visualization.plot.plot_cartopy_gridlines_and_labels(ax, add_gridlines=True, add_labels=True)[source][source]#

Add cartopy gridlines and labels.

gpm.visualization.plot.plot_cartopy_imshow(ax, da, x, y, interpolation='nearest', add_colorbar=True, plot_kwargs=None, cbar_kwargs=None)[source][source]#

Plot imshow with cartopy.

gpm.visualization.plot.plot_cartopy_pcolormesh(ax, da, x, y, add_colorbar=True, add_swath_lines=True, plot_kwargs=None, cbar_kwargs=None)[source][source]#

Plot imshow with cartopy.

x and y must represents longitude and latitudes. The function currently does not allow to zoom on regions across the antimeridian. The function mask scanning pixels which spans across the antimeridian. If the DataArray has a RGB dimension, plot_kwargs should contain the rgb key with the name of the RGB dimension.

gpm.visualization.plot.plot_image(da, x=None, y=None, ax=None, add_colorbar=True, add_labels=True, interpolation='nearest', fig_kwargs=None, cbar_kwargs=None, **plot_kwargs)[source][source]#

Plot data using imshow.

Parameters:
  • da (xarray.DataArray) – xarray DataArray.

  • x (str, optional) – X dimension name. If None, takes the second dimension. The default is None.

  • y (str, optional) – Y dimension name. If None, takes the first dimension. The default is None.

  • ax (cartopy.mpl.geoaxes.GeoAxes, optional) – The matplotlib axes where to plot the image. If None, a figure is initialized using the specified fig_kwargs. The default is None.

  • add_colorbar (bool, optional) – Whether to add a colorbar. The default is True.

  • add_labels (bool, optional) – Whether to add labels to the plot. The default is True.

  • interpolation (str, optional) – Argument to be passed to imshow. The default is "nearest".

  • fig_kwargs (dict, optional) – Figure options to be passed to matplotlib.pyplot.subplots. The default is None. Only used if ax is None.

  • subplot_kwargs (dict, optional) – Subplot options to be passed to matplotlib.pyplot.subplots. The default is None. Only used if `ax` is None.

  • cbar_kwargs (dict, optional) – Colorbar options. The default is None.

  • **plot_kwargs – Additional arguments to be passed to the plotting function. Examples include cmap, norm, vmin, vmax, levels, … For FacetGrid plots, specify row, col and col_wrap. With rgb you can specify the name of the xarray.DataArray RGB dimension.

gpm.visualization.plot.plot_labels(obj, label_name=None, max_n_labels=50, add_colorbar=True, interpolation='nearest', cmap='Paired', fig_kwargs=None, **plot_kwargs)[source][source]#
gpm.visualization.plot.plot_map(da, x=None, y=None, ax=None, interpolation='nearest', add_colorbar=True, add_background=True, add_labels=True, add_gridlines=True, add_swath_lines=True, fig_kwargs=None, subplot_kwargs=None, cbar_kwargs=None, **plot_kwargs)[source][source]#

Plot data on a geographic map.

Parameters:
  • da (xarray.DataArray) – xarray DataArray.

  • x (str, optional) – Longitude coordinate name. If None, takes the second dimension. The default is None.

  • y (str, optional) – Latitude coordinate name. If None, takes the first dimension. The default is None.

  • ax (cartopy.mpl.geoaxes.GeoAxes, optional) – The cartopy GeoAxes where to plot the map. If None, a figure is initialized using the specified fig_kwargs and subplot_kwargs. The default is None.

  • add_colorbar (bool, optional) – Whether to add a colorbar. The default is True.

  • add_labels (bool, optional) – Whether to add cartopy labels to the plot. The default is True.

  • add_gridlines (bool, optional) – Whether to add cartopy gridlines to the plot. The default is True.

  • add_swath_lines (bool, optional) – Whether to plot the swath sides with a dashed line. The default is True. This argument only applies for ORBIT objects.

  • add_background (bool, optional) – Whether to add the map background. The default is True.

  • interpolation (str, optional) – Argument to be passed to matplotlib.axes.Axes.imshow. Only applies for GRID objects. The default is "nearest".

  • fig_kwargs (dict, optional) – Figure options to be passed to matplotlib.pyplot.subplots. The default is None. Only used if ax is None.

  • subplot_kwargs (dict, optional) – Dictionary of keyword arguments for matplotlib.pyplot.subplots. Must contain the Cartopy CRS ` projection key if specified. The default is None. Only used if ax is None.

  • cbar_kwargs (dict, optional) – Colorbar options. The default is None.

  • **plot_kwargs – Additional arguments to be passed to the plotting function. Examples include cmap, norm, vmin, vmax, levels, … For FacetGrid plots, specify row, col and col_wrap. With rgb you can specify the name of the xarray.DataArray RGB dimension.

gpm.visualization.plot.plot_map_mesh(xr_obj, x=None, y=None, ax=None, edgecolors='k', linewidth=0.1, add_background=True, add_gridlines=True, add_labels=True, fig_kwargs=None, subplot_kwargs=None, **plot_kwargs)[source][source]#
gpm.visualization.plot.plot_map_mesh_centroids(xr_obj, x=None, y=None, ax=None, c='r', s=1, add_background=True, add_gridlines=True, add_labels=True, fig_kwargs=None, subplot_kwargs=None, **plot_kwargs)[source][source]#

Plot GPM orbit granule mesh centroids in a cartographic map.

gpm.visualization.plot.plot_patches(patch_gen, variable=None, add_colorbar=True, interpolation='nearest', fig_kwargs=None, cbar_kwargs=None, **plot_kwargs)[source][source]#

Plot patches.

gpm.visualization.plot.plot_sides(sides, ax, **plot_kwargs)[source][source]#

Plot boundary sides.

Expects a list of (lon, lat) tuples.

gpm.visualization.plot.plot_xr_imshow(ax, da, x, y, interpolation='nearest', add_colorbar=True, add_labels=True, cbar_kwargs=None, visible_colorbar=True, **plot_kwargs)[source][source]#

Plot imshow with xarray.

The colorbar is added with xarray to enable to display multiple colorbars when calling this function multiple times on different fields with different colorbars.

gpm.visualization.plot.plot_xr_pcolormesh(ax, da, x, y, add_colorbar=True, cbar_kwargs=None, **plot_kwargs)[source][source]#

Plot pcolormesh with xarray.

gpm.visualization.plot.preprocess_figure_args(ax, fig_kwargs=None, subplot_kwargs=None, is_facetgrid=False)[source][source]#
gpm.visualization.plot.preprocess_rgb_dataarray(da, rgb)[source][source]#
gpm.visualization.plot.preprocess_subplot_kwargs(subplot_kwargs, infer_crs=False, xr_obj=None)[source][source]#

gpm.visualization.plot_3d module#

This module contains functions for 3D visualization of GPM-API RADAR data.

class gpm.visualization.plot_3d.IsosurfaceSlider(vol, method='contour', isovalue=None)[source][source]#

Bases: object

Define pyvista slider for 3D isosurfaces.

update()[source][source]#
class gpm.visualization.plot_3d.OpacitySlider(pl_actor)[source][source]#

Bases: object

Opacity Slider for pyvista pl.add_slider_widget.

class gpm.visualization.plot_3d.OrthogonalSlicesSlider(vol, x=1, y=1, z=1)[source][source]#

Bases: object

Define pyvista sliders for 3D orthogonal slices.

update()[source][source]#
gpm.visualization.plot_3d.add_3d_isosurface_slider(vol, pl, method='contour', isovalue=None, **mesh_kwargs)[source][source]#

Add a 3D isosurface slider enabling to slide through the 3D volume.

gpm.visualization.plot_3d.add_3d_isosurfaces(vol, pl, isovalues=[30, 40, 50], opacities=[0.3, 0.5, 1], method='contour', style='surface', add_sliders=False, **mesh_kwargs)[source][source]#

Add 3D isosurface to a pyvista plotter object.

If add_sliders=True, isosurface opacity can be adjusted interactively.

gpm.visualization.plot_3d.add_3d_orthogonal_slices(vol, pl, x=None, y=None, z=None, add_sliders=False, **mesh_kwargs)[source][source]#

Add 3D orthogonal slices with interactive sliders.

gpm.visualization.plot_3d.create_pyvista_2d_surface(data_array, spacing=(1, 1, 1), origin=(0, 0, 0))[source][source]#

Create a pyvista.ImageData object from a 2D xarray.DataArray.

gpm.visualization.plot_3d.create_pyvista_3d_volume(data_array, spacing=(1, 1, 0.25), origin=(0, 0, 0))[source][source]#

Create a pyvista.ImageData object from a 3D xarray.DataArray.

gpm.visualization.plot_3d.get_slider_button_positions(i, num_buttons, spacing_factor=0.04)[source][source]#

Return the pointa and pointb parameters for pl.add_slider_widget.

gpm.visualization.quicklooks module#

This module contains utility for generating quicklooks.

gpm.visualization.quicklooks.create_quicklooks_dataset(list_ds, spacing=2, total_size=200, concat_dim='along_track')[source][source]#

Concatenate multiple xarray.Dataset objects for quicklook plotting.

This function merges the Datasets in list_ds along the dimension concat_dim. Between consecutive Datasets, a dummy (NaN-filled) Dataset of width spacing is inserted to visually separate the events in a plot. After the last Dataset, any remaining space to reach total_size is also filled with NaNs.

A coordinate named “spacing_flag” is added to the result, indicating which indices in concat_dim are actual data (0) versus inserted NaNs (1).

Parameters:
  • list_ds (list of xarray.Dataset) – List of xarray Datasets to concatenate along the dimension concat_dim. All Datasets should share the same variables and dimension names, except for differences in the size of concat_dim.

  • spacing (int, optional) – Number of NaN entries to insert between consecutive Datasets. Defaults to 2.

  • total_size (int, optional) – The desired total size (maximum length) along the concat_dim dimension in the final “quicklook” dataset. Defaults to 200.

  • concat_dim (str, optional) – Name of the dimension along which to concatenate. Typically “along_track”.

Returns:

A new Dataset of size total_size (or less if the data plus spacing exceeds total_size) along the concat_dim dimension. Between real data segments, there are NaNs for visual separation, and an integer coordinate “spacing_flag” (1 = NaNs region, 0 = real data).

Return type:

xarray.Dataset

gpm.visualization.quicklooks.create_quicklooks_datasets(ds, list_slices, subplot_size=200, spacing=2, n_subplots=4, concat_dim='along_track')[source][source]#

Build an array dataset for quicklook plotting of interesting data regions.

It extracts slices of interest from the input dataset, ensuring each group of slices having a total length not exceeding subplot_size. Within each group, slices are concatenated along the “along_track” dimension, and a dummy (NaN) dataset of width spacing is inserted between slices to visually separate them. Any leftover space in the subplot is filled with NaNs.

A new coordinate, “spacing_flag”, is added to indicate the indices that correspond to these NaN (spacing) regions.

Parameters:
  • ds (xarray.Dataset) – The input dataset containing an “along_track” dimension.

  • list_slices (list of slice) – List of valid data segments along the “along_track” dimension.

  • subplot_size (int, optional) – Maximum length of each subplot (group of slices) along the “along_track” axis. Defaults to 200.

  • spacing (int, optional) – Number of NaN points inserted between consecutive slices in a subplot. Defaults to 2.

  • n_subplots (int, optional) – Maximum number of subplot groups to produce. Defaults to 4.

Returns:

A list of up to n_subplots datasets, each dataset having:

  • Dimension “along_track” size up to subplot_size.

  • Slices concatenated with NaNs for spacing.

  • A “spacing_flag” coordinate along “along_track” (0 for real data, 1 for NaN spacing).

Return type:

list of xarray.Dataset

gpm.visualization.quicklooks.get_subplot_slices(list_slices, subplot_size=100, spacing=2, n_subplots=4)[source][source]#

Group slices into subplots, ensuring each subplot stays within a maximum size.

This function accumulates slices (plus their inter-slice spacing) until adding another slice would exceed subplot_size. It then starts a new group (subplot). The number of subplots is capped at n_subplots.

Parameters:
  • list_slices (list of slice) – List of Python slice objects along an xarray object dimension. Each slice has a .start and .stop attribute (integers).

  • subplot_size (int, optional) – The maximum allowable sum of slice lengths (plus spacing) for each subplot. Defaults to 100.

  • spacing (int, optional) – Spacing that is reserved after each slice. Defaults to 2. This is accounted for in the total length when deciding whether a slice fits in the current subplot.

  • n_subplots (int, optional) – Maximum number of subplot groups to return. Defaults to 4.

Returns:

A list of sub-lists, where each sub-list contains the slices assigned to one subplot. Each group’s combined length (sum of slices plus spacing) does not exceed subplot_size (except possibly the last group), unless truncated by n_subplots.

Return type:

list of list of slice

gpm.visualization.title module#

This module contains utilities to define plot titles.

gpm.visualization.title.get_dataarray_title(da, prefix_product=True, add_timestep=True, time_idx=None, resolution='m', timezone='UTC')[source][source]#

Generate the plot title for a GPM xarray.DataArray.

Parameters:
  • da (xarray.DataArray) – GPM xarray DataArray.

  • prefix_product (bool, optional) – Whether to add the GPM product as prefix. The default is True.

  • add_timestep (bool, optional) – Whether to add time information to the title. The default is True. For GRID objects (like IMERG), the timestep is added only if the xarray.DataArray has 1 timestep.

  • time_idx (int, optional) – Index of timestep to select, instead of selecting the middle. The default is None.

  • resolution (str, optional) – The maximum temporal resolution to display. The default is “m” (for minutes).

  • timezone (str, optional) – The timezone of the time to display. The default is “UTC” (as the reference timezone of the dataset).

Returns:

title_str – Title of the xarray.DataArray.

Return type:

str

gpm.visualization.title.get_dataset_title(ds, add_timestep=True, time_idx=None, resolution='m', timezone='UTC')[source][source]#

Generate the GPM Dataset title.

Parameters:
  • ds (xarray.Dataset) – GPM xarray Dataset.

  • add_timestep (bool, optional) – Whether to add time information to the title. The default is True. For GRID objects (like IMERG), the timestep is added only if the xarray.DataArray has 1 timestep.

  • time_idx (int, optional) – Index of timestep to select, instead of selecting the middle. The default is None.

  • resolution (str, optional) – The maximum temporal resolution to display. The default is “m” (for minutes).

  • timezone (str, optional) – The timezone of the time to display. The default is “UTC” (as the reference timezone of the dataset).

Returns:

title_str – Title of the Dataset.

Return type:

str

gpm.visualization.title.get_time_str(timesteps, time_idx=None, resolution='m', timezone='UTC')[source][source]#

Return the time string from a single timestep or array of timesteps.

If an array, it takes the timesteps in the middle of the array.

Module contents#

This directory contains the GPM-API data visualization tools.

gpm.visualization.add_map_inset(ax, loc='upper left', inset_height=0.2, projection=None, inside_figure=True, border_pad=0)[source][source]#

Adds an inset map to a matplotlib axis using Cartopy, highlighting the extent of the main plot.

This function creates a smaller map inset within a larger map plot to show a global view or contextual location of the main plot’s extent.

It uses Cartopy for map projections and plotting, and it outlines the extent of the main plot within the inset to provide geographical context.

Parameters:
  • ax (matplotlib.axes.Axes or cartopy.mpl.geoaxes.GeoAxes) – The main matplotlib or cartopy axis object where the geographic data is plotted.

  • loc (str, optional) – The location of the inset map within the main plot. Options include 'lower left', 'lower right', 'upper left', and 'upper right'. The default is 'upper left'.

  • inset_height (float, optional) – The size of the inset height, specified as a fraction of the figure’s height. For example, a value of 0.2 indicates that the inset’s height will be 20% of the figure’s height. The aspect ratio (of the map inset) will govern the inset_width.

  • inside_figure (bool, optional) – Determines whether the inset is constrained to be fully inside the figure bounds. If True (default), the inset is placed fully within the figure. If False, the inset can extend beyond the figure’s edges, allowing for a half-outside placement.

  • projection (cartopy.crs.Projection, optional) – A cartopy projection. If None, am Orthographic projection centered on the extent center is used.

Returns:

ax2 – The Cartopy GeoAxesSubplot object for the inset map.

Return type:

cartopy.mpl.geoaxes.GeoAxes

Notes

The function adjusts the extent of the inset map based on the main plot’s extent, adding a slight padding for visual clarity. It then overlays a red outline indicating the main plot’s geographical extent.

Examples

>>> p = da.gpm.plot_map()
>>> add_map_inset(ax=p.axes, loc="upper left", inset_height=0.15)

This example creates a main plot with a specified extent and adds an upper-left inset map showing the global context of the main plot’s extent.

gpm.visualization.plot_cartopy_background(ax)[source][source]#

Plot cartopy background.

gpm.visualization.plot_colorbar(p, *, ax=None, cax=None, **cbar_kwargs)[source][source]#

Add a univariate colorbar to a matplotlib/cartopy plot.

You can either provide:

  • An existing Axes (ax) in which to place the colorbar (the colorbar will be appended to one of its sides).

  • A dedicated Axes object (cax) for direct drawing of the colorbar on the specified cax.

  • Or no Axes at all, in which case a new figure and Axes are created.

If both ax and cax are given, ax is ignored !.

Parameters:
  • mappable – The matplotlib.cm.ScalarMappable (i.e., AxesImage, ContourSet, etc.) described by the colorbar.

  • ax (matplotlib.axes.Axes or cartopy.mpl.geoaxes.GeoAxesSubplot, optional) – The Axes to which the colorbar should be appended. Ignored if cax is provided. If both ax and cax are None, a new figure and Axes are created.

  • cax (matplotlib.axes.Axes, optional) – The Axes in which to directly draw the colorbar. If provided, ax is ignored.

  • **cbar_kwargs (dict) – Additional keyword arguments passed to the matplotlib.figure.colorbar. See the matplotlib.figure.colorbar documentation. Arguments ‘size’ and ‘pad’ controls the size of the colorbar. and the padding between the plot and the colorbar only if cax is not specified !.

gpm.visualization.plot_image(da, x=None, y=None, ax=None, add_colorbar=True, add_labels=True, interpolation='nearest', fig_kwargs=None, cbar_kwargs=None, **plot_kwargs)[source][source]#

Plot data using imshow.

Parameters:
  • da (xarray.DataArray) – xarray DataArray.

  • x (str, optional) – X dimension name. If None, takes the second dimension. The default is None.

  • y (str, optional) – Y dimension name. If None, takes the first dimension. The default is None.

  • ax (cartopy.mpl.geoaxes.GeoAxes, optional) – The matplotlib axes where to plot the image. If None, a figure is initialized using the specified fig_kwargs. The default is None.

  • add_colorbar (bool, optional) – Whether to add a colorbar. The default is True.

  • add_labels (bool, optional) – Whether to add labels to the plot. The default is True.

  • interpolation (str, optional) – Argument to be passed to imshow. The default is "nearest".

  • fig_kwargs (dict, optional) – Figure options to be passed to matplotlib.pyplot.subplots. The default is None. Only used if ax is None.

  • subplot_kwargs (dict, optional) – Subplot options to be passed to matplotlib.pyplot.subplots. The default is None. Only used if `ax` is None.

  • cbar_kwargs (dict, optional) – Colorbar options. The default is None.

  • **plot_kwargs – Additional arguments to be passed to the plotting function. Examples include cmap, norm, vmin, vmax, levels, … For FacetGrid plots, specify row, col and col_wrap. With rgb you can specify the name of the xarray.DataArray RGB dimension.

gpm.visualization.plot_labels(obj, label_name=None, max_n_labels=50, add_colorbar=True, interpolation='nearest', cmap='Paired', fig_kwargs=None, **plot_kwargs)[source][source]#
gpm.visualization.plot_map(da, x=None, y=None, ax=None, interpolation='nearest', add_colorbar=True, add_background=True, add_labels=True, add_gridlines=True, add_swath_lines=True, fig_kwargs=None, subplot_kwargs=None, cbar_kwargs=None, **plot_kwargs)[source][source]#

Plot data on a geographic map.

Parameters:
  • da (xarray.DataArray) – xarray DataArray.

  • x (str, optional) – Longitude coordinate name. If None, takes the second dimension. The default is None.

  • y (str, optional) – Latitude coordinate name. If None, takes the first dimension. The default is None.

  • ax (cartopy.mpl.geoaxes.GeoAxes, optional) – The cartopy GeoAxes where to plot the map. If None, a figure is initialized using the specified fig_kwargs and subplot_kwargs. The default is None.

  • add_colorbar (bool, optional) – Whether to add a colorbar. The default is True.

  • add_labels (bool, optional) – Whether to add cartopy labels to the plot. The default is True.

  • add_gridlines (bool, optional) – Whether to add cartopy gridlines to the plot. The default is True.

  • add_swath_lines (bool, optional) – Whether to plot the swath sides with a dashed line. The default is True. This argument only applies for ORBIT objects.

  • add_background (bool, optional) – Whether to add the map background. The default is True.

  • interpolation (str, optional) – Argument to be passed to matplotlib.axes.Axes.imshow. Only applies for GRID objects. The default is "nearest".

  • fig_kwargs (dict, optional) – Figure options to be passed to matplotlib.pyplot.subplots. The default is None. Only used if ax is None.

  • subplot_kwargs (dict, optional) – Dictionary of keyword arguments for matplotlib.pyplot.subplots. Must contain the Cartopy CRS ` projection key if specified. The default is None. Only used if ax is None.

  • cbar_kwargs (dict, optional) – Colorbar options. The default is None.

  • **plot_kwargs – Additional arguments to be passed to the plotting function. Examples include cmap, norm, vmin, vmax, levels, … For FacetGrid plots, specify row, col and col_wrap. With rgb you can specify the name of the xarray.DataArray RGB dimension.

gpm.visualization.plot_map_mesh(xr_obj, x=None, y=None, ax=None, edgecolors='k', linewidth=0.1, add_background=True, add_gridlines=True, add_labels=True, fig_kwargs=None, subplot_kwargs=None, **plot_kwargs)[source][source]#
gpm.visualization.plot_patches(patch_gen, variable=None, add_colorbar=True, interpolation='nearest', fig_kwargs=None, cbar_kwargs=None, **plot_kwargs)[source][source]#

Plot patches.