def export_forecast_dataset(field, exporter):
    """Write a forecast array into a file.

    If the exporter was initialized with n_ens_members>1, the written dataset
    has dimensions (n_ens_members,num_timesteps,shape[0],shape[1]), where shape
    refers to the shape of the two-dimensional forecast grids. Otherwise, the
    dimensions are (num_timesteps,shape[0],shape[1]). If the exporter was
    initialized with incremental!=None, the array is appended to the existing
    dataset either along the ensemble member or time axis.

    Parameters
    ----------
    exporter: dict
        An exporter object created with any initialization method implemented
        in :py:mod:`pysteps.io.exporters`.
    field: array_like
        The array to write. The required shape depends on the choice of the
        'incremental' parameter the exporter was initialized with:

        +-----------------+---------------------------------------------------+
        |    incremental  |                    required shape                 |
        +=================+===================================================+
        |    None         | (num_ens_members,num_timesteps,shape[0],shape[1]) |
        +-----------------+---------------------------------------------------+
        |    'timestep'   | (num_ens_members,shape[0],shape[1])               |
        +-----------------+---------------------------------------------------+
        |    'member'     | (num_timesteps,shape[0],shape[1])                 |
        +-----------------+---------------------------------------------------+

        If the exporter was initialized with num_ens_members=1,
        the num_ens_members dimension is dropped.
    """

    if exporter["method"] == "netcdf" and not NETCDF4_IMPORTED:
        raise MissingOptionalDependency(
            "netCDF4 package is required for netcdf "
            "exporters but it is not installed"
        )

    if exporter["incremental"] is None:
        if exporter["num_ens_members"] > 1:
            shp = (
                exporter["num_ens_members"],
                exporter["num_timesteps"],
                exporter["shape"][0],
                exporter["shape"][1],
            )
        else:
            shp = (
                exporter["num_timesteps"],
                exporter["shape"][0],
                exporter["shape"][1],
            )
        if field.shape != shp:
            raise ValueError(
                "field has invalid shape: %s != %s" % (str(field.shape), str(shp))
            )
    elif exporter["incremental"] == "timestep":
        if exporter["num_ens_members"] > 1:
            shp = (
                exporter["num_ens_members"],
                exporter["shape"][0],
                exporter["shape"][1],
            )
        else:
            shp = exporter["shape"]
        if field.shape != shp:
            raise ValueError(
                "field has invalid shape: %s != %s" % (str(field.shape), str(shp))
            )
    elif exporter["incremental"] == "member":
        shp = (exporter["num_timesteps"], exporter["shape"][0], exporter["shape"][1])
        if field.shape != shp:
            raise ValueError(
                "field has invalid shape: %s != %s" % (str(field.shape), str(shp))
            )

    if exporter["method"] == "geotiff":
        _export_geotiff(field, exporter)
    elif exporter["method"] == "netcdf":
        _export_netcdf(field, exporter)
    elif exporter["method"] == "kineros":
        _export_kineros(field, exporter)
    else:
        raise ValueError("unknown exporter method %s" % exporter["method"])
Write a forecast array into a file.

If the exporter was initialized with n_ens_members>1, the written dataset
has dimensions (n_ens_members,num_timesteps,shape[0],shape[1]), where shape
refers to the shape of the two-dimensional forecast grids. Otherwise, the
dimensions are (num_timesteps,shape[0],shape[1]). If the exporter was
initialized with incremental!=None, the array is appended to the existing
dataset either along the ensemble member or time axis.

Parameters
----------
exporter: dict
An exporter object created with any initialization method implemented
in :py:mod:`pysteps.io.exporters`.
field: array_like
The array to write. The required shape depends on the choice of the
'incremental' parameter the exporter was initialized with:

+-----------------+---------------------------------------------------+
|    incremental  |                    required shape                 |
+=================+===================================================+
|    None         | (num_ens_members,num_timesteps,shape[0],shape[1]) |
+-----------------+---------------------------------------------------+
|    'timestep'   | (num_ens_members,shape[0],shape[1])               |
+-----------------+---------------------------------------------------+
|    'member'     | (num_timesteps,shape[0],shape[1])                 |
+-----------------+---------------------------------------------------+

If the exporter was initialized with num_ens_members=1,
the num_ens_members dimension is dropped.
pysteps/io/exporters.py