Skip to content

short_examples

Carles Tena edited this page Oct 6, 2026 · 1 revision

NES Short Examples

These examples show a small Python workflow and command-line checks without requiring a benchmark download. Install and activate NES first; see How to install.

Table of Contents


1. Create a small dataset

Save the following script as create_example.py:

from datetime import datetime
import numpy as np
from nes import create_nes

dataset = create_nes(
    projection="regular",
    lat_orig=40.0, lon_orig=0.0,
    inc_lat=1.0, inc_lon=1.0, n_lat=3, n_lon=4,
    times=[datetime(2026, 1, 1)],
)
dataset.variables = {
    "example": {
        "data": np.ones((1, 1, 3, 4), dtype=np.float32),
        "units": "1",
        "long_name": "Constant example field",
    }
}
dataset.to_netcdf("example.nc")
dataset.close()

Run this creation example in serial:

python create_example.py

The script writes example.nc with one timestep, one level and twelve cells. It assigns a full array and is intended for one process. For distributed array preparation see reading and creation.

2. Read and validate

from nes import open_netcdf

dataset = open_netcdf("example.nc")
dataset.keep_vars(["example"])
dataset.load()
assert dataset.get_totals()["example"] == 12.0
assert dataset.get_min("example") == 1.0
assert dataset.get_max("example") == 1.0
dataset.close()

The expected total is 12 and both extrema are 1.

nes check -i example.nc -l example
nes gridarea -f example.nc -o example_with_area.nc
nes diff -1 example.nc -2 example.nc -o example_difference.nc -l example

The checker should find no NaN or Inf; the difference field should contain zeros. Read example_difference.nc with the same Python workflow and check that both extrema are zero.

3. Explore further

Clone this wiki locally