Skip to content

Output_Formats

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

Output formats and incremental writing

After loading or assigning data, write with dataset.to_netcdf("output.nc").

Table of Contents


NetCDF output

The nc_type argument selects a writer:

Value Output
NES, DEFAULT Native NES NetCDF
CAMS_RA CAMS reanalysis format
MONARCH MONARCH format and writer-specific unit conversions
MOCAGE MOCAGE format and writer-specific unit conversions
CHIMERE CHIMERE format and writer-specific unit conversions
WRF_CHEM WRF-Chem format and writer-specific unit conversions
CMAQ CMAQ format and writer-specific unit conversions

These are model-specific writers, not arbitrary format conversions. Input variables, metadata, units and grid must satisfy the selected model's requirements. Start from a compatible dataset; dataset.to_netcdf("monarch.nc", nc_type="MONARCH") selects the MONARCH writer.

compression_level ranges from 0 to 9 (default 0). serial=True gathers distributed data for writing on the master rank. chunking=True is available for non-serial writes and cannot be combined with balanced decomposition.

For the native writer, parallel_io_mode="independent" (default) uses independent variable writes and a fixed time dimension. parallel_io_mode="collective" uses collective writes and an unlimited time dimension. All participating ranks must follow the same collective write sequence. Model writers have their own output rules.

Incremental writing

Use keep_open=True, populate the timestep data, call append_time_step_data(i_time) and finally close(). See the write-by-timestep tutorial for data preparation.

# dataset already has the time axis, metadata and variables prepared
# Keep the file open for subsequent timestep writes.
dataset.to_netcdf("output.nc", keep_open=True, parallel_io_mode="independent")
timing = dataset.append_time_step_data(0, return_timing=True)
print(timing)
dataset.close()

return_timing=False is the default. With True, the returned diagnostics report unit conversion, communication, NetCDF writing, unaccounted write time and total elapsed time. out_format defaults to DEFAULT and selects timestep unit conversion where supported. A fixed time dimension must include the intended timestep indices before writing.

GRIB2

Latitude-longitude datasets implement to_grib2(path, grib_keys, grib_template_path, lat_flip=False, info=False). Supply an existing GRIB template and ecCodes keys appropriate to the variables. Load data before export. lat_flip controls reversal of latitude and data.

Rotated (including nested), LCC, Mercator and point datasets raise NotImplementedError for this export. Regrid to a supported latitude-longitude grid first if GRIB2 is required.

See MBTiles and geometry operations for other output types.

Clone this wiki locally