https://github.com/blaylockbk/herbie-plugin-tutorial

A demonstration of writing a custom model template plugin for Herbie

https://github.com/blaylockbk/herbie-plugin-tutorial

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (13.7%) to scientific vocabulary

Keywords

herbie herbie-data
Last synced: 10 months ago · JSON representation

Repository

A demonstration of writing a custom model template plugin for Herbie

Basic Info
Statistics
  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Topics
herbie herbie-data
Created about 1 year ago · Last pushed about 1 year ago
Metadata Files
Readme License

README.md

# Herbie Plugin Tutorial

This tutorial shows how to write a plugin for Herbie to add custom model templates—like giving Herbie a new set of tires.

You might need your own model template when:

  • You have local GRIB2 files (e.g., WRF/MPAS output) you'd like to access with Herbie.
  • You have access to GRIB2 data on a private network.
  • You want to override behavior of an existing model temple.
  • You want to iterate on a new model template before contributing upstream.

What is a Herbie model template?

A model template in Herbie is a Python class that defines where Herbie looks for weather model datasets. Herbie comes with a bunch of model templates you can look at for reference. When you import Herbie, it loads its model templates, and then Herbie looks for any templates from installed plugins.

Project structure

Here's what your plugin project should look like:

herbie-plugin-tutorial/ ├── pyproject.toml └── src/ └── herbie_plugin_tutorial/ └── __init__.py # contains your model templates

Create the plugin project

I used uv to create this example plugin:

bash uv init --lib herbie-plugin-tutorial --python 3.10 cd herbie-plugin-tutorial uv add herbie-data

  • I set --python 3.10 because that is Herbie's minimum version
  • Add herbie-data as a dependency, because what good is a plugin without the main package.

To register your plugin with Herbie, add the following to your pyproject.toml:

toml [project.entry-points."herbie.plugins"] hrrr_analysis = "herbie_plugin_tutorial:hrrr_analysis" bmw = "herbie_plugin_tutorial:bmw"

Making a custom model template

Your model templates live in your plugin’s __init__.py file.

Model templates are a bit of a craft due to some historical quirks, a few odd conventions (Herbie's grown over time!), and support for a lot of edge cases. Still, the basic structure is simple.

Take a look at this plugin's __init__.py, which includes two example templates:

  1. hrrr_analysis — A custom template for the HRRR model that only locates analysis fields from AWS.
  2. bmw — Local GRIB2 files output from a fictional dataset BMW "Brian's Model of Weather"

[!TIP]

  1. Class names must be lowercase! Herbie lowercases the model= input, so model='HRRR' becomes model='hrrr'.

  2. Set self.DESCRIPTION and self.DETAILS for helpful metadata.

  3. self.PRODUCTS must have at least one entry. If the user doesn't provide a product=, Herbie uses the first one by default.

  4. self.SOURCES is a dictionary of key-value pairs. Herbie will try each one in order until it finds a valid file. Prefix a key with local if the file is on disk instead of on a remote server.

  5. self.LOCALFILE is how you specify what the file name will be when it is downloaded. Setting to f"{self.get_remoteFileName}" simply says to keep the original name of the file.

Look at existing model templates for more examples.

Use your Herbie plugin

Install the plugin pip install -e . in your environment to use your custom templates.

Let's walk through using this plugin in a new project using uv.

bash uv init new_project cd new_project uv add herbie-data --extra extras uv add --editable ../herbie-plugin-tutorial

  • I used --editable so I could debug the plugin if needed.

Then launch Python

bash uv run python

Importing Herbie automatically registers your templates.

python from herbie import Herbie

You should see output like this when a plugin loads:

Herbie: Added model 'bmw' from herbie-plugin-tutorial. Herbie: Added model 'hrrr_analysis' from herbie-plugin-tutorial.

Now you can use those models in Herbie.

```python H = Herbie("2023-01-01", model="hrrr_analysis")

This one doesn't find anything because its a fictitious model

H = Herbie("2022-01-01", model="bmw", domain='hello') ```

You can look at the possible source locations with H.SOURCES

```python

from herbie import Herbie H = Herbie("2022-01-01", model="bmw", domain='hello') 💔 Did not find ┊ model=bmw ┊ product=default ┊ 2022-Jan-01 00:00 UTC F00 H.SOURCES {'localmain': '/path/to/bmw/model/output/bmw/gribfiles/2022010100/myfile.t00z.f00_hello.grib2'} ```

Fin

Please tell me if you made a useful plugin. Consider publishing it on GitHub or PyPI if you think others would like it too.

Owner

  • Name: Brian Blaylock
  • Login: blaylockbk
  • Kind: user
  • Location: Monterey, CA

Meteorologist

GitHub Events

Total
  • Release event: 1
  • Push event: 8
  • Create event: 5
Last Year
  • Release event: 1
  • Push event: 8
  • Create event: 5

Issues and Pull Requests

Last synced: about 1 year ago

All Time
  • Total issues: 0
  • Total pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 0
  • Total pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels

Dependencies

pyproject.toml pypi
  • herbie-data >=2025.3.1