uxarray.UxDataArray.to_raster

uxarray.UxDataArray.to_raster#

UxDataArray.to_raster(ax)#

Rasterizes a data variable stored on the faces of an unstructured grid onto the pixels of the provided Cartopy GeoAxes.

Parameters:

ax (GeoAxes) – A Cartopy GeoAxes onto which the data will be rasterized. Each pixel in this axes will be sampled against the unstructured grid’s face geometry.

Returns:

raster – Array of resampled data values corresponding to each pixel.

Return type:

numpy.ndarray, shape (ny, nx)

Notes

  • This method currently employs a nearest-neighbor resampling approach. For every pixel in the GeoAxes, it finds the face of the unstructured grid that contains the pixel’s geographic coordinate and colors that pixel with the face’s data value.

  • If a pixel does not intersect any face (i.e., lies outside the grid domain), it will be left empty (transparent).

Example

>>> import cartopy.crs as ccrs
>>> import matplotlib.pyplot as plt

Create a GeoAxes with a Robinson projection and global extent

>>> fig, ax = plt.subplots(subplot_kw={"projection": ccrs.Robinson()})
>>> ax.set_global()

Rasterize data onto the GeoAxes

>>> raster = uxds["psi"].to_raster(ax=ax)

Use Imshow to visualuze the raster

>>> ax.imshow(raster, origin="lower", extent=ax.get_xlim() + ax.get_ylim())