def create_default_pystepsrc(
    pysteps_data_dir, config_dir=None, file_name="pystepsrc", dryrun=False
):
    """
    Create a default configuration file pointing to the pysteps data directory.

    If the configuration file already exists, it will backup the existing file by
    appending the extensions '.1', '.2', up to '.5.' to the filename.
    A maximum of 5 files are kept. .2, up to app.log.5.

    File rotation is implemented for the backup files.
    For example, if the default configuration filename is 'pystepsrc' and the files
    pystepsrc, pystepsrc.1, pystepsrc.2, etc. exist, they are renamed to respectively
    pystepsrc.1, pystepsrc.2, pystepsrc.2, etc. Finally, after the existing files are
    backed up, the new configuration file is written.

    Parameters
    ----------
    pysteps_data_dir: str
        Path to the directory with the pysteps data.
    config_dir: str
        Destination directory for the configuration file.
        Default values: $HOME/.pysteps (unix and Mac OS X)
        or $USERPROFILE/pysteps (windows).
        The directory is created if it does not exists.
    file_name: str
        Configuration file name. `pystepsrc` by default.
    dryrun: bool
        Do not create the parameter file, nor create backups of existing files.
        No changes are made in the file system. It just returns the file path.

    Returns
    -------
    dest_path: str
        Configuration file path.
    """

    pysteps_lib_root = os.path.dirname(_decode_filesystem_path(pysteps.__file__))

    # Load the library built-in configuration file
    with open(os.path.join(pysteps_lib_root, "pystepsrc"), "r") as f:
        rcparams_json = json.loads(jsmin(f.read()))

    for key, value in rcparams_json["data_sources"].items():
        value["root_path"] = os.path.abspath(
            os.path.join(pysteps_data_dir, value["root_path"])
        )

    if config_dir is None:
        home_dir = os.path.expanduser("~")
        if os.name == "nt":
            subdir = "pysteps"
        else:
            subdir = ".pysteps"
        config_dir = os.path.join(home_dir, subdir)

    dest_path = os.path.join(config_dir, file_name)

    if not dryrun:
        if not os.path.isdir(config_dir):
            os.makedirs(config_dir)

        # Backup existing configuration files if it exists and rotate previous backups
        if os.path.isfile(dest_path):
            RotatingFileHandler(dest_path, backupCount=6).doRollover()

        with open(dest_path, "w") as f:
            json.dump(rcparams_json, f, indent=4)

    return os.path.normpath(dest_path)
Create a default configuration file pointing to the pysteps data directory.

If the configuration file already exists, it will backup the existing file by
appending the extensions '.1', '.2', up to '.5.' to the filename.
A maximum of 5 files are kept. .2, up to app.log.5.

File rotation is implemented for the backup files.
For example, if the default configuration filename is 'pystepsrc' and the files
pystepsrc, pystepsrc.1, pystepsrc.2, etc. exist, they are renamed to respectively
pystepsrc.1, pystepsrc.2, pystepsrc.2, etc. Finally, after the existing files are
backed up, the new configuration file is written.

Parameters
----------
pysteps_data_dir: str
Path to the directory with the pysteps data.
config_dir: str
Destination directory for the configuration file.
Default values: $HOME/.pysteps (unix and Mac OS X)
or $USERPROFILE/pysteps (windows).
The directory is created if it does not exists.
file_name: str
Configuration file name. `pystepsrc` by default.
dryrun: bool
Do not create the parameter file, nor create backups of existing files.
No changes are made in the file system. It just returns the file path.

Returns
-------
dest_path: str
Configuration file path.
pysteps/datasets.py