def postprocess_import(fillna=np.nan, dtype="double"):
    """
    Postprocess the imported precipitation data.
    Operations:
    - Allow type casting (dtype keyword)
    - Set invalid or missing data to predefined value (fillna keyword)
    This decorator replaces the text "{extra_kwargs}" in the function's
    docstring with the documentation of the keywords used in the postprocessing.
    The additional docstrings are added as "Other Parameters" in the importer function.

    Parameters
    ----------
    dtype: str
        Default data type for precipitation. Double precision by default.
    fillna: float or np.nan
        Default value used to represent the missing data ("No Coverage").
        By default, np.nan is used.
        If the importer returns a MaskedArray, all the masked values are set to the
        fillna value. If a numpy array is returned, all the invalid values (nan and inf)
        are set to the fillna value.

    """

    def _postprocess_import(importer):
        @wraps(importer)
        def _import_with_postprocessing(*args, **kwargs):
            precip, *other_args = importer(*args, **kwargs)

            _dtype = kwargs.get("dtype", dtype)

            accepted_precisions = ["float32", "float64", "single", "double"]
            if _dtype not in accepted_precisions:
                raise ValueError(
                    "The selected precision does not correspond to a valid value."
                    "The accepted values are: " + str(accepted_precisions)
                )

            if isinstance(precip, np.ma.MaskedArray):
                invalid_mask = np.ma.getmaskarray(precip)
                precip.data[invalid_mask] = fillna
            else:
                # If plain numpy arrays are used, the importers should indicate
                # the invalid values with np.nan.
                _fillna = kwargs.get("fillna", fillna)
                if _fillna is not np.nan:
                    mask = ~np.isfinite(precip)
                    precip[mask] = _fillna

            return (precip.astype(_dtype),) + tuple(other_args)

        extra_kwargs_doc = """
            Other Parameters
            ----------------
            dtype: str
                Data-type to which the array is cast.
                Valid values:  "float32", "float64", "single", and "double".
            fillna: float or np.nan
                Value used to represent the missing data ("No Coverage").
                By default, np.nan is used.
            """

        _add_extra_kwrds_to_docstrings(_import_with_postprocessing, extra_kwargs_doc)

        return _import_with_postprocessing

    return _postprocess_import
Postprocess the imported precipitation data.
Operations:
- Allow type casting (dtype keyword)
- Set invalid or missing data to predefined value (fillna keyword)
This decorator replaces the text "{extra_kwargs}" in the function's
docstring with the documentation of the keywords used in the postprocessing.
The additional docstrings are added as "Other Parameters" in the importer function.

Parameters
----------
dtype: str
Default data type for precipitation. Double precision by default.
fillna: float or np.nan
Default value used to represent the missing data ("No Coverage").
By default, np.nan is used.
If the importer returns a MaskedArray, all the masked values are set to the
fillna value. If a numpy array is returned, all the invalid values (nan and inf)
are set to the fillna value.
pysteps/decorators.py