Skip to content

to_raster producing all the same value #1393

@brianpm

Description

@brianpm

Version

2025.9.0

How did you install UXarray?

Conda

What happened?

I'm having a problem where to_raster is just returning an array of all the same value. I'm not sure if there's something weird about this dataset or what. Here's my example:

b_loc = Path("/glade/work/brianpm/trbelt_derived") / "te_mcs_FLUT_blobs_20250908"
b_file = b_loc / "te_stitchblobs.nc"
grid_file = "/glade/work/brianpm/VRM2112/ne0np4.trbelta.ne30x8/grids/trbelta_ne30x8_np4_MESH.nc"
b_ds = ux.open_dataset(grid_file, b_file)
insta = b_ds['MCS'].isel(time=2468).compute()

# `plot` WORKS:
insta.plot()

# `to_raster` DOES NOT WORK:
proj = ccrs.EckertIV()

fig, ax = plt.subplots(subplot_kw={"projection":proj})
raster, pxmap = insta.to_raster(ax, return_pixel_mapping=True)
ax.set_global()
ax.coastlines()
ax.imshow(raster,origin="lower", extent=ax.get_xlim() + ax.get_ylim())

# `to_polycollection` WORKS:
poly_collection = insta.to_polycollection(rasterized=True)
poly_collection.set_antialiased(False)

fig, ax = plt.subplots(
    1,
    1,
    facecolor="w",
    constrained_layout=True,
    subplot_kw=dict(projection=proj),
)

ax.coastlines()

ax.add_collection(poly_collection)
ax.set_global()
plt.title("PolyCollection")

Here are the results:
Image

Image Image

What did you expect to happen?

Expecting a similar result as to_polycollection (but faster and producing a smaller pdf file when saved).

Can you provide a MCVE to repoduce the bug?

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status

📚 Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions