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
levelcoordinate
Upper-air levels are written in
levelcoordinate order and renumbered1..N(surface is 0), so a Dataset holding a subset of a file’s levels (e.g. fromopen_dataset(levels=...)ords.sel(level=...)) is written as a compact file, likearlmet.extract_subset()does. A slice that is entirely NaN is taken to be absent from the file (asopen_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
dswas opened from.vertical_axis (VerticalAxis, optional) – Vertical axis to write. By default it is rebuilt from the Dataset’s
levelcoordinates. Required for surface-only Datasets; otherwise it must have one level perlevelcoordinate 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_objis the filedswas opened from.
Notes
The file is written to a temporary file next to
filename_or_objand renamed into place once complete, so an interrupted write never leaves a truncated file under the final name.