def proj4_to_cartopy(proj4str):
    """
    Convert a PROJ.4 projection string into a Cartopy coordinate reference
    system (crs) object.

    Parameters
    ----------
    proj4str: str
        A PROJ.4-compatible projection string.

    Returns
    -------
    out: object
        Instance of a crs class defined in cartopy.crs.
    """
    if not CARTOPY_IMPORTED:
        raise MissingOptionalDependency(
            "cartopy package is required for proj4_to_cartopy function "
            "utility but it is not installed"
        )

    if not PYPROJ_IMPORTED:
        raise MissingOptionalDependency(
            "pyproj package is required for proj4_to_cartopy function utility "
            "but it is not installed"
        )

    proj = pyproj.Proj(proj4str)

    try:
        # pyproj >= 2.2.0
        is_geographic = proj.crs.is_geographic
    except AttributeError:
        # pyproj < 2.2.0
        is_geographic = proj.is_latlong()

    if is_geographic:
        return ccrs.PlateCarree()

    proj_dict = parse_proj4_string(proj4str)

    cartopy_crs_kwargs = dict()
    globe_kwargs = dict()
    cartopy_crs = None
    globe = None

    for key, value in proj_dict.items():
        if key == "proj":
            if value in PYPROJ_PROJECTION_TO_CARTOPY:
                cartopy_crs = PYPROJ_PROJECTION_TO_CARTOPY[value]
            else:
                raise ValueError(f"Unsupported projection: {value}")

        if key in PYPROJ_PROJ_KWRDS_TO_CARTOPY:
            cartopy_crs_kwargs[PYPROJ_PROJ_KWRDS_TO_CARTOPY[key]] = value

        if key in PYPROJ_GLOB_KWRDS_TO_CARTOPY:
            globe_kwargs[PYPROJ_GLOB_KWRDS_TO_CARTOPY[key]] = value

    # issubset: <=
    if {"lat_1", "lat_2"} <= proj_dict.keys():
        cartopy_crs_kwargs["standard_parallels"] = (
            proj_dict["lat_1"],
            proj_dict["lat_2"],
        )
    if "R" in proj_dict.keys():
        globe_kwargs["semimajor_axis"] = proj_dict["R"]
        globe_kwargs["semiminor_axis"] = proj_dict["R"]

    if globe_kwargs:
        globe = ccrs.Globe(**globe_kwargs)

    if isinstance(cartopy_crs, ccrs.Mercator):
        cartopy_crs_kwargs.pop("false_easting", None)
        cartopy_crs_kwargs.pop("false_northing", None)

    return cartopy_crs(globe=globe, **cartopy_crs_kwargs)
Convert a PROJ.4 projection string into a Cartopy coordinate reference
system (crs) object.

Parameters
----------
proj4str: str
A PROJ.4-compatible projection string.

Returns
-------
out: object
Instance of a crs class defined in cartopy.crs.
pysteps/visualization/utils.py