credit.datasets.mrms_download
=============================

.. py:module:: credit.datasets.mrms_download

.. autoapi-nested-parse::

   mrms_download.py
   ----------------
   Standalone utility for downloading MRMS data from AWS S3 to local disk.

   Downloaded files follow the same ``filename_time_format`` strftime convention
   used by ``MRMSDataset`` in local mode, so files are immediately usable without
   any renaming.

   Usage::

       python -m credit.datasets.mrms_download --config config/my_conf.yaml

   Or programmatically::

       from credit.datasets.mrms_download import download_mrms
       download_mrms(config, output_format="netcdf")

   Config section used (``data.source.MRMS``)::

       data:
         source:
           MRMS:
             mode: "local"             # output mode after download
             region: "CONUS"
             variables:
               prognostic:
                 vars_2D:
                   - "MultiSensor_QPE_01H_Pass2_00.00"
                   - "MultiSensor_QPE_06H_Pass2_00.00"
                 path: "/data/mrms_*.nc"          # determines base_path + format
                 filename_time_format: "%Y%m%d-%H%M%S"
             extent: [-130, -60, 20, 55]          # optional

         start_datetime: "2024-06-01"
         end_datetime:   "2024-07-01"
         timestep:       "6h"
         forecast_len:   0

   Output files are written to the directory of ``path``, with names derived
   from the ``filename_time_format``.  For example, with
   ``filename_time_format: "%Y%m%d-%H%M%S"`` and ``path: "/data/mrms_*.nc"``
   the file ``/data/mrms_20240601-060000.nc`` is created for the 06:00 UTC step.



Attributes
----------

.. autoapisummary::

   credit.datasets.mrms_download.logger
   credit.datasets.mrms_download._GRIB_TABLE_URL
   credit.datasets.mrms_download.parser


Functions
---------

.. autoapisummary::

   credit.datasets.mrms_download.download_mrms


Module Contents
---------------

.. py:data:: logger

.. py:data:: _GRIB_TABLE_URL
   :value: 'https://raw.githubusercontent.com/NOAA-National-Severe-Storms-Laboratory/mrms-support/refs/heads...


.. py:function:: download_mrms(config: dict, output_format: str = 'netcdf', grib_table_url: str = _GRIB_TABLE_URL) -> None

   Download MRMS data from AWS S3 to local disk.

   Iterates over all timestamps defined by the top-level data config and
   writes one output file per timestamp.  Files are named using
   ``filename_time_format`` so they are immediately loadable by
   ``MRMSDataset`` in ``mode: "local"``.

   :param config: Top-level ``data`` config dict (same object passed to
                  ``MRMSDataset``).
   :param output_format: ``"netcdf"`` (default) or ``"zarr"``.
   :param grib_table_url: URL to the MRMS GRIB2 parameter table CSV used for
                          attaching variable metadata to output files.

   :raises ValueError: If *output_format* is not ``"netcdf"`` or ``"zarr"``.
   :raises KeyError: If the config is missing required fields.


.. py:data:: parser

