Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Removed AIFS-ENS invariants from model input / outputs and moved into model wrapper
- CDS and NCAR lexica have been updated with variables for AIFS-ENS
- Switch grib reads in HRRR data sources from xarray to pygrib to fix memory leak

### Deprecated

Expand All @@ -28,6 +29,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Dependencies

- Added pygrib to data dependency group

## [0.11.0] - 2025-12-19

### Added
Expand Down
18 changes: 13 additions & 5 deletions earth2studio/data/hrrr.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@
from earth2studio.utils.type import LeadTimeArray, TimeArray, VariableArray

try:
import pygrib
import pyproj
except ImportError:
OptionalDependencyFailure("data")
pyproj = None
pygrib = None

logger.remove()
logger.add(lambda msg: tqdm.write(msg, end=""), colorize=True)
Expand Down Expand Up @@ -510,11 +512,17 @@ async def fetch_array(
byte_offset=byte_offset,
byte_length=byte_length,
)
# Open into xarray data-array
da = xr.open_dataarray(
grib_file, engine="cfgrib", backend_kwargs={"indexpath": ""}
)
return modifier(da.values)
# Load with pygrib, xarray with cfgrib is 10x slower and leaks memory
try:
grbs = pygrib.open(grib_file)
values = modifier(grbs[1].values)
except Exception as e:
logger.error(f"Failed to read grib file {grib_file}")
raise e
finally:
grbs.close()

return values

def _validate_time(self, times: list[datetime]) -> None:
"""Verify if date time is valid for HRRR based on offline knowledge
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ data = [
"intake-esgf>=2025.9.26",
"planetary-computer>=0.5.0",
"globus-sdk<4.0.0", # TODO: Remove once intake-esgf updates
"pygrib",
"pystac-client>=0.9.0",
"httpx==0.28.1",
"rasterio>=1.3.9",
Expand Down
Loading