arlmet.packing.pack#

arlmet.packing.pack(unpacked)[source]#

Pack a 2D field using the ARL differential byte encoding.

This is the inverse of unpack() and a translation of the HYSPLIT PAKOUT routine, in single precision as PAKOUT is, so it gives the same bytes, exponent, precision and initial value.

Parameters:

unpacked (NDArray[Any]) – The 2D numpy array of shape (ny, nx) to be packed; it is packed as float32.

Returns:

Tuple of (packed, precision, exponent, initial_value). packed is the byte payload, precision and exponent are the ARL packing parameters, and initial_value is the value at the first grid cell.

Return type:

tuple[NDArray[ubyte], float, int, float]

Raises:

ValueError – If the field is not 2D, is empty, or holds NaN or infinite values.