Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

UXarray for Advanced HEALPix Analysis & Visualization

HEALPix logo

UXarray for Advanced HEALPix Analysis & Visualization

In this section, you’ll learn:

  • Using the uxarray package to perform advanced analysis operators over HEALPix data such as non-conservative zonal means, etc.

Prerequisites

ConceptsImportanceNotes
UXarrayNecessary
HEALPix overviewNecessary

Time to learn: 30 minutes


Open data catalog

Let us open the online catalog from the WCRP’s Digital Earths Global Hackathon 2025 catalog repository using intake and read the output of the ICON run d3hp003, which is stored in the HEALPix format:

/home/runner/micromamba/envs/healpix-cookbook-dev2/lib/python3.14/site-packages/intake/catalog/utils.py:173: UserWarning: Shell command not executed due to getshell=False
  warnings.warn("Shell command not executed due to getshell=False")
/home/runner/micromamba/envs/healpix-cookbook-dev2/lib/python3.14/site-packages/intake/catalog/utils.py:182: UserWarning: Shell command not executed due to getshell=False
  warnings.warn("Shell command not executed due to getshell=False")

We can look into the highest possible resolution level allowed in this dataset at zoom level = 9 as Xarray.Dataset:

Create UXarray Datasets from HEALPix

We can use UXarray’s from_healpix API as follows to open a HEALPix grid from xarray.Dataset:

Loading...

Data variable of interest

Then let us pick a variable, the surface temperature, from the dataset, which will give us an uxarray.UxDataArray:

Loading...

Global mean and plot

Computing the global surface temperature mean (at the first timestep) and also having a quick plot of it would be a good idea to have as references to compare the upcoming analyses & visualizations to them:

Global surface temperature average on  2020-01-02T00:00:00.000000000 :  286.9924  K
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
CPU times: user 9.44 s, sys: 229 ms, total: 9.67 s
Wall time: 10.5 s

Rasterized point plots

When working with a higher-resolution dataset at a global scale, it’s not always practical to render each cell as a polygon. Instead, we can rasterize the center of each pixel.

CPU times: user 362 ms, sys: 4.96 ms, total: 367 ms
Wall time: 481 ms

If we decrease the size of each pixel (by setting the pixel ratio to a higher value), we can start to see missing values, which is due to a lower density of points near the poles, leading to some pixels not containing any of our original points.

Because of this, it’s useful to try a few pixel_ratio values and see which one works best for your given resolution.

Cross-sections

We can look at constant latitude/longitude cross-sections of an uxarray.UxDataArray:

/tmp/ipykernel_4353/1448597744.py:9: DeprecationWarning: The ‘.cross_section.constant_latitude’ method is deprecated and will be removed in a future release; please use the `.subset.constant_latitude` accessor instead.
  uxda_lat = uxda_coarse.cross_section.constant_latitude(boulder_lat)
Loading...

Let’s also look at the mean of the cross-section:

Mean at 40.019 degrees lat (Boulder, CO, USA): 288.3074645996094 K

Latitude interval

/tmp/ipykernel_4353/2145717487.py:1: DeprecationWarning: The ‘.cross_section.constant_latitude_interval’ method is deprecated and will be removed in a future release; please use the `.subset.constant_latitude_interval` accessor instead.
  uxda_lat_interval = uxda_coarse.cross_section.constant_latitude_interval(
Mean at the latitude interval of [35.019,45.019] degrees (-/+15 degrees Boulder, CO, USA): nan K

Non-conservative zonal mean

Calculating the zonal mean is easy by providing the latitude range between -90 and 90 degrees with a step size in degrees:

CPU times: user 12.4 s, sys: 41.9 ms, total: 12.5 s
Wall time: 12.5 s
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Remapping

Now, we will be looking into one of many possible use cases where remapping would be helpful.

The data set we have been using in this section so far belongs to the newer ICON simulation, icon_d3hp003, while there is an older simulation as well, icon_ngc4008, in the same catalog. They are both stored in the HEALPix format in this case, but for most of the model intercomparison workflows in general, they might not be even so. UXarray would still be helpful to remap of those model outputs to other and then make comparisons since it can support several most commonly used unstructrued grid formats.

In this particular case, we still have some use for UXarray’s remapping such that the newer simulation has the zoom = 9 as the maximum available resolution, while the older one has zoom = 10 available. Unfortunately at zoom = 10 though, there is no actual data simulated for ts, the surface temperature. If there was, we could remap the newer simulation’s output to that one, so we could have both of them at zoom = 10, and then we could look into the difference between them for instance. Let’s pretend the highest zoom-level in the newer data is zoom = 8 then, and remap that one into the older simulation’s grid.

Let’s start with opening the older simulation run first:

/home/runner/micromamba/envs/healpix-cookbook-dev2/lib/python3.14/site-packages/intake/catalog/utils.py:173: UserWarning: Shell command not executed due to getshell=False
  warnings.warn("Shell command not executed due to getshell=False")
/home/runner/micromamba/envs/healpix-cookbook-dev2/lib/python3.14/site-packages/intake/catalog/utils.py:182: UserWarning: Shell command not executed due to getshell=False
  warnings.warn("Shell command not executed due to getshell=False")
Loading...

Plot the older simulation for reference

Let’s have a quick look at how the global surface temperature looks like in the older simulation’s output:

Visually there does not seem to be a huge difference between this and the newer simulation’s output we had plotted in the very beginning.

Remap the old simulation output to the newer one

Let’s start remapping! For that, we will use the uxgrid of the newer simulation output as the destination grid and use an inverse distance weighted implementation:

CPU times: user 32.4 ms, sys: 6.04 ms, total: 38.5 ms
Wall time: 754 ms
/home/runner/micromamba/envs/healpix-cookbook-dev2/lib/python3.14/site-packages/uxarray/remap/utils.py:87: UserWarning: No spatial coordinate variables found in `source`.
  output_coords = coords_remapper.construct_output_coords()

Plot the difference between the old and newer simulations

Now that we have the older and newer model outputs on the same grid, let’s look at the surface temperature differences between the two:

WARNING:param.GeoOverlayPlot01249: Due to internal constraints, when aspect and width/height is set, the bokeh backend uses those values as frame_width/frame_height instead. This ensures the aspect is respected, but means that the plot might be slightly larger than anticipated. Set the frame_width/frame_height explicitly to suppress this warning.
Loading...