Metadata-Version: 2.4
Name: pysteps-nwp-importers
Version: 2.0.0
Summary: Pysteps plugin to import a variety of NWP rainfall forecasts
Keywords: pysteps_nwp_importers,pysteps,plugin,importer
Author: pySTEPS developers
License-Expression: BSD-3-Clause
License-File: LICENSE
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Dist: netcdf4
Requires-Dist: numpy
Requires-Dist: pyproj
Requires-Dist: pysteps>=2.0.0rc2
Requires-Dist: xarray>=2025.7.1
Requires-Dist: pygrib ; sys_platform != 'win32' and extra == 'pygrib'
Requires-Python: >=3.11.5
Provides-Extra: pygrib
Description-Content-Type: text/x-rst

pysteps-nwp-importers
=====================

Pysteps plugin to import a variety of NWP rainfall forecasts. This plugin was created for pysteps 1.x with Cookiecutter, and has since been converted to the xarray data model of pysteps 2.x. It makes the NWP importers findable for the Pysteps importer functionality after installation.


License
=======
* BSD license


Documentation
=============

NWP rainfall forecast importer using pysteps utilities. This plugin currently provides importers for:

* KNMI HARMONIE NWP forecasts
* BoM NWP forecasts
* RMI NWP forecasts
* DWD NWP forecasts

The importers follow the xarray-based data model of pysteps v2 (see
``pysteps.io.importers``): each importer returns an ``xarray.Dataset`` instead
of the ``(precip, quality, metadata)`` tuple of pysteps v1. The metadata is
stored in the dataset: the projection and institution in its attributes, the
unit, accumulation time, threshold and zero value in the attributes of the
precipitation variable, and the grid and valid times in its coordinates.

Once the plugin is installed, the importers are available through the pysteps
interface::

    from pysteps import io

    importer = io.get_method("bom_nwp", "importer")
    nwp_dataset = importer(filename)
    precip_var = nwp_dataset.attrs["precip_var"]
    nwp_dataset[precip_var]  # dimensions (time, y, x)

The DWD ICON-D2-RUC importer returns the rainfall on the unstructured ICON grid,
with dimensions (ens_number, time, cell). Use ``unstructured2regular`` to
reproject it onto the grid of another pysteps dataset, such as a radar
composite::

    from pysteps_nwp_importers.importer_dwd_nwp import unstructured2regular

    importer = io.get_method("dwd_nwp", "importer")
    nwp_dataset = importer(filename, varname="PR_GSP", grid_file_path=grid_file)
    nwp_dataset = unstructured2regular(nwp_dataset, radar_dataset)
    # dimensions (ens_number, time, y, x), on the grid of radar_dataset

``pysteps.blending.steps.forecast`` expects the NWP dataset to have an
``ens_number`` dimension. For a deterministic NWP forecast, add it with
``nwp_dataset.expand_dims(ens_number=[1])``.


Installation
============

The plugin requires pysteps 2.0 (2.0.0rc3 or later) and is packaged and managed with uv_.

To add the latest development version of pysteps_nwp_importers to a uv project,
run in a terminal::

    uv add pysteps-nwp-importers

or, to install it into an existing environment without modifying a project::

    uv pip install pysteps-nwp-importers

The DWD importer also needs pygrib, which is an optional dependency, installed
with the ``pygrib`` extra::

    uv add "pysteps-nwp-importers[pygrib]"

or, with ``uv pip``::

    uv pip install "pysteps-nwp-importers[pygrib]"

pygrib has no Windows wheels on PyPI, so on Windows the ``pygrib`` extra installs
nothing; the other importers work without it.

Test the plugin
===============

This plugin comes with a tester, which can also be used to test whether the plugin is correctly hooked up to pysteps.

In a clone of this repository, install the plugin with its dependencies (including
the ``pygrib`` extra and the ``dev`` dependency group) and run the tests with::

    uv sync --all-extras
    uv run pytest -v --tb=line

On Windows, pygrib is not installed and the DWD tests are skipped.

The tests download their data from pysteps-data on the first run.

.. _uv: https://docs.astral.sh/uv/

Credits
=======

This package was created with Cookiecutter_ and the `cookiecutter-pysteps-plugin`_ project template.
The `cookiecutter-pysteps-plugin`_ template was adapted from the cookiecutter-pypackage_
template.

.. _cookiecutter-pypackage: https://github.com/audreyfeldroy/cookiecutter-pypackage
.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _`cookiecutter-pysteps-plugin`: https://github.com/pysteps/cookiecutter-pysteps-plugin
