arlmet.Grid.window_from_bbox#

Grid.window_from_bbox(bbox, *, bbox_crs=None)[source]#

Resolve a bounding box to grid indices.

Without bbox_crs the box is in degrees of longitude and latitude, as described next; with it, see bbox_crs below.

On a lat/lon grid the window holds the cells whose centers lie inside the box, edges included. A column or row within a millionth of a cell of an edge counts as on it, so rounding in the arithmetic (an east edge of -110 against a column stored as 250 degrees, a north edge of 41.4 against a row stored as 41.400000000000006) never decides a column or row. HYSPLIT’s xtrct_grid takes the column nearest each edge, so it agrees for edges on columns and can keep one more column for edges between them.

On a projected grid the window is the smallest rectangle of cells that holds every point of the box that lies on the grid (in one of its cells). Its edges come from the box’s outline, sampled at most half a cell apart on the grid, where it lies on the grid or crosses the grid’s border, and from the grid’s own corners that lie inside the box; the lowest and highest index on each axis is rounded to the nearest cell, like Fortran NINT. Parallels and meridians curve on these grids, so an extreme is often the box’s south-east or north-west corner, or a point partway along an edge. Points off the grid do not widen the window, so a box that reaches past the grid, across the meridian opposite the projection’s center or to a pole the projection cannot map, gives the cells of its part on the grid (all of them, for a box that holds the whole grid). xtrct_grid uses only the south-west and north-east corners, on or off the grid, so its crop can leave out part of the box; for a box inside the grid this window holds that crop and can be a few cells larger. Longitudes count modulo 360 ((440, 0, 450, 10) is (80, 0, 90, 10)), and a box 360 degrees wide or more holds every longitude.

Raises ValueError when no point of the box lies on the grid.

Parameters:
  • bbox (tuple[float, float, float, float]) – Bounding box as (west, south, east, north) in degrees. Longitudes count modulo 360, so 180 and -180 are the same meridian and a box may reach past 180. west > east crosses the dateline, so (170, -170) is the box (170, 190): a window where it reaches the grid (GFS, Alaska) and ValueError where it does not (HRRR). An infinite width (west=-inf or east=inf) holds every longitude; a NaN longitude raises ValueError. Edges may be any real numbers (NumPy scalars, Decimal): they are converted to float first.

  • bbox_crs (Any) – The coordinate reference system of bbox, as anything pyproj.CRS.from_user_input() takes ("EPSG:32612", a PROJ string, crs). The box is then (xmin, ymin, xmax, ymax) in that system’s units, easting before northing (longitude before latitude), whatever order the system names its axes in; the edges must be finite, with xmin <= xmax. On either kind of grid the window is then the smallest rectangle of cells that holds every point of the box on the grid, found as on a projected grid above: from the box’s outline, sampled about half a cell apart on the grid, and the grid’s corners inside the box. A global lat/lon grid is cut at its seam, so a box across the seam gets every column. The default, None, and any system equal to EPSG:4326 (in either axis order, so "OGC:CRS84" too) mean degrees, as above. On a projected grid, bbox_crs=grid.crs gives the box in meters from the first cell’s center, so cell (i, j) is at (i, j) * grid_size * 1000.

Return type:

GridWindow