bluemath_tk.core.plotting package

Submodules

bluemath_tk.core.plotting.base_plotting module

class bluemath_tk.core.plotting.base_plotting.BasePlotting[source]

Bases: ABC

Abstract base class for handling default plotting functionalities across the project.

abstractmethod plot_line(x, y)[source]

Abstract method for plotting a line. Should be implemented by subclasses.

abstractmethod plot_scatter(x, y)[source]

Abstract method for plotting a scatter plot. Should be implemented by subclasses.

class bluemath_tk.core.plotting.base_plotting.DefaultInteractivePlotting[source]

Bases: BasePlotting

Concrete implementation of BasePlotting with interactive plotting behaviors.

plot_line(x, y)[source]

Abstract method for plotting a line. Should be implemented by subclasses.

plot_map(markers=None)[source]
plot_scatter(x, y)[source]

Abstract method for plotting a scatter plot. Should be implemented by subclasses.

class bluemath_tk.core.plotting.base_plotting.DefaultStaticPlotting(template: str = 'default')[source]

Bases: BasePlotting

Concrete implementation of BasePlotting with static plotting behaviors.

get_subplot(figsize, **kwargs)[source]
get_subplots(**kwargs)[source]
plot_bathymetry(ax: Axes, source: str, area: Tuple[float, float, float, float], **kwargs) None[source]

Plot a bathymetry map from a bathymetry dataset stored in the PATHS dictionary.

Parameters:
  • ax (plt.Axes) – The axes on which to plot the data.

  • source (str) – The source of the bathymetry data. Must be a key in the PATHS dictionary.

  • area (Tuple[float, float, float, float]) – The area of the bathymetry data in the format (lon_min, lon_max, lat_min, lat_max).

  • **kwargs – Additional keyword arguments passed to the xr.Dataset.plot() function.

plot_line(ax: Axes, **kwargs)[source]

Abstract method for plotting a line. Should be implemented by subclasses.

plot_satellite(ax: Axes, area: Tuple[float, float, float, float], source: str = 'arcgis', **kwargs) None[source]

Downloads and displays a satellite/raster map for the given bounding box.

Parameters:
  • ax (plt.Axes) – The axes on which to plot the data.

  • source (str) – The source of the satellite data.

  • area (Tuple[float, float, float, float]) – The area of the satellite data.

  • **kwargs – Additional keyword arguments passed to the plotting function.

plot_scatter(ax: Axes, **kwargs)[source]

Abstract method for plotting a scatter plot. Should be implemented by subclasses.

templates = {'default': {'bathymetry': {'cmap': 'albita_ocean'}, 'line': {'color': 'blue', 'line_style': '-'}, 'scatter': {'color': 'red', 'marker': 'o', 'size': 10}}}

bluemath_tk.core.plotting.colors module

bluemath_tk.core.plotting.colors.GetFamsColors(num_fams: int) ndarray[source]

Get colors for wave families.

Parameters:

num_fams (int) – Number of wave families.

Returns:

Array of RGB colors for the specified number of wave families.

Return type:

np.ndarray

bluemath_tk.core.plotting.colors.colormap_bathy(topat: float, topag: float) ListedColormap[source]

Create custom colormap for bathymetry plot.

Parameters:
  • topat (float) – Maximum topography value.

  • topag (float) – Minimum bathymetry value.

Returns:

Custom colormap combining YlGnBu_r and turbid colormaps.

Return type:

ListedColormap

bluemath_tk.core.plotting.colors.colormap_spectra() ListedColormap[source]

Create custom colormap for spectra plots combining RdBu and rainbow colormaps.

Returns:

Custom colormap combining RdBu and rainbow colormaps.

Return type:

ListedColormap

bluemath_tk.core.plotting.colors.colors_awt() ndarray[source]

Get colors for Annual Weather Types (6 categories).

Returns:

Array of RGB colors for 6 AWT categories

Return type:

np.ndarray

bluemath_tk.core.plotting.colors.colors_dwt(num_clusters: int) ndarray[source]

Get colors for Daily Weather Types.

Parameters:

num_clusters (int) – Number of clusters to get colors for.

Returns:

Array of RGB colors for the specified number of clusters.

Return type:

np.ndarray

bluemath_tk.core.plotting.colors.colors_fams_3() ndarray[source]

Get colors for 3 wave families.

Returns:

Array of RGB colors for 3 wave families.

Return type:

np.ndarray

bluemath_tk.core.plotting.colors.colors_interp(num_clusters: int) ndarray[source]

Generate interpolated colors from Spectral colormap.

Parameters:

num_clusters (int) – Number of clusters to generate colors for.

Returns:

Array of RGB colors interpolated from Spectral colormap.

Return type:

np.ndarray

bluemath_tk.core.plotting.colors.colors_mjo() ndarray[source]

Get colors for MJO 25 categories.

Returns:

Array of RGB colors for 25 MJO categories.

Return type:

np.ndarray

bluemath_tk.core.plotting.colors.get_cluster_colors(num_clusters: int) ndarray[source]

Get appropriate colors for clustering based on number of clusters.

Parameters:

num_clusters (int) – Number of clusters to get colors for.

Returns:

Array of RGB colors for the specified number of clusters.

Return type:

np.ndarray

bluemath_tk.core.plotting.colors.get_config_variables() Dict[str, Dict[str, Any]][source]

Get configuration variables for different meteorological parameters.

Returns:

Dictionary containing configuration for different variables: - geo500hpa: Geopotential height at 500hPa - mslp: Mean Sea Level Pressure - mslp_grad: MSLP gradient - sst: Sea Surface Temperature - other: Default configuration

Return type:

Dict[str, Dict[str, Any]]

bluemath_tk.core.plotting.satellite module

bluemath_tk.core.plotting.satellite.calculate_zoom(lon_min: float, lon_max: float, display_width_px: int = 1024, tile_size: int = 256) int[source]

Automatically estimates an appropriate zoom level for the bounding box.

Parameters:
  • lon_min (float) – The minimum longitude of the bounding box.

  • lon_max (float) – The maximum longitude of the bounding box.

  • display_width_px (int) – The width of the display in pixels. Default is 1024.

  • tile_size (int) – The size of the tile in pixels. Default is 256.

Returns:

zoom – Estimated zoom level.

Return type:

int

bluemath_tk.core.plotting.satellite.deg2num(lat: float, lon: float, zoom: int) Tuple[int, int][source]

Converts geographic coordinates to tile numbers for a given zoom level.

Parameters:
  • lat (float) – Latitude in degrees.

  • lon (float) – Longitude in degrees.

  • zoom (int) – Zoom level.

Returns:

  • xtile (int) – Tile number in x-direction.

  • ytile (int) – Tile number in y-direction.

bluemath_tk.core.plotting.satellite.get_cartopy_scale(zoom: int) str[source]

Select appropriate cartopy feature scale based on zoom level.

Parameters:

zoom (int) – Web Mercator zoom level.

Returns:

scale – One of ‘110m’, ‘50m’, or ‘10m’.

Return type:

str

bluemath_tk.core.plotting.satellite.get_satellite_image(source: str, area: Tuple[float, float, float, float], zoom: int = None, display_width_px: int = 1024) Tuple[Image, Tuple[float, float, float, float]][source]

Downloads a satellite map for the given bounding box.

Parameters:
  • source (str) – The source of the satellite data.

  • area (Tuple[float, float, float, float]) – The area of the satellite data.

  • zoom (int) – The zoom level of the satellite data.

  • display_width_px (int) – The width of the display in pixels.

Returns:

  • map_img (Image.Image) – The satellite map image.

  • extent (Tuple[float, float, float, float]) – The extent of the satellite map (Web Mercator projection).

bluemath_tk.core.plotting.satellite.lonlat_to_webmercator(lon: float, lat: float) Tuple[float, float][source]

Converts lon/lat to Web Mercator projection coordinates in meters.

Parameters:
  • lon (float) – Longitude in degrees.

  • lat (float) – Latitude in degrees.

Returns:

  • x (float) – X coordinate in meters.

  • y (float) – Y coordinate in meters.

bluemath_tk.core.plotting.satellite.num2deg(xtile: int, ytile: int, zoom: int) Tuple[float, float][source]

Converts tile numbers back to geographic coordinates.

Parameters:
  • xtile (int) – Tile number in x-direction.

  • ytile (int) – Tile number in y-direction.

  • zoom (int) – Zoom level.

Returns:

  • lat (float) – Latitude in degrees.

  • lon (float) – Longitude in degrees.

bluemath_tk.core.plotting.satellite.tile_bounds_meters(x_start: int, y_start: int, x_end: int, y_end: int, zoom: int) Tuple[float, float, float, float][source]

Computes the bounding box of the tile region in Web Mercator meters.

Parameters:
  • x_start (int) – The starting x-coordinate of the tile.

  • y_start (int) – The starting y-coordinate of the tile.

  • x_end (int) – The ending x-coordinate of the tile.

  • y_end (int) – The ending y-coordinate of the tile.

  • zoom (int) – The zoom level of the tile.

Returns:

xmin, ymin, xmax, ymax – Bounding box in meters (Web Mercator projection).

Return type:

float

bluemath_tk.core.plotting.scatter module

bluemath_tk.core.plotting.scatter.density_scatter(x: ndarray, y: ndarray) Tuple[ndarray, ndarray, ndarray][source]

Compute a density scatter for two arrays using gaussian KDE.

Parameters:
  • x (np.ndarray) – X values for the scatter plot.

  • y (np.ndarray) – Y values for the scatter plot.

Returns:

A tuple containing: - Sorted x values - Sorted y values - Density values corresponding to each point

Return type:

Tuple[np.ndarray, np.ndarray, np.ndarray]

bluemath_tk.core.plotting.scatter.plot_scatters_in_triangle(dataframes: List[DataFrame], data_colors: List[str] | None = None, **kwargs) Tuple[Figure, ndarray][source]

Plot scatter plots of the dataframes with axes in a triangle arrangement.

Parameters:
  • dataframes (List[pd.DataFrame]) – List of dataframes to plot. Each dataframe should contain the same columns.

  • data_colors (Optional[List[str]], optional) – List of colors for the dataframes. If None, uses default_colors.

  • **kwargs (dict, optional) – Additional keyword arguments for the scatter plot. These will be passed to matplotlib.pyplot.scatter. Common parameters include: - s : float, marker size - alpha : float, transparency - marker : str, marker style

Returns:

A tuple containing: - Figure object - 2D array of Axes objects

Return type:

Tuple[Figure, np.ndarray]

Raises:

ValueError – If the variables in the first dataframe are not present in all other dataframes.

bluemath_tk.core.plotting.scatter.validation_scatter(axs: Axes, x: ndarray, y: ndarray, xlabel: str, ylabel: str, title: str, cmap: str = 'rainbow') None[source]

Plot a density scatter and Q-Q plot for validation.

Parameters:
  • axs (Axes) – Matplotlib axes to plot on.

  • x (np.ndarray) – X values for the scatter plot.

  • y (np.ndarray) – Y values for the scatter plot.

  • xlabel (str) – Label for the X-axis.

  • ylabel (str) – Label for the Y-axis.

  • title (str) – Title for the plot.

  • cmap (str, optional) – Colormap to use for the scatter plot. Default is “rainbow”.

bluemath_tk.core.plotting.utils module

bluemath_tk.core.plotting.utils.create_cmap_from_colors(color_list: List[str], name: str = 'custom') LinearSegmentedColormap[source]

Create a colormap from a list of hex colors.

Parameters:
  • color_list (List[str]) – List of hex color codes (e.g., [“#ff0000”, “#00ff00”])

  • name (str, optional) – Name for the colormap. Default is “custom”.

Returns:

A colormap created from the provided colors.

Return type:

colors.LinearSegmentedColormap

bluemath_tk.core.plotting.utils.get_list_of_colors_for_colormap(cmap: str | Colormap, num_colors: int) list[source]

Get a list of colors from a colormap.

Parameters:
  • cmap (Union[str, Colormap]) – The colormap to use.

  • num_colors (int) – The number of colors to generate.

Returns:

A list of colors generated from the colormap.

Return type:

list

bluemath_tk.core.plotting.utils.join_colormaps(cmap1: str | List[str] | Colormap, cmap2: str | List[str] | Colormap, name: str = 'joined_cmap', range1: Tuple[float, float] = (0.0, 1.0), range2: Tuple[float, float] = (0.0, 1.0), value_range1: Tuple[float, float] = None, value_range2: Tuple[float, float] = None) Tuple[ListedColormap, BoundaryNorm][source]

Join two colormaps into one, with value ranges specified for each.

Parameters:
  • cmap1 (Union[str, List[str], Colormap]) – Input colormaps (name, list of hex codes, or Colormap object).

  • cmap2 (Union[str, List[str], Colormap]) – Input colormaps (name, list of hex codes, or Colormap object).

  • name (str) – Name of the output colormap.

  • range1 (Tuple[float, float]) – Portion of each colormap to use (from 0 to 1).

  • range2 (Tuple[float, float]) – Portion of each colormap to use (from 0 to 1).

  • value_range1 (Tuple[float, float]) – Value ranges in the data domain corresponding to each colormap.

  • value_range2 (Tuple[float, float]) – Value ranges in the data domain corresponding to each colormap.

Returns:

  • ListedColormap – Merged colormap object.

  • BoundaryNorm – Normalization for mapping data to colors.

Module contents