Skip to content

Instantly share code, notes, and snippets.

@fralc
Last active February 25, 2021 11:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fralc/c9c8747aca233b7e35f013abdf6bd099 to your computer and use it in GitHub Desktop.
Save fralc/c9c8747aca233b7e35f013abdf6bd099 to your computer and use it in GitHub Desktop.
import numpy as np
import geohash
import xarray as xr
array = xr.DataArray(np.array([[1, 2, 3], [4, 5, 6]]), coords=[("lat", [36, 37]), ("lon", [12, 13, 14])])
lat_arr, lon_arr = xr.broadcast(array.lat, array.lon)
f = lambda y, x: geohash.encode(y, x, 7)
array_geohash = xr.apply_ufunc(f, lat_arr, lon_arr, vectorize=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment