Geo API
Geo Package
Generic geospatial logic and data for the NGED substation forecast project: H3 spatial indexing and the Great Britain boundary the numerical weather prediction (NWP) grid is clipped to. H3 is a grid system that tiles the globe in hexagons at nested resolutions, with 12 pentagons where hexagons alone cannot close the sphere, and each cell is identified by an index.
Map of Great Britain using H3 resolution 5 hexagons

Purpose
The geo package decouples generic geospatial operations from dataset-specific ingestion logic,
such as the processing of European Centre for Medium-Range Weather Forecasts (ECMWF) data in
dynamical_data. Any package in the workspace can therefore perform a spatial transformation —
mapping a latitude/longitude grid to H3 hexagons, for example — without depending on heavy or
unrelated packages.
compute_h3_grid_weights_for_boundary accepts any boundary polygon, not only the Great Britain
shape this package ships. Accepting any boundary polygon adds no complexity here and means a new
region plugs into the same H3 gridding rather than forking the gridding code. Keeping the function
boundary-agnostic is design principle
5
applied to this package.
Two neighbouring jobs are deliberately not here. The per-substation H3 index (h3_res_5 on
TimeSeriesMetadata) is computed by nged_data straight from each substation's coordinates. The
spatial aggregation that consumes the grid weights computed here happens in dynamical_data at
ECMWF ingest. The weather grid is square and the H3 grid is hexagonal, so a grid weight is the
fraction of one hexagon that one square grid point covers, and each hexagon takes a weighted share
of the grid points overlapping it.
Contents
h3—compute_h3_grid_weights_for_boundary()andcompute_h3_grid_weights(), which map the H3 grid onto the regular lat/lon NWP grid. The sampling and snapping method is documented on the functions themselves.great_britain.load—load_gb_boundary(), which loads the Great Britain boundary polygon that the NWP grid is clipped to, from the packaged GeoJSON file.
geo.h3
H3-related utilities for geospatial operations.
Classes
Functions:
compute_h3_grid_weights_for_boundary(boundary, nwp_grid_size_degrees, h3_res, child_h3_res=None)
Computes the H3 grid weights for a geospatial boundary.
Generates the spatial mapping between the hexagonal H3 grid and the regular lat/lon NWP grid.
The mapping is calculated by sampling each H3 cell with finer-resolution child cells and
determining which regular grid cell each child falls into. The nwp_grid_size_degrees
parameter is used to snap high-resolution H3 cells to the nearest regular NWP grid points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
boundary
|
BaseGeometry
|
The geospatial boundary to find H3 cells for. |
required |
nwp_grid_size_degrees
|
float
|
The size of the regular lat/lon grid in degrees. |
required |
h3_res
|
int
|
The H3 resolution to use for the grid. |
required |
child_h3_res
|
int | None
|
The H3 resolution to use for the underlying points. If None, it defaults to h3_res + 2. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame[H3GridWeights]
|
One row per (H3 cell, NWP grid point) pair that overlap within |
DataFrame[H3GridWeights]
|
holds the fraction of that H3 cell's child cells falling inside the grid point's box. This |
DataFrame[H3GridWeights]
|
function resolves |
DataFrame[H3GridWeights]
|
|
Source code in packages/geo/src/geo/h3.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
compute_h3_grid_weights(nwp_grid_size_degrees, h3_index, child_h3_res=None)
Computes the proportion mapping for H3 grid cells to a regular lat/lng grid.
This function takes a list of H3 indices. Each H3 resolution subdivides the one above it, so a
cell at resolution n contains a set of smaller child cells at resolution n+1. For each
index, this function counts how many of its child H3 cells at the finer resolution
child_h3_res fall into each cell of a regular lat/lng grid of size nwp_grid_size_degrees.
The regular grid is assumed to be perfectly aligned to 0.0 (e.g., 0.0,
nwp_grid_size_degrees, nwp_grid_size_degrees * 2).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nwp_grid_size_degrees
|
float
|
The size of the regular NWP lat/lng grid in degrees (e.g., 0.25). |
required |
h3_index
|
list[int]
|
List of 64-bit H3 discrete spatial indices. |
required |
child_h3_res
|
int | None
|
The H3 resolution to use for the underlying points. Must be
strictly greater than the resolution of the input |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame[H3GridWeights]
|
One row per (H3 cell, NWP grid point) pair that overlap, with |
DataFrame[H3GridWeights]
|
fraction of that H3 cell's child cells falling inside the grid point's box. The |
DataFrame[H3GridWeights]
|
|
Source code in packages/geo/src/geo/h3.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
geo.great_britain.load
Loading the Great Britain boundary polygon that the NWP H3 grid is clipped to.
Functions:
load_gb_boundary()
Loads the boundary geometry for Great Britain from a local GeoJSON file.
The boundary is buffered to ensure that coastal substations and nearby islands are included in the resulting H3 grid without spatial distortion.
Source code in packages/geo/src/geo/great_britain/load.py
12 13 14 15 16 17 18 19 20 21 22 | |