iconarray.core.latlonhash.Icon2latlon#
- class iconarray.core.latlonhash.Icon2latlon(grid: xarray.Dataset, scale_factor: float = 0.3)#
Creates a field in a Cartesian lat/lon grid whose elements contain the ICON grid indices of the element whose lat/lon coordinates are contained within the cartesian element.
It can be used as a hashing of the ICON grid indices in order to search for nearest neighbor ICON indices with O(1) complexity.
- Parameters:
grid (
xr.Dataset
) – the ICON grid information, it should contain the following coordinates: clon,clat,elon,elat,vlon,vlatscale_factor (
float
) – factor of resolution between the icon grid and an auxiliary latlon grid needed by the cropping algorithm.
Example
open the ICON grid:
>>> ds_grid = xr.open_dataset("icon_grid_0001_R19B08_lon:0.1525-0.1535_lat:0.8748-0.8752.nc")
create the 2D array that maps ICON grid indices into a lat/lon Cartesian grid
>>> i2ll = Icon2latlon(ds_grid) >>> cartgrid_ind = i2ll.latlon_grid("cell") >>> cartgrid_ind ... array([[ 3, 0, 0, 1], ... [ 0, 0, 0, 0], ... [ 0, 4, 2, 0], ... [ 0, 0, 0, 0], ... [ 5, 0, 0, 9], ... [ 0, 0, 0, 0], ... [ 6, 0, 8, 0], ... [ 0, 0, 0, 0], ... [10, 0, 0, 0], ... [ 0, 0, 0, 7]]) ... Dimensions without coordinates: x, y
the lat/lon bounds of the grid are lon:[0.1525,0.1535], lat[0.8748,0.8752]
we can search for the ICON indices of the following coordinates:
>>> lons = xr.DataArray([0.152871, 0.153016]) >>> lats = xr.DataArray([0.875108, 0.874878]) >>> inds_lon, inds_lat = i2ll.latlon_indices_of_coords("cell", lons, lats) >>> inds_lon ... <xarray.DataArray (cindex: 2)> ... array([2, 4]) ... Dimensions without coordinates: cindex >>> inds_lat ... <xarray.DataArray (cindex: 2)> ... array([2, 0]) ... Dimensions without coordinates: cindex
retrieve the ICON indices:
>>> icon_inds = cartgrid_ind[inds_lon, inds_lat] >>> icon_inds ... <xarray.DataArray (cindex: 2)> ... array([2, 5]) ... Dimensions without coordinates: cindex
- __init__(grid: xarray.Dataset, scale_factor: float = 0.3)#
Methods
__init__
(grid[, scale_factor])latlon_grid
(loc)Generate a lat/lon grid that covers the entire ICON grid.
latlon_indices_of_coords
(loc, lons, lats)Retrieve the indices in the lat/lon grid associated with a sequence of lon/lat coordinates.