Skip to content

Conversation

@andrewdnolan
Copy link
Collaborator

Closes #44, which was introduced by #29. norm must be passed to the Polycollection instantiation.

CC'ing @cbegeman, as this should fix the issues you've seen with mosaic 1.12.0 in polaris.

Ensure the vmin/vmax of the norm is applied to polycollection.
@andrewdnolan andrewdnolan self-assigned this Nov 6, 2025
@andrewdnolan andrewdnolan added the bug Something isn't working label Nov 6, 2025
@andrewdnolan
Copy link
Collaborator Author

Testing:

Using the same MWE example code the from the issue documentaiton #44:

import cartopy.crs as ccrs
import matplotlib.colors as cols
import matplotlib.pyplot as plt
import mosaic
import xarray as xr

from pathlib import Path

transform = ccrs.PlateCarree()
projection = ccrs.PlateCarree()

ds = mosaic.datasets.open_dataset("QU.240km")

descriptor = mosaic.Descriptor(ds, projection, transform)

nCells = ds.sizes["nCells"]
vmin = nCells // 2 - nCells // 10
vmax = nCells // 2 + nCells // 10

norm = cols.Normalize(vmin=vmin, vmax=vmax)

def plot(ds, descriptor, kwargs):
    fig, ax = plt.subplots(
        constrained_layout=True, subplot_kw={"projection": projection}
    )

    pc = mosaic.polypcolor(
        ax, descriptor, ds.indexToCellID, **kwargs
    )

    fig.colorbar(pc, extend='both', shrink=0.6)
    
    plt.show()

Specifying vmin/vmax explicitly

plot(ds, descriptor, {"vmin": vmin, "vmax": vmax})
vmin_vmax_kwargs

Passing vmin/vmax to norm, and then providing mosaic with norm argument

plot(ds, descriptor, {"norm": norm})
vmin_vmax_norm

@cbegeman
Copy link

cbegeman commented Nov 6, 2025

@andrewdnolan Great, thanks! It looks like you've done adequate testing here so I'll wait for the mosaic update in Polaris unless you'd like me to try this fix out.

@andrewdnolan
Copy link
Collaborator Author

I've also tested with the 240km output from the spherical rotation_2d polaris testcase. The issue also appears to be fixed there.

I'll get this merged and have a patch release out ASAP.

@andrewdnolan andrewdnolan merged commit b979c97 into E3SM-Project:main Nov 6, 2025
6 checks passed
@andrewdnolan andrewdnolan deleted the fix_setting_norm branch November 6, 2025 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Polycollections vmin/vmax not enforced if passed as kwarg to norm

2 participants