Skip to content

Instantly share code, notes, and snippets.

View fralc's full-sized avatar

Francesco LoConti fralc

View GitHub Profile
@fralc
fralc / radar_formulas.py
Created September 15, 2022 12:25
Weather radar formulas
import numpy as np
def rad2mmh(dbz, a_coeff=200, b_coeff=1.6):
Z = 10. ** (dbz / 10)
mmh = (Z / a_coeff) ** (1 / b_coeff)
return mmh
def mmh2rad(mmh, a_coeff=200, b_coeff=1.6):
Z = (mmh ** b_coeff) * a_coeff
dbz = 10 * np.log10(Z)
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)
@fralc
fralc / raster_postgis.py
Last active June 5, 2020 15:54 — forked from gzagatti/raster_postgis.py
Loads raster data from POSTGIS directly to numpy.array using rasterio
import psycopg2
from rasterio.io import MemoryFile
conn = pscopg2.connect("<connection string>")
cur = conn.cursor()
# ensure that the GTiff driver is available,
# see https://postgis.net/docs/postgis_gdal_enabled_drivers.html
cur.execute('''
SET postgis.gdal_enabled_drivers TO 'GTiff';
WITH temp as (