arlmet.Grid#

class arlmet.Grid(projection, nx, ny)[source]#

Two-dimensional horizontal grid definition for ARL data.

Grids are immutable, hashable value objects (the derived crs and origin are computed once and cached). Use subset() or dataclasses.replace() to derive a new grid.

Parameters:
  • projection (Projection) – Grid projection metadata.

  • nx (int) – Number of grid points in the x-direction (columns).

  • ny (int) – Number of grid points in the y-direction (rows).

crs#

Coordinate reference system for the grid.

Type:

pyproj.CRS

dims#

Dimension names for the grid (“lat”, “lon”) or (“y”, “x”).

Type:

tuple

is_latlon#

True if the grid uses a lat-lon projection.

Type:

bool

origin#

Origin (lower-left corner) in the base CRS (projected coordinates).

Type:

tuple[float, float]

calculate_coords() → dict[str, tuple[tuple[str, ...], np.ndarray]][source]#

Calculate grid coordinates as name -> (dims, values).

fractional_indices(lon, lat)[source]#

Convert lon/lat positions to fractional grid indices.

window_from_bbox(bbox)[source]#

Resolve a geographic bounding box to an inclusive grid window.

subset(window)[source]#

Build a new Grid describing a rectangular subset.

Examples

>>> from arlmet.grid import Grid, Projection
>>> proj = Projection(
...     pole_lat=90.0,
...     pole_lon=180.0,
...     tangent_lat=1.0,
...     tangent_lon=1.0,
...     grid_size=0.0,
...     orientation=0.0,
...     cone_angle=0.0,
...     sync_x=1.0,
...     sync_y=1.0,
...     sync_lat=40.0,
...     sync_lon=-120.0,
... )
>>> grid = Grid(projection=proj, nx=3, ny=2)
>>> tuple(grid.dims)
('lat', 'lon')

Methods

Grid.__init__(projection, nx, ny)

Grid.calculate_coords()

Grid coordinates in both projected and geographic systems.

Grid.fractional_indices(lon, lat)

Convert geographic coordinates to zero-based fractional grid indices.

Grid.full_window()

Return a GridWindow spanning the full horizontal domain.

Grid.meridian_convergence(lon, lat)

Angle from grid north to true north at each point, in degrees.

Grid.rotate_winds(u, v, lon, lat)

Rotate grid-relative wind components to earth-relative ones.

Grid.subset(window)

Build a new grid definition for a rectangular subset.

Grid.window_from_bbox(bbox)

Resolve a geographic bounding box to grid indices.

Attributes

Grid.crs

Coordinate reference system for this grid.

Grid.dims

Get the dimension names for this grid.

Grid.is_latlon

Check if this grid uses a lat-lon projection.

Grid.origin

Origin (lower-left corner) in the base CRS.

Grid.wraps_lon

Whether the grid is lat/lon and its columns span all 360 degrees of longitude.

Grid.projection

Grid.nx

Grid.ny