Source code for pycif.plugins.datastreams.fluxes.lmdz_bin.write
import numpy as np
import xarray
[docs]
def write(self, name, flx_file, flx, mode="a", **kwargs):
"""Write flux to an LMDZ-DISPERSION compatible Fortran binary file.
Extracts the ``"fwd"`` and ``"tl"`` (tangent-linear) fields from `flx`,
transposes them to the LMDZ physical vectorial grid layout, and dumps
the interleaved forward/tangent-linear values as raw binary to
`flx_file`.
Args:
self (Fluxes): the Fluxes plugin
name: Unused, kept for interface consistency with other flux
plugins.
flx_file (str): the file where to write fluxes
flx (xarray.Dataset): fluxes data to write, with ``"fwd"`` and
``"tl"`` data variables
mode (str): Unused, kept for interface consistency; the file is
always (over)written.
"""
flx_fwd = flx["fwd"].values[:, 0]
flx_tl = flx["tl"].values[:, 0]
np.transpose([flx_fwd, flx_tl], axes=(0, 3, 2, 1)).T.tofile(flx_file)