Skip to content

Conversation

@mkavulich
Copy link
Collaborator

@mkavulich mkavulich commented Dec 8, 2025

This PR revamps mpas_plot to use the latest and greatest UXarray version 2025.09, which includes rasterized plotting rather than constructing polygons from the original grid. Rasterized plotting is an order of magnitude (or more) faster than the polycollection method, especially for large domains and alternate projections where it was essentially impossible to produce plots in a reasonable amount of time.

New settings

New setting polycollection

False by default, the polycollection option will allow users to use the old method of plotting that plots the true polygons of the input unstructured grids. This is retained for back-compatibility (and the retaining of a few features that are not yet supported for rasterization, such as plotting the grid edges) but is not recommended due to its slowness, and due to a known issue with plotting periodic (global) data in the latest UXarray libraries; see UXARRAY/uxarray#1386 for more details

Pixel ratio

Rasterization is an inherently lossy process, but we can control the quality of the output using the setting pixel_ratio. The default value is 1, which will result in very good plots for most domains, but may look "pixelated" at small scales for very large/high resolution domains. Increasing this value will result in finer quality images, resolving the true polygons of the native grid data, but will take longer to create. Conversely, for plots where fine detail is not important, you can decrease pixel_ratio for an increase in plotting speed.

maxval and minval

New in this PR, maxval and minval are added as substitutable keys in plot titles, names, etc. This is the maximum and minimum numerical values respectively for the given plotted domain.

New custom function: sum_of_magnitudes

This new function allows the input of a u and v wind vector (or any two perpendicular vector fields) and outputs the magnitude of the vector field (wind speed from wind vectors, for example).

Other changes

  • Re-add line mpl.use("Agg") that was accidentally removed in an earlier PR; this fixes some memory problems when creating large numbers of of plots.
  • Only use starmap when parallel processing is used
  • Automatically load mpas_plot conda environment when sourcing setup script
  • Add a check that the latrange and lonrange are valid

Example plot

dataset:
  vars:
    wind10m:
      source: derived
      function: sum_of_magnitudes
      inputs:
        - "u10"
        - "v10"
      attrs:
        long_name: "10-meter wind magnitude"
        units: "m s^{-1}"
      plot:
        colormap: gsl_wind_speed
        colorbins: 20
        vmax: 40
        vmin: 0
plot:
  title:
    text: 'Plot of {varln}, level {lev} for {date} {time}, Max: {maxval}, Min: {minval}'
wind10m_lev0_2020-09-08_19:00:00

…polycollection method with plot:polycollection:True

 - Had to rearrange a lot of logic in plotit(), so the changes look way more invasive than they actually are
 - Had to implement manual setting of domain bounds using new custom function get_data_extent(), though it needs more work
 - Also changed default image size and resolution to be a bit smaller
…n get_data_extent() function; also fix level 0 error. Currently may not work for polycollection
 - Add back in mpl.use("Agg"); not sure how I dropped that at some point
 - Better error handling to hopefully not hang on Ctrl-C
 - Set axes extent before calls to to_polycollection or to_raster; this should speed things up a lot when only plotting part of a domain
 - "colorbins" setting now works for built-in colormaps in addition to custom ones
 - remove many unnecessary prints and commented code
 - Add timer for full script in addition to individual plots
@mkavulich
Copy link
Collaborator Author

Important note: I have not yet fixed global plots with alternate projections; hopefully I will find time to add this in later.

@mkavulich mkavulich marked this pull request as draft December 8, 2025 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants