arlmet.concat#

arlmet.concat(sources, destination, *, sort=True)[source]#

Concatenate multiple ARL files into a single ARL file.

Each input is appended to the output byte-for-byte, preserving every record (including diff records and checksums) exactly. The inputs are first scanned to ensure they share one grid and vertical axis and do not repeat valid times, since a concatenated ARL file must be a single coherent record stream.

Parameters:
  • sources (iterable of path-like) – Input ARL files to join. Must contain at least one path. A bare string or path is rejected — wrap a single file in a list.

  • destination (path-like) – Output ARL file path. Overwrites any existing file. Must not be one of sources.

  • sort (bool, default True) – Order the inputs by their earliest valid time before joining, so the output is chronological regardless of input order. When False, inputs are joined in the order given (like cat).

Returns:

The newly written file, opened in read mode. Close it when done (or use it as a context manager). Callers that only need the file on disk may ignore the return value.

Return type:

File

Raises:

ValueError – If sources is empty, if destination is also a source, if any source is empty, if the inputs disagree on grid or vertical axis, or if the same valid time appears in more than one input.

Examples

Join three 6-hourly HRRR files into one daily file:

>>> import arlmet
>>> arlmet.concat(
...     ["20240101_00_hrrr", "20240101_06_hrrr", "20240101_12_hrrr"],
...     "20240101_hrrr",
... )

Combine every 6-hourly file for one day discovered by glob (sort=True orders them by valid time, so glob order does not matter):

>>> import glob
>>> arlmet.concat(glob.glob("20240101_*_hrrr"), "20240101_hrrr")