Skip to content

Data_Operations

Carles Tena edited this page Oct 6, 2026 · 3 revisions

Statistics and grid transformations

Load variables before numerical operations. In MPI runs, call global reductions on all ranks.

from nes import open_netcdf

dataset = open_netcdf("input.nc")
dataset.keep_vars(["NO2"])
dataset.load()
print(dataset.get_totals())
print(dataset.get_min("NO2"), dataset.get_max("NO2"))
dataset.close()

get_totals() returns per-variable global sums on every rank. These are sums of stored values, not integrals weighted by cell area. Non-numeric variables contribute zero. get_min and get_max return global extrema ignoring NaN; entirely NaN or non-numeric variables return NaN.

sum_axis(axis="Z") modifies loaded data in place and retains a size-one dimension. T updates time and time bounds; Z updates levels. Reduction over the axis used for MPI decomposition is rejected. Prefer T or Z for a dataset you intend to write with consistent time/level metadata.

last_time_step() retains the final data slice, but sets its time coordinate to midnight of the first full timestamp. It rejects T decomposition. Use this operation only when that daily-label convention is intended. daily_statistic and rolling_mean are illustrated in the statistics tutorial.

Grid and data transformations

expand(n_cells=1) adds spatial border cells; contract(n_cells=1) removes them. Both modify the grid and its variables. Point grids reject these operations. They are also used by nearest-neighbour border correction.

to_dtype(data_type="float32") casts loaded variable arrays in place. Choose a type appropriate to the desired precision.

convert_longitudes() modifies loaded data and longitudes from [0, 360] to [-180, 180], reordering the longitude axis. It requires serial execution and fully loaded data, and rejects already converted or unrecognized longitude formats. Write the result separately with to_netcdf. See also the reorder CLI.

The legacy sum tutorial is not included in the current GitHub wiki.

Clone this wiki locally