Skip to content

to_polycollection() data array method fails when called with periodic_elements='exclude' #1507

Closed

Description

@mkavulich

Version

v2026.04.1

How did you install UXarray?

Conda

What happened?

With newer UXarray versions (starting with v2026.02), the data array method .to_polycollection(periodic_elements='exclude') (which I believe is the default value for this argument) results in an exception being raised:

$ python mcve.py 
Traceback (most recent call last):
  File "/scratch3/BMC/hmtb/Michael.Kavulich/MPAS/plotting_scripts/raster_PR/mpas_plot/mcve.py", line 45, in <module>
    plotit(dataset[var].isel(Time=0),ftime_dt)
    ~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/scratch3/BMC/hmtb/Michael.Kavulich/MPAS/plotting_scripts/raster_PR/mpas_plot/mcve.py", line 11, in plotit
    pc=uxda.to_polycollection(periodic_elements='exclude')
  File "/scratch3/BMC/hmtb/Michael.Kavulich/MPAS/plotting_scripts/raster_PR/mpas_plot/conda/envs/mpas_plot/lib/python3.13/site-packages/uxarray/core/dataarray.py", line 327, in to_polycollection
    _data = np.delete(
        self.values,
    ...<3 lines>...
        axis=0,
    )
  File "/scratch3/BMC/hmtb/Michael.Kavulich/MPAS/plotting_scripts/raster_PR/mpas_plot/conda/envs/mpas_plot/lib/python3.13/site-packages/numpy/lib/_function_base_impl.py", line 5444, in delete
    keep[obj,] = False
    ~~~~^^^^^^
IndexError: arrays used as indices must be of integer (or boolean) type

Changing the argument to periodic_elements='split' or periodic_elements='ignore' resulted in a successful plot (though the latter results in an incorrect plot, seemingly identical to the problem described in #1386).

The MCVE below should be runnable on Derecho and Casper; I staged the example data there, though I have seen this with two completely different MPAS datasets so I assume this will occur with any data.

What did you expect to happen?

I expected successful plot generation. The example script mcve.py runs successfully with v2025.12 (though this older version exhibits the problems from the since-fixed issue #1386).

Can you provide a MCVE to repoduce the bug?

#!/usr/bin/env python3
from datetime import datetime

import matplotlib.pyplot as plt
import cartopy.feature as cfeature
import cartopy.crs as ccrs

import uxarray as ux

def plotit(uxda: ux.UxDataArray,ftime) -> None:
    pc=uxda.to_polycollection()
    pc.set_antialiased(False)
    pc.set_cmap('viridis')

    fig, ax = plt.subplots(1, 1, figsize=(8,4), dpi=300, constrained_layout=True,
                           subplot_kw=dict(projection=ccrs.PlateCarree()))

    ax.add_feature(cfeature.NaturalEarthFeature(category='cultural', scale='50m',edgecolor='k',facecolor='none',linewidth=0.2, name='admin_0_countries'))
    ax.add_feature(cfeature.NaturalEarthFeature(category='physical',color='k',facecolor='none',
                           linewidth=0.5, scale='10m', name='coastline'))

    pc.set_transform(ccrs.PlateCarree())

    coll = ax.add_collection(pc, autolim=True)
    ax.autoscale()

    plt.title(f'Plot of 2-meter temperature for MPAS forecast, {ftime}',fontsize=8)

    cbar = plt.colorbar(coll,ax=ax,orientation='vertical')
    cbar.set_label('Units: {units}', fontsize=8)

    plt.savefig('example.png',format='png')
    plt.close(fig)
    print("Done saving 'example.png'")


if __name__ == "__main__":

    fn='/glade/work/kavulich/MPAS/tutorial/120km_global/rundir/history.2025-05-14_00.00.00.nc'
    var='t2m'
    timestring='2025-05-14_00:00:00'
    ftime_dt = datetime.strptime(timestring.strip(), "%Y-%m-%d_%H:%M:%S")
    dataset=ux.open_dataset(fn,fn)

    plotit(dataset[var].isel(Time=0),ftime_dt)

Activity

  1. added
    bug
    on May 12, 2026
  2. moved this from 📚 Backlog to 📝 To-Do in UXarray Developmenton May 13, 2026
  3. erogluorhan commented on May 13, 2026

    @erogluorhan
    Member

    Hey @mkavulich thanks very much for reporting this! We'll start looking into it next week.

  4. moved this from 📝 To-Do to ✅ Done in UXarray Developmenton May 14, 2026
  5. erogluorhan commented on May 14, 2026

    @erogluorhan
    Member

    Hey @mkavulich , this should now be fixed in the main branch and would soon be released. Please give it a try either way and let us know if there is any issue.

  6. added a commit that references this issue on May 22, 2026
    ae51717
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Fields

Priority

None yet

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions