Skip to content

Commit 9f95676

Browse files
committed
allow user-specified label
1 parent 1dcf2ab commit 9f95676

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

src/herbie/v2/fast.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,13 @@ class FastHerbie:
203203
Forecast lead time(s) in hours. Either a single ``int``/``str`` or
204204
an iterable of ints. The cross-product of ``dates`` × ``step`` is
205205
used when multiple values are provided.
206+
label
207+
Optional human-readable stem for the output filename
208+
(e.g. ``"hrrr_precip_june2024"``). The file will be written as
209+
``<label>.grib2``. When ``None`` (default), a name is auto-generated
210+
from the model name and a content hash. Note: if ``label`` is set and
211+
``overwrite=False``, repeated calls with different search strings will
212+
return the existing file without re-downloading.
206213
**kwargs
207214
Forwarded to the model constructor (``product``, ``priority``,
208215
``save_dir``, ``overwrite``, etc.).
@@ -233,6 +240,7 @@ def __init__(
233240
*,
234241
model: type[HerbieModel],
235242
step: int | str | Iterable = 0,
243+
label: str | None = None,
236244
**kwargs,
237245
):
238246
if not (isinstance(model, type) and issubclass(model, HerbieModel)):
@@ -242,6 +250,7 @@ def __init__(
242250
)
243251

244252
self.model_cls = model
253+
self.label = label
245254
self.index_fallback_method = kwargs.get("index_fallback_method", "auto")
246255

247256
dates_list = list(dates)
@@ -674,6 +683,8 @@ def _auto_filename(
674683
of the search expression so repeated calls with different filters
675684
produce distinct files.
676685
"""
686+
if self.label is not None:
687+
return f"{self.label}.grib2"
677688
model = self.model_cls.MODEL_NAME
678689
n = len(self.objects)
679690
# Stable hash: based on the search string and the set of source URLs

0 commit comments

Comments
 (0)