arlmet.write_dataset#

arlmet.write_dataset(ds, filename_or_obj, *, vertical_axis=None)[source]#

Write a simple flat Dataset representation to an ARL file.

This writer supports the common-case Dataset contract returned by open_dataset():

  • surface variables use dims (time, y, x) or (time, lat, lon)

  • upper-air variables use dims (time, level, y, x) or (time, level, lat, lon)

  • all upper-air variables share the same level coordinate

Upper-air levels are written in level coordinate order and renumbered 1..N (surface is 0), so a Dataset holding a subset of a file’s levels (e.g. from open_dataset(levels=...) or ds.sel(level=...)) is written as a compact file, like arlmet.extract_subset() does. A slice that is entirely NaN is taken to be absent from the file (as open_dataset() represents it) and no record is written for it.

Per-variable forecast heterogeneity is intentionally not represented in the flat Dataset API. forecast_hour(time) supplies only the ARL index-record forecast written for each time step.

Parameters:
  • ds (xarray.Dataset) – Dataset in the layout returned by open_dataset().

  • filename_or_obj (path-like) – Output ARL file path. Overwrites any existing file, but must not be the file ds was opened from.

  • vertical_axis (VerticalAxis, optional) – Vertical axis to write. By default it is rebuilt from the Dataset’s level coordinates. Required for surface-only Datasets; otherwise it must have one level per level coordinate value plus the surface.

Return type:

None

Raises:

ValueError – If the Dataset does not match the layout above, a slice is partly NaN or non-finite, or filename_or_obj is the file ds was opened from.

Notes

The file is written to a temporary file next to filename_or_obj and renamed into place once complete, so an interrupted write never leaves a truncated file under the final name.