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.

Reductions

Part 3: Aggregations by Name (Functional Ops on Dims)

This notebook demonstrates dimension-aware reductions and numerical integration using the untag + cmap pattern.

3.1 Calculating the Time-Mean Map

Temperature field: ('time', 'latitude', 'longitude'), shape: (36, 16, 32)

Computing the time mean

Time-mean map: ('latitude', 'longitude'), shape: (16, 32)

Seasonal climatology

Monthly climatology: ('month', 'latitude', 'longitude'), shape: (12, 16, 32)

3.2 Area-Weighted Global Mean Temperature

Computing cosine-latitude weights

Latitude weights: ('latitude',), shape: (16,)
Global mean temperature: 30.85 °C

Alternative: zonal-mean then latitude-weighted average

Zonal mean: ('latitude',), shape: (16,)
Global mean (v2): 30.85 °C
Methods agree (tol 1e-3): True

3.3 Integrating Ocean Heat Content (Trapezoid Rule)

Ocean temperature: ('depth', 'latitude', 'longitude'), shape: (20, 8, 16)

Trapezoid-rule integration over depth

Integrated temperature: ('latitude', 'longitude'), shape: (8, 16)
Ocean heat content (GJ/m²) — mean: 32.03

Cumulative integration

Cumulative temperature: ('depth', 'latitude', 'longitude'), shape: (20, 8, 16)

Key Patterns Summary

1. Simple reduction

result = cx.cmap(lambda x: jnp.mean(x, axis=0))(field.untag('time'))

2. Weighted aggregation

weighted = field * weights          # broadcasting
result = cx.cmap(jnp.sum)(weighted.untag('lat', 'lon')) / total_weight

3. Numerical integration

integrated = cx.cmap(lambda f: trapezoid_integrate(f, z_vals))(field.untag('z'))

4. Cumulative operations

cumul = cx.cmap(lambda f: cumulative_trap(f, x))(field.untag('x')).tag(x_axis)