herbie.accessors.HerbieAccessor#

class herbie.accessors.HerbieAccessor(xarray_obj)[source]#

Accessor for xarray Datasets opened with Herbie.

__init__(xarray_obj)[source]#

Methods

__init__(xarray_obj)

nearest_points(points[, names, verbose])

Legacy point extractor.

pick_points(points[, method, k, ...])

Pick nearest neighbor grid values at selected points.

plot([ax, common_features_kw, vars])

Plot data on a map.

to_180()

Wrap longitude coordinates as range [-180,180].

to_360()

Wrap longitude coordinates as range [0,360].

with_wind([which])

Return Dataset with calculated wind speed and/or direction.

Attributes

center

Return the geographic center point of this dataset.

crs

Cartopy coordinate reference system (crs) from a cfgrib Dataset.

polygon

Get a polygon of the domain boundary.

Methods:

__init__(xarray_obj)

nearest_points(points[, names, verbose])

Legacy point extractor.

pick_points(points[, method, k, ...])

Pick nearest neighbor grid values at selected points.

plot([ax, common_features_kw, vars])

Plot data on a map.

to_180()

Wrap longitude coordinates as range [-180,180].

to_360()

Wrap longitude coordinates as range [0,360].

with_wind([which])

Return Dataset with calculated wind speed and/or direction.

Attributes:

center

Return the geographic center point of this dataset.

crs

Cartopy coordinate reference system (crs) from a cfgrib Dataset.

polygon

Get a polygon of the domain boundary.

__init__(xarray_obj)[source]#
property center: tuple[float, float]#

Return the geographic center point of this dataset.

property crs[source]#

Cartopy coordinate reference system (crs) from a cfgrib Dataset.

Projection information is from the grib2 message for each variable.

Parameters:

ds (xarray.Dataset) – An xarray.Dataset from a GRIB2 file opened by the cfgrib engine.

nearest_points(points, names=None, verbose=True)[source]#

Legacy point extractor.

pick_points(points: DataFrame, method: Literal['nearest', 'weighted'] = 'nearest', *, k: int | None = None, max_distance: int | float = 500, use_cached_tree: bool | Literal['replant'] = True, tree_name: str | None = None, verbose: bool = False) Dataset[source]#

Pick nearest neighbor grid values at selected points.

Parameters:
  • points (pd.DataFrame) – DataFrame with ‘latitude’ and ‘longitude’ columns

  • method ({'nearest', 'weighted'}) – Method for point picking: - ‘nearest’: Get value at nearest grid point - ‘weighted’: Inverse-distance weighted mean of k nearest points

  • k (int, optional) – Number of nearest neighbors. Defaults to 1 for ‘nearest’, 4 for ‘weighted’

  • max_distance (float) – Maximum distance in km for valid neighbors (default: 500)

  • use_cached_tree (bool or 'replant') – Whether to cache the BallTree spatial index: - True: Use cached tree if exists, create and cache if not - False: Always create new tree, don’t cache - ‘replant’: Force create new tree and cache it

  • tree_name (str, optional) – Custom name for BallTree cache file. If None, uses ds.model

  • verbose (bool) – Print verbose output (currently unused)

Returns:

Dataset with values at requested points. Includes coordinates: - point_latitude, point_longitude: requested coordinates - point_grid_distance: distance to nearest grid point (km) - Any other columns from points DataFrame

Return type:

xr.Dataset

Examples

>>> H = Herbie("2024-03-28 00:00", model="hrrr")
>>> ds = H.xarray("TMP:[5,6,7,8,9][0,5]0 mb")
>>> points = pd.DataFrame({
...     "longitude": [-100, -105, -98.4],
...     "latitude": [40, 29, 42.3],
...     "stid": ["aa", "bb", "cc"],
... })

Get nearest neighbor values: >>> dsp = ds.herbie.pick_points(points, method=”nearest”)

Get distance-weighted mean of 4 nearest points: >>> dsp = ds.herbie.pick_points(points, method=”weighted”)

Convert to DataFrame: >>> df = dsp.to_dataframe()

Index by station ID: >>> dsp = dsp.swap_dims({“point”: “point_stid”})

plot(ax=None, common_features_kw={}, vars=None, **kwargs)[source]#

Plot data on a map.

Parameters:

vars (list) – List of variables to plot. Default None will plot all variables in the DataSet.

property polygon[source]#

Get a polygon of the domain boundary.

to_180() Dataset[source]#

Wrap longitude coordinates as range [-180,180].

to_360() Dataset[source]#

Wrap longitude coordinates as range [0,360].

with_wind(which: Literal['both', 'speed', 'direction'] = 'both') Dataset[source]#

Return Dataset with calculated wind speed and/or direction.

Consistent with the eccodes GRIB parameter database, variables names are assigned as follows:

  • “si10” : 10 metre wind speed (note this is not ws10 as you might expect)

  • “wdir10” : 10 metre wind direction

  • “ws” : wind speed

  • “wdir” : wind direction

Refer to the eccodes database <https://codes.ecmwf.int/grib/param-db/>.

Parameters:

which ({'both', 'speed', 'direction'}) – Specify which wind quantity to compute.