API

Grids

class earth2grid.healpix.Grid(level: int, pixel_order: PixelOrder | XY = PixelOrder.RING)

Bases: Grid

A Healpix Grid

Attrs:

level: 2^level = nside pixel_order: the ordering convection of the data

get_bilinear_regridder_to(lat: ndarray, lon: ndarray)

Get regridder to the specified lat and lon points

reorder(order: PixelOrder | XY, x: Tensor) Tensor

Rorder the pixels of x to have order

to_image(x: Tensor, fill_value=nan) Tensor

Use the 45 degree rotated grid pixelation i points to SE, j point to NE

class earth2grid.latlon.LatLonGrid(lat: list[float], lon: list[float])

Bases: Grid

get_bilinear_regridder_to(lat: ndarray, lon: ndarray)

Get regridder to the specified lat and lon points

earth2grid.latlon.equiangular_lat_lon_grid(nlat: int, nlon: int, includes_south_pole: bool = True) LatLonGrid

Return a regular lat-lon grid

Lat is ordered from 90 to -90. Includes -90 and only if if includes_south_pole is True. Lon is ordered from 0 to 360. includes 0, but not 360.

Parameters:
  • nlat – number of latitude points

  • nlon – number of longtidue points

  • includes_south_pole – if true the final nlat includes the south pole

Regridding

earth2grid.get_regridder(src: Grid, dest: Grid) Module

Get a regridder from src to dest

earth2grid.KNNS2Interpolator(src_lon: Tensor, src_lat: Tensor, dest_lon: Tensor, dest_lat: Tensor, k: int = 1, eps=1e-07) Regridder

K-nearest neighbor interpolator with inverse distance weighting

Parameters:
  • src_lon – (m,) source longitude in degrees E

  • src_lat – (m,) source latitude in degrees N

  • dest_lon – (n,) output longitude in degrees E

  • dest_lat – (n,) output latitude in degrees N

  • k – number of neighbors, default: 1

  • eps – regularization factor for inverse distance weighting. Only used if k > 1.

earth2grid.BilinearInterpolator(x_coords: Tensor, y_coords: Tensor, x_query: Tensor, y_query: Tensor, fill_value=nan) None

Bilinear interpolation for a non-uniform grid

Other utilities

earth2grid.healpix.reorder(x: Tensor, src_pixel_order: PixelOrder | XY, dest_pixel_order: PixelOrder | XY)

Reorder x from one pixel order to another

earth2grid.healpix.pad(x: Tensor, padding: int) Tensor

Pad each face consistently with its according neighbors in the HEALPix

Parameters:
  • x – The input tensor of shape [N, F, H, W] or [N, F, C, H, W]

  • padding – the amount of padding

Returns:

The padded tensor with shape [N, F, H+2*padding, W+2*padding]

Examples

Ths example show to pad data described by a Grid object.

>>> grid = Grid(level=4, pixel_order=PixelOrder.RING)
>>> lon = torch.from_numpy(grid.lon)
>>> faces = grid.reorder(HEALPIX_PAD_XY, lon)
>>> faces = faces.view(1, 12, grid._nside(), grid._nside())
>>> faces.shape
torch.Size([1, 12, 16, 16])
>>> padded = pad(faces, padding=1)
>>> padded.shape
torch.Size([1, 12, 18, 18])