Skip to content

Commit cb4ba7e

Browse files
committed
updates (formatting)
1 parent 5f267dc commit cb4ba7e

14 files changed

Lines changed: 310 additions & 176 deletions

File tree

src/herbie/v2/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import herbie.v2.models as _models_pkg
3434
from herbie.v2._base import HerbieModel
3535
from herbie.v2._namespace import Herbie
36-
from herbie.v2.models.fast import FastHerbie
36+
from herbie.v2.fast import FastHerbie
3737

3838
# ---------------------------------------------------------------------------
3939
# Auto-discover and register all HerbieModel subclasses

src/herbie/v2/_namespace.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ class Herbie:
5252
def available_models(cls) -> list[str]:
5353
"""Return a sorted list of all registered model names."""
5454
from herbie.v2._base import HerbieModel
55+
5556
return sorted(
56-
name for name, obj in vars(cls).items()
57+
name
58+
for name, obj in vars(cls).items()
5759
if isinstance(obj, type) and issubclass(obj, HerbieModel)
5860
)
5961

src/herbie/v2/_sources.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,23 @@
3232

3333
from __future__ import annotations
3434

35+
from collections.abc import Callable
3536
from dataclasses import dataclass, field
36-
from typing import Callable, Literal
37-
37+
from typing import Literal
3838

3939
# ---------------------------------------------------------------------------
4040
# GRIB2 sources
4141
# ---------------------------------------------------------------------------
4242

43+
4344
@dataclass
4445
class GribSource:
4546
"""A remote GRIB2 file accessible via HTTP/HTTPS."""
4647

4748
url: str
4849
"""Full URL to the GRIB2 file."""
4950

50-
index_suffixes: list[str] = field(
51-
default_factory=lambda: [".idx", ".grib2.idx"]
52-
)
51+
index_suffixes: list[str] = field(default_factory=lambda: [".idx", ".grib2.idx"])
5352
"""Suffixes to try when looking for the companion index file.
5453
Each suffix is *appended* to ``url`` in order. The first one that
5554
exists is used.
@@ -72,6 +71,7 @@ class EccodesGribSource:
7271
# Zarr source
7372
# ---------------------------------------------------------------------------
7473

74+
7575
@dataclass
7676
class ZarrSource:
7777
"""A cloud-native Zarr store."""
@@ -93,6 +93,7 @@ class ZarrSource:
9393
# Directory source (one GRIB message per file — Canadian/Navy models)
9494
# ---------------------------------------------------------------------------
9595

96+
9697
@dataclass
9798
class DirectorySource:
9899
"""

src/herbie/v2/_xarray.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def load_xarray(
7272
# Try to merge multiple hypercubes (e.g. subhourly)
7373
try:
7474
import itertools
75+
7576
data_vars = set(itertools.chain(*[list(ds) for ds in datasets]))
7677
data_vars.discard("gribfile_projection")
7778
merged = xr.concat(datasets, dim="step", data_vars=list(data_vars))
Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,19 @@
3232

3333
from __future__ import annotations
3434

35+
from collections.abc import Iterable
3536
from concurrent.futures import ThreadPoolExecutor, as_completed
3637
from pathlib import Path
37-
from typing import Iterable
3838

3939
import pandas as pd
4040
from rich.console import Console
41-
from rich.progress import BarColumn, Progress, SpinnerColumn, TaskProgressColumn, TextColumn
41+
from rich.progress import (
42+
BarColumn,
43+
Progress,
44+
SpinnerColumn,
45+
TaskProgressColumn,
46+
TextColumn,
47+
)
4248

4349
from herbie.v2._base import HerbieModel
4450

@@ -109,10 +115,7 @@ def __iter__(self):
109115
return iter(self.objects)
110116

111117
def __repr__(self) -> str:
112-
return (
113-
f"FastHerbie({self.model_cls.MODEL_NAME}, "
114-
f"{len(self.objects)} objects)"
115-
)
118+
return f"FastHerbie({self.model_cls.MODEL_NAME}, {len(self.objects)} objects)"
116119

117120
# ── Bulk operations ────────────────────────────────────────────────────
118121

@@ -165,8 +168,7 @@ def download(
165168
with ThreadPoolExecutor(max_workers=max_workers) as pool:
166169
futures = {
167170
pool.submit(
168-
obj.download, search,
169-
overwrite=overwrite, verbose=False
171+
obj.download, search, overwrite=overwrite, verbose=False
170172
): i
171173
for i, obj in enumerate(self.objects)
172174
}
@@ -179,13 +181,9 @@ def download(
179181
progress.update(task, advance=1)
180182

181183
if errors:
182-
console.print(
183-
f"[yellow]⚠ {len(errors)} download(s) failed:[/yellow]"
184-
)
184+
console.print(f"[yellow]⚠ {len(errors)} download(s) failed:[/yellow]")
185185
for i, exc in errors.items():
186-
console.print(
187-
f" [{i}] {self.objects[i]!r}: [red]{exc}[/red]"
188-
)
186+
console.print(f" [{i}] {self.objects[i]!r}: [red]{exc}[/red]")
189187

190188
return [results.get(i) for i in range(len(self.objects))]
191189

@@ -232,9 +230,7 @@ def xarray(
232230
ds = obj.xarray(search, remove_grib=remove_grib)
233231
datasets.append(ds)
234232
except Exception as exc:
235-
console.print(
236-
f"[yellow]⚠ xarray failed for {obj!r}: {exc}[/yellow]"
237-
)
233+
console.print(f"[yellow]⚠ xarray failed for {obj!r}: {exc}[/yellow]")
238234
datasets.append(None)
239235

240236
# Filter out None

src/herbie/v2/models/canada.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class HRDPS(HerbieModel):
8686
"valid": ["continental", "north"],
8787
"descriptions": {
8888
"continental": "Continental domain; 2.5-km resolution",
89-
"north": "Northern domain; 3-km resolution",
89+
"north": "Northern domain; 3-km resolution",
9090
},
9191
},
9292
}

src/herbie/v2/models/ecmwf.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ class IFS(HerbieModel):
9090
"mmsf": "Multi-model seasonal forecast (ECMWF model only)",
9191
},
9292
},
93-
9493
}
9594

9695
def _build_sources(self) -> dict:
@@ -122,7 +121,8 @@ def _build_sources(self) -> dict:
122121
f"https://storage.googleapis.com/ecmwf-open-data/{post_root}", idx
123122
),
124123
"aws": EccodesGribSource(
125-
f"https://ecmwf-forecasts.s3.eu-central-1.amazonaws.com/{post_root}", idx
124+
f"https://ecmwf-forecasts.s3.eu-central-1.amazonaws.com/{post_root}",
125+
idx,
126126
),
127127
"ecmwf": EccodesGribSource(
128128
f"https://data.ecmwf.int/forecasts/{post_root}", idx
@@ -174,7 +174,6 @@ class AIFS(HerbieModel):
174174
"enfo": "50-member ensemble forecast",
175175
},
176176
},
177-
178177
}
179178

180179
def _build_sources(self) -> dict:
@@ -214,7 +213,8 @@ def _build_sources(self) -> dict:
214213
f"https://storage.googleapis.com/ecmwf-open-data/{post_root}", idx
215214
),
216215
"aws": EccodesGribSource(
217-
f"https://ecmwf-forecasts.s3.eu-central-1.amazonaws.com/{post_root}", idx
216+
f"https://ecmwf-forecasts.s3.eu-central-1.amazonaws.com/{post_root}",
217+
idx,
218218
),
219219
"ecmwf": EccodesGribSource(
220220
f"https://data.ecmwf.int/forecasts/{post_root}", idx

src/herbie/v2/models/gfs.py

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class GFS(HerbieModel):
6464
"valid": ["pgrb2", "pgrb2b"],
6565
"aliases": {"common": "pgrb2", "uncommon": "pgrb2b"},
6666
"descriptions": {
67-
"pgrb2": "Common pressure-level fields; 0.25° resolution",
67+
"pgrb2": "Common pressure-level fields; 0.25° resolution",
6868
"pgrb2b": "Supplemental pressure-level fields; 0.25° resolution",
6969
},
7070
},
@@ -73,11 +73,10 @@ class GFS(HerbieModel):
7373
"valid": [0.25, 0.5, 1.0],
7474
"descriptions": {
7575
0.25: "Quarter-degree (~28 km)",
76-
0.5: "Half-degree (~56 km)",
77-
1.0: "One-degree (~111 km)",
76+
0.5: "Half-degree (~56 km)",
77+
1.0: "One-degree (~111 km)",
7878
},
7979
},
80-
8180
}
8281

8382
def _build_sources(self) -> dict:
@@ -91,14 +90,22 @@ def _build_sources(self) -> dict:
9190
if d < datetime(2021, 3, 23):
9291
path = f"gfs.{d:%Y%m%d/%H}/gfs.t{d:%H}z.{product}.{res_str}.f{fxx:03d}"
9392
else:
94-
path = f"gfs.{d:%Y%m%d/%H}/atmos/gfs.t{d:%H}z.{product}.{res_str}.f{fxx:03d}"
93+
path = (
94+
f"gfs.{d:%Y%m%d/%H}/atmos/gfs.t{d:%H}z.{product}.{res_str}.f{fxx:03d}"
95+
)
9596

9697
idx = [".idx", ".grb2.inv"]
9798
return {
98-
"aws": GribSource(f"https://noaa-gfs-bdp-pds.s3.amazonaws.com/{path}", idx),
99-
"google": GribSource(f"https://storage.googleapis.com/global-forecast-system/{path}", idx),
100-
"nomads": GribSource(f"https://nomads.ncep.noaa.gov/pub/data/nccf/com/gfs/prod/{path}", idx),
101-
"azure": GribSource(f"https://noaagfs.blob.core.windows.net/gfs/{path}", idx),
99+
"aws": GribSource(f"https://noaa-gfs-bdp-pds.s3.amazonaws.com/{path}", idx),
100+
"google": GribSource(
101+
f"https://storage.googleapis.com/global-forecast-system/{path}", idx
102+
),
103+
"nomads": GribSource(
104+
f"https://nomads.ncep.noaa.gov/pub/data/nccf/com/gfs/prod/{path}", idx
105+
),
106+
"azure": GribSource(
107+
f"https://noaagfs.blob.core.windows.net/gfs/{path}", idx
108+
),
102109
"ncar_rda": GribSource(
103110
f"https://data.rda.ucar.edu/d084001/{d:%Y/%Y%m%d}"
104111
f"/gfs.0p25.{d:%Y%m%d%H}.f{fxx:03d}.grib2",
@@ -139,7 +146,6 @@ class GDAS(HerbieModel):
139146
"default": "pgrb2.0p25",
140147
"valid": ["pgrb2.0p25", "pgrb2.1p00"],
141148
},
142-
143149
}
144150

145151
def _build_sources(self) -> dict:
@@ -154,10 +160,16 @@ def _build_sources(self) -> dict:
154160

155161
idx = [".idx"]
156162
return {
157-
"aws": GribSource(f"https://noaa-gfs-bdp-pds.s3.amazonaws.com/{path}", idx),
158-
"google": GribSource(f"https://storage.googleapis.com/global-forecast-system/{path}", idx),
159-
"nomads": GribSource(f"https://nomads.ncep.noaa.gov/pub/data/nccf/com/gfs/prod/{path}", idx),
160-
"azure": GribSource(f"https://noaagfs.blob.core.windows.net/gfs/{path}", idx),
163+
"aws": GribSource(f"https://noaa-gfs-bdp-pds.s3.amazonaws.com/{path}", idx),
164+
"google": GribSource(
165+
f"https://storage.googleapis.com/global-forecast-system/{path}", idx
166+
),
167+
"nomads": GribSource(
168+
f"https://nomads.ncep.noaa.gov/pub/data/nccf/com/gfs/prod/{path}", idx
169+
),
170+
"azure": GribSource(
171+
f"https://noaagfs.blob.core.windows.net/gfs/{path}", idx
172+
),
161173
}
162174

163175

@@ -189,11 +201,15 @@ class GFSWave(HerbieModel):
189201
"product": {
190202
"default": "global.0p25",
191203
"valid": [
192-
"arctic.9km", "atlocn.0p16", "epacif.0p16",
193-
"global.0p16", "global.0p25", "gsouth.0p25", "wcoast.0p16",
204+
"arctic.9km",
205+
"atlocn.0p16",
206+
"epacif.0p16",
207+
"global.0p16",
208+
"global.0p25",
209+
"gsouth.0p25",
210+
"wcoast.0p16",
194211
],
195212
},
196-
197213
}
198214

199215
def _build_sources(self) -> dict:
@@ -207,7 +223,11 @@ def _build_sources(self) -> dict:
207223
)
208224
idx = [".idx"]
209225
return {
210-
"aws": GribSource(f"https://noaa-gfs-bdp-pds.s3.amazonaws.com/{path}", idx),
211-
"nomads": GribSource(f"https://nomads.ncep.noaa.gov/pub/data/nccf/com/gfs/prod/{path}", idx),
212-
"google": GribSource(f"https://storage.googleapis.com/global-forecast-system/{path}", idx),
226+
"aws": GribSource(f"https://noaa-gfs-bdp-pds.s3.amazonaws.com/{path}", idx),
227+
"nomads": GribSource(
228+
f"https://nomads.ncep.noaa.gov/pub/data/nccf/com/gfs/prod/{path}", idx
229+
),
230+
"google": GribSource(
231+
f"https://storage.googleapis.com/global-forecast-system/{path}", idx
232+
),
213233
}

src/herbie/v2/models/hrrr.py

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,29 @@ def _build_sources(self) -> dict:
9494
product = self.params["product"]
9595

9696
path = f"hrrr.{d:%Y%m%d}/conus/hrrr.t{d:%H}z.wrf{product}f{fxx:02d}.grib2"
97-
path_pando = f"hrrr/{product}/{d:%Y%m%d}/hrrr.t{d:%H}z.wrf{product}f{fxx:02d}.grib2"
97+
path_pando = (
98+
f"hrrr/{product}/{d:%Y%m%d}/hrrr.t{d:%H}z.wrf{product}f{fxx:02d}.grib2"
99+
)
98100

99101
idx = [".idx", ".grib2.idx"]
100102
return {
101-
"aws": GribSource(f"https://noaa-hrrr-bdp-pds.s3.amazonaws.com/{path}", idx),
102-
"google": GribSource(f"https://storage.googleapis.com/high-resolution-rapid-refresh/{path}", idx),
103-
"nomads": GribSource(f"https://nomads.ncep.noaa.gov/pub/data/nccf/com/hrrr/prod/{path}", idx),
104-
"azure": GribSource(f"https://noaahrrr.blob.core.windows.net/hrrr/{path}", idx),
105-
"pando": GribSource(f"https://pando-rgw01.chpc.utah.edu/{path_pando}", idx),
106-
"pando2": GribSource(f"https://pando-rgw02.chpc.utah.edu/{path_pando}", idx),
103+
"aws": GribSource(
104+
f"https://noaa-hrrr-bdp-pds.s3.amazonaws.com/{path}", idx
105+
),
106+
"google": GribSource(
107+
f"https://storage.googleapis.com/high-resolution-rapid-refresh/{path}",
108+
idx,
109+
),
110+
"nomads": GribSource(
111+
f"https://nomads.ncep.noaa.gov/pub/data/nccf/com/hrrr/prod/{path}", idx
112+
),
113+
"azure": GribSource(
114+
f"https://noaahrrr.blob.core.windows.net/hrrr/{path}", idx
115+
),
116+
"pando": GribSource(f"https://pando-rgw01.chpc.utah.edu/{path_pando}", idx),
117+
"pando2": GribSource(
118+
f"https://pando-rgw02.chpc.utah.edu/{path_pando}", idx
119+
),
107120
}
108121

109122

@@ -156,13 +169,24 @@ def _build_sources(self) -> dict:
156169
product = self.params["product"]
157170

158171
path = f"hrrr.{d:%Y%m%d}/alaska/hrrr.t{d:%H}z.wrf{product}f{fxx:02d}.ak.grib2"
159-
path_pando = f"hrrr/{product}/{d:%Y%m%d}/hrrr.t{d:%H}z.wrf{product}f{fxx:02d}.ak.grib2"
172+
path_pando = (
173+
f"hrrr/{product}/{d:%Y%m%d}/hrrr.t{d:%H}z.wrf{product}f{fxx:02d}.ak.grib2"
174+
)
160175

161176
idx = [".idx", ".grib2.idx"]
162177
return {
163-
"nomads": GribSource(f"https://nomads.ncep.noaa.gov/pub/data/nccf/com/hrrr/prod/{path}", idx),
164-
"aws": GribSource(f"https://noaa-hrrr-bdp-pds.s3.amazonaws.com/{path}", idx),
165-
"google": GribSource(f"https://storage.googleapis.com/high-resolution-rapid-refresh/{path}", idx),
166-
"azure": GribSource(f"https://noaahrrr.blob.core.windows.net/hrrr/{path}", idx),
167-
"pando": GribSource(f"https://pando-rgw01.chpc.utah.edu/{path_pando}", idx),
178+
"nomads": GribSource(
179+
f"https://nomads.ncep.noaa.gov/pub/data/nccf/com/hrrr/prod/{path}", idx
180+
),
181+
"aws": GribSource(
182+
f"https://noaa-hrrr-bdp-pds.s3.amazonaws.com/{path}", idx
183+
),
184+
"google": GribSource(
185+
f"https://storage.googleapis.com/high-resolution-rapid-refresh/{path}",
186+
idx,
187+
),
188+
"azure": GribSource(
189+
f"https://noaahrrr.blob.core.windows.net/hrrr/{path}", idx
190+
),
191+
"pando": GribSource(f"https://pando-rgw01.chpc.utah.edu/{path_pando}", idx),
168192
}

0 commit comments

Comments
 (0)