def import_netcdf_pysteps(filename, onerror="warn", **kwargs):
    """
    Read a nowcast or an ensemble of nowcasts from a NetCDF file conforming
    to the CF 1.7 specification.

    If an error occurs during the import, the corresponding error message
    is shown, and ( None, None ) is returned.

    Parameters
    ----------
    filename: str
        Name of the file to import.
    onerror: str
        Define the behavior if an exception is raised during the import.
        - "warn": Print an error message and return (None, None)
        - "raise": Raise an exception

    {extra_kwargs_doc}

    Returns
    -------
    precipitation: 2D array, float32
        Precipitation field in mm/h. The dimensions are [latitude, longitude].
        The first grid point (0,0) corresponds to the upper left corner of the
        domain, while (last i, last j) denote the lower right corner.
    metadata: dict
        Associated metadata (pixel sizes, map projections, etc.).
    """
    if not NETCDF4_IMPORTED:
        raise MissingOptionalDependency(
            "netCDF4 package is required to import pysteps netcdf "
            "nowcasts but it is not installed"
        )

    onerror = onerror.lower()
    if onerror not in ["warn", "raise"]:
        raise ValueError("'onerror' keyword must be 'warn' or 'raise'.")

    try:
        ds = netCDF4.Dataset(filename, "r")

        var_names = list(ds.variables.keys())

        if "precip_intensity" in var_names:
            precip = ds.variables["precip_intensity"]
            unit = "mm/h"
            accutime = None
            transform = None
        elif "precip_accum" in var_names:
            precip = ds.variables["precip_accum"]
            unit = "mm"
            accutime = None
            transform = None
        elif "hourly_precip_accum" in var_names:
            precip = ds.variables["hourly_precip_accum"]
            unit = "mm"
            accutime = 60.0
            transform = None
        elif "reflectivity" in var_names:
            precip = ds.variables["reflectivity"]
            unit = "dBZ"
            accutime = None
            transform = "dB"
        else:
            raise DataModelError(
                "Non CF compilant file: "
                "the netCDF file does not contain any "
                "supported variable name.\n"
                "Supported names: 'precip_intensity', 'hourly_precip_accum', "
                "or 'reflectivity'\n"
                "file: " + filename
            )

        precip = precip[...].squeeze().astype(float)

        if isinstance(precip, np.ma.MaskedArray):
            invalid_mask = np.ma.getmaskarray(precip)
            precip = precip.data
            precip[invalid_mask] = np.nan

        metadata = {}

        time_var = ds.variables["time"]
        leadtimes = time_var[:] / 60.0  # minutes leadtime
        metadata["leadtimes"] = leadtimes
        timestamps = netCDF4.num2date(time_var[:], time_var.units)
        metadata["timestamps"] = timestamps

        if "polar_stereographic" in var_names:
            vn = "polar_stereographic"

            attr_dict = {}
            for attr_name in ds.variables[vn].ncattrs():
                attr_dict[attr_name] = ds[vn].getncattr(attr_name)

            proj_str = _convert_grid_mapping_to_proj4(attr_dict)
            metadata["projection"] = proj_str

        # geodata
        metadata["xpixelsize"] = abs(ds.variables["x"][1] - ds.variables["x"][0])
        metadata["ypixelsize"] = abs(ds.variables["y"][1] - ds.variables["y"][0])

        xmin = np.min(ds.variables["x"]) - 0.5 * metadata["xpixelsize"]
        xmax = np.max(ds.variables["x"]) + 0.5 * metadata["xpixelsize"]
        ymin = np.min(ds.variables["y"]) - 0.5 * metadata["ypixelsize"]
        ymax = np.max(ds.variables["y"]) + 0.5 * metadata["ypixelsize"]

        # TODO: this is only a quick solution
        metadata["x1"] = xmin
        metadata["y1"] = ymin
        metadata["x2"] = xmax
        metadata["y2"] = ymax

        metadata["yorigin"] = "upper"  # TODO: check this

        # TODO: Read the metadata to the dictionary.
        if (accutime is None) and (leadtimes.size > 1):
            accutime = leadtimes[1] - leadtimes[0]
        metadata["accutime"] = accutime
        metadata["unit"] = unit
        metadata["transform"] = transform
        metadata["zerovalue"] = np.nanmin(precip)
        if metadata["zerovalue"] == np.nanmax(precip):
            metadata["threshold"] = metadata["zerovalue"]
        else:
            metadata["threshold"] = np.nanmin(precip[precip > metadata["zerovalue"]])

        ds.close()

        return precip, metadata
    except Exception as er:
        if onerror == "warn":
            print("There was an error processing the file", er)
            return None, None
        else:
            raise er
Read a nowcast or an ensemble of nowcasts from a NetCDF file conforming
to the CF 1.7 specification.

If an error occurs during the import, the corresponding error message
is shown, and ( None, None ) is returned.

Parameters
----------
filename: str
Name of the file to import.
onerror: str
Define the behavior if an exception is raised during the import.
- "warn": Print an error message and return (None, None)
- "raise": Raise an exception

{extra_kwargs_doc}

Returns
-------
precipitation: 2D array, float32
Precipitation field in mm/h. The dimensions are [latitude, longitude].
The first grid point (0,0) corresponds to the upper left corner of the
domain, while (last i, last j) denote the lower right corner.
metadata: dict
Associated metadata (pixel sizes, map projections, etc.).
pysteps/io/nowcast_importers.py