def download_mrms_data(dir_path, initial_date, final_date, timestep=2, nodelay=False):
    """
    Download a small dataset with 6 hours of the NSSL's Multi-Radar/Multi-Sensor
    System ([MRMS](https://www.nssl.noaa.gov/projects/mrms/)) precipitation
    product (grib format).

    All the available files in the archive in the indicated time period
    (`initial_date` to `final_date`) are downloaded.
    By default, the timestep between files downloaded is 2 min.
    If the `timestep` is exactly divisible by 2 min, the immediately lower
    multiple is used. For example, if  `timestep=5min`, the value is lowered to
    4 min.

    Note
    ----
    To reduce the load on the archive's server, an internal delay of 5 seconds
    every 30 files downloaded is implemented.
    This delay can be disabled by setting `nodelay=True`.


    Parameters
    ----------
    dir_path: str
        Path to directory where the MRMS data is be placed.
        If None, the default location defined in the pystepsrc file is used.
        The files are archived following the folder structure defined in
        the pystepsrc file.
        If the directory exists existing MRMS files may be overwritten.
    initial_date: datetime
        Beginning of the date period.
    final_date: datetime
        End of the date period.
    timestep: int or timedelta
        Timestep between downloaded files in minutes.
    nodelay: bool
        Do not implement a 5-seconds delay every 30 files downloaded.
    """

    if dir_path is None:
        data_source = pysteps.rcparams.data_sources["mrms"]
        dir_path = data_source["root_path"]

    if not isinstance(timestep, (int, timedelta)):
        raise TypeError(
            "'timestep' must be an integer or a timedelta object."
            f"Received: {type(timestep)}"
        )

    if isinstance(timestep, int):
        timestep = timedelta(seconds=timestep * 60)

    if timestep.total_seconds() < 120:
        raise ValueError(
            "The time step should be greater than 2 minutes."
            f"Received: {timestep.total_seconds()}"
        )

    _remainder = timestep % timedelta(seconds=120)
    timestep -= _remainder

    if not os.path.isdir(dir_path):
        os.makedirs(dir_path)

    if nodelay:

        def delay(_counter):
            return 0

    else:

        def delay(_counter):
            if _counter >= 30:
                _counter = 0
                time.sleep(5)
            return _counter

    archive_url = "https://mtarchive.geol.iastate.edu"
    print(f"Downloading MRMS data from {archive_url}")

    current_date = initial_date

    counter = 0
    while current_date <= final_date:
        counter = delay(counter)

        sub_dir = os.path.join(dir_path, datetime.strftime(current_date, "%Y/%m/%d"))

        if not os.path.isdir(sub_dir):
            os.makedirs(sub_dir)

        # Generate files URL from https://mtarchive.geol.iastate.edu
        dest_file_name = datetime.strftime(
            current_date, "PrecipRate_00.00_%Y%m%d-%H%M%S.grib2"
        )

        rel_url_fmt = (
            "/%Y/%m/%d"
            "/mrms/ncep/PrecipRate"
            "/PrecipRate_00.00_%Y%m%d-%H%M%S.grib2.gz"
        )

        file_url = archive_url + datetime.strftime(current_date, rel_url_fmt)

        try:
            print(f"Downloading {file_url} ", end="")
            tmp_file_name, _ = request.urlretrieve(file_url)
            print("DONE")

            dest_file_path = os.path.join(sub_dir, dest_file_name)

            # Uncompress the data
            with gzip.open(tmp_file_name, "rb") as f_in:
                with open(dest_file_path, "wb") as f_out:
                    shutil.copyfileobj(f_in, f_out)

            current_date = current_date + timedelta(seconds=60 * 2)
            counter += 1

        except HTTPError as err:
            print(err)
Download a small dataset with 6 hours of the NSSL's Multi-Radar/Multi-Sensor
System ([MRMS](https://www.nssl.noaa.gov/projects/mrms/)) precipitation
product (grib format).

All the available files in the archive in the indicated time period
(`initial_date` to `final_date`) are downloaded.
By default, the timestep between files downloaded is 2 min.
If the `timestep` is exactly divisible by 2 min, the immediately lower
multiple is used. For example, if  `timestep=5min`, the value is lowered to
4 min.

Note
----
To reduce the load on the archive's server, an internal delay of 5 seconds
every 30 files downloaded is implemented.
This delay can be disabled by setting `nodelay=True`.


Parameters
----------
dir_path: str
Path to directory where the MRMS data is be placed.
If None, the default location defined in the pystepsrc file is used.
The files are archived following the folder structure defined in
the pystepsrc file.
If the directory exists existing MRMS files may be overwritten.
initial_date: datetime
Beginning of the date period.
final_date: datetime
End of the date period.
timestep: int or timedelta
Timestep between downloaded files in minutes.
nodelay: bool
Do not implement a 5-seconds delay every 30 files downloaded.
pysteps/datasets.py