def import_odim_hdf5(filename, qty="RATE", **kwargs):
    """
    Import a precipitation field (and optionally the quality field) from a
    HDF5 file conforming to the ODIM specification.
    **Important:** Currently, only the Pan-European (OPERA) and the
    Dipartimento della Protezione Civile (DPC) radar composites are correctly supported.
    Other ODIM-compliant files may not be read correctly.

    Parameters
    ----------
    filename: str
        Name of the file to import.
    qty: {'RATE', 'ACRR', 'DBZH'}
        The quantity to read from the file. The currently supported identitiers
        are: 'RATE'=instantaneous rain rate (mm/h), 'ACRR'=hourly rainfall
        accumulation (mm) and 'DBZH'=max-reflectivity (dBZ). The default value
        is 'RATE'.

    {extra_kwargs_doc}

    Returns
    -------
    out: tuple
        A three-element tuple containing the OPERA product for the requested
        quantity and the associated quality field and metadata. The quality
        field is read from the file if it contains a dataset whose quantity
        identifier is 'QIND'.
    """
    if not H5PY_IMPORTED:
        raise MissingOptionalDependency(
            "h5py package is required to import "
            "radar reflectivity composites using ODIM HDF5 specification "
            "but it is not installed"
        )

    if qty not in ["ACRR", "DBZH", "RATE"]:
        raise ValueError(
            "unknown quantity %s: the available options are 'ACRR', 'DBZH' and 'RATE'"
        )

    f = h5py.File(filename, "r")

    precip = None
    quality = None

    for dsg in f.items():
        if dsg[0].startswith("dataset"):
            what_grp_found = False
            # check if the "what" group is in the "dataset" group
            if "what" in list(dsg[1].keys()):
                if "quantity" in dsg[1]["what"].attrs.keys():
                    try:
                        qty_, gain, offset, nodata, undetect = (
                            _read_opera_hdf5_what_group(dsg[1]["what"])
                        )
                        what_grp_found = True
                    except KeyError:
                        pass

            for dg in dsg[1].items():
                if dg[0][0:4] == "data":
                    # check if the "what" group is in the "data" group
                    if "what" in list(dg[1].keys()):
                        (
                            qty_,
                            gain,
                            offset,
                            nodata,
                            undetect,
                        ) = _read_opera_hdf5_what_group(dg[1]["what"])
                    elif not what_grp_found:
                        raise DataModelError(
                            "Non ODIM compliant file: "
                            "no what group found from {} "
                            "or its subgroups".format(dg[0])
                        )

                    if qty_.decode() in [qty, "QIND"]:
                        arr = dg[1]["data"][...]
                        mask_n = arr == nodata
                        mask_u = arr == undetect
                        mask = np.logical_and(~mask_u, ~mask_n)

                        if qty_.decode() == qty:
                            precip = np.empty(arr.shape)
                            precip[mask] = arr[mask] * gain + offset
                            if qty != "DBZH":
                                precip[mask_u] = offset
                            else:
                                precip[mask_u] = -30.0
                            precip[mask_n] = np.nan
                        elif qty_.decode() == "QIND":
                            quality = np.empty(arr.shape, dtype=float)
                            quality[mask] = arr[mask]
                            quality[~mask] = np.nan
                    if quality is None:
                        for dgg in dg[
                            1
                        ].items():  # da qui  ----------------------------
                            if dgg[0][0:7] == "quality":
                                quality_keys = list(dgg[1].keys())
                                if "what" in quality_keys:
                                    (
                                        qty_,
                                        gain,
                                        offset,
                                        nodata,
                                        undetect,
                                    ) = _read_opera_hdf5_what_group(dgg[1]["what"])
                                if qty_.decode() == "QIND":
                                    arr = dgg[1]["data"][...]
                                    mask_n = arr == nodata
                                    mask_u = arr == undetect
                                    mask = np.logical_and(~mask_u, ~mask_n)
                                    quality = np.empty(arr.shape)  # , dtype=float)
                                    quality[mask] = arr[mask] * gain + offset
                                    quality[~mask] = (
                                        np.nan
                                    )  # a qui -----------------------------

    if precip is None:
        raise IOError("requested quantity %s not found" % qty)

    where = f["where"]
    if isinstance(where.attrs["projdef"], str):
        proj4str = where.attrs["projdef"]
    else:
        proj4str = where.attrs["projdef"].decode()
    pr = pyproj.Proj(proj4str)

    ll_lat = where.attrs["LL_lat"]
    ll_lon = where.attrs["LL_lon"]
    ur_lat = where.attrs["UR_lat"]
    ur_lon = where.attrs["UR_lon"]
    if (
        "LR_lat" in where.attrs.keys()
        and "LR_lon" in where.attrs.keys()
        and "UL_lat" in where.attrs.keys()
        and "UL_lon" in where.attrs.keys()
    ):
        lr_lat = float(where.attrs["LR_lat"])
        lr_lon = float(where.attrs["LR_lon"])
        ul_lat = float(where.attrs["UL_lat"])
        ul_lon = float(where.attrs["UL_lon"])
        full_cornerpts = True
    else:
        full_cornerpts = False

    ll_x, ll_y = pr(ll_lon, ll_lat)
    ur_x, ur_y = pr(ur_lon, ur_lat)

    if full_cornerpts:
        lr_x, lr_y = pr(lr_lon, lr_lat)
        ul_x, ul_y = pr(ul_lon, ul_lat)
        x1 = min(ll_x, ul_x)
        y1 = min(ll_y, lr_y)
        x2 = max(lr_x, ur_x)
        y2 = max(ul_y, ur_y)
    else:
        x1 = ll_x
        y1 = ll_y
        x2 = ur_x
        y2 = ur_y

    dataset1 = f["dataset1"]

    if "xscale" in where.attrs.keys() and "yscale" in where.attrs.keys():
        xpixelsize = where.attrs["xscale"]
        ypixelsize = where.attrs["yscale"]
    elif (
        "xscale" in dataset1["where"].attrs.keys()
        and "yscale" in dataset1["where"].attrs.keys()
    ):
        where = dataset1["where"]
        xpixelsize = where.attrs["xscale"]
        ypixelsize = where.attrs["yscale"]
    else:
        xpixelsize = None
        ypixelsize = None

    if qty == "ACRR":
        unit = "mm"
        transform = None
    elif qty == "DBZH":
        unit = "dBZ"
        transform = "dB"
    else:
        unit = "mm/h"
        transform = None

    metadata = {
        "projection": proj4str,
        "ll_lon": ll_lon,
        "ll_lat": ll_lat,
        "ur_lon": ur_lon,
        "ur_lat": ur_lat,
        "x1": x1,
        "y1": y1,
        "x2": x2,
        "y2": y2,
        "xpixelsize": xpixelsize,
        "ypixelsize": ypixelsize,
        "cartesian_unit": "m",
        "yorigin": "upper",
        "institution": "Odyssey datacentre",
        "accutime": 15.0,
        "unit": unit,
        "transform": transform,
        "zerovalue": np.nanmin(precip),
        "threshold": _get_threshold_value(precip),
    }

    metadata.update(kwargs)

    f.close()

    return precip, quality, metadata
Import a precipitation field (and optionally the quality field) from a
HDF5 file conforming to the ODIM specification.
**Important:** Currently, only the Pan-European (OPERA) and the
Dipartimento della Protezione Civile (DPC) radar composites are correctly supported.
Other ODIM-compliant files may not be read correctly.

Parameters
----------
filename: str
Name of the file to import.
qty: {'RATE', 'ACRR', 'DBZH'}
The quantity to read from the file. The currently supported identitiers
are: 'RATE'=instantaneous rain rate (mm/h), 'ACRR'=hourly rainfall
accumulation (mm) and 'DBZH'=max-reflectivity (dBZ). The default value
is 'RATE'.

{extra_kwargs_doc}

Returns
-------
out: tuple
A three-element tuple containing the OPERA product for the requested
quantity and the associated quality field and metadata. The quality
field is read from the file if it contains a dataset whose quantity
identifier is 'QIND'.
pysteps/io/importers.py