https://github.com/blaylockbk/herbie-plugin-tutorial
A demonstration of writing a custom model template plugin for Herbie
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
Repository
A demonstration of writing a custom model template plugin for Herbie
Basic Info
- Host: GitHub
- Owner: blaylockbk
- License: mit
- Language: Python
- Default Branch: main
- Homepage: https://herbie.readthedocs.io/en/stable/user_guide/tutorial/extend.html
- Size: 1.95 MB
Statistics
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
- Releases: 0
Topics
Metadata Files
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.10because that is Herbie's minimum version - Add
herbie-dataas 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:
hrrr_analysis— A custom template for the HRRR model that only locates analysis fields from AWS.bmw— Local GRIB2 files output from a fictional dataset BMW "Brian's Model of Weather"
[!TIP]
Class names must be lowercase! Herbie lowercases the
model=input, somodel='HRRR'becomesmodel='hrrr'.Set
self.DESCRIPTIONandself.DETAILSfor helpful metadata.
self.PRODUCTSmust have at least one entry. If the user doesn't provide aproduct=, Herbie uses the first one by default.
self.SOURCESis a dictionary of key-value pairs. Herbie will try each one in order until it finds a valid file. Prefix a key withlocalif the file is on disk instead of on a remote server.
self.LOCALFILEis how you specify what the file name will be when it is downloaded. Setting tof"{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
--editableso 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
- Website: http://home.chpc.utah.edu/~u0553130/Brian_Blaylock/home.html
- Twitter: blaylockbk
- Repositories: 45
- Profile: https://github.com/blaylockbk
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
- herbie-data >=2025.3.1