This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from pathlib import Path | |
| import json | |
| def get_kernels(): | |
| venvs = !jupyter kernelspec list | |
| venvs_list = [i for venv in venvs[1:] for i in venv.split(' ') if len(i)>0] | |
| venvs_dict = {venvs_list[i]: venvs_list[i + 1] for i in range(0, len(venvs_list), 2)} | |
| return venvs_dict | |
| def get_parent_env(kernel_name): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| import pandas as pd | |
| from shapely.geometry import Polygon | |
| polygon = Polygon(((0, 0), (0, 1), (5, 1), (5, 0))) | |
| polygon_gdf = gpd.GeoDataFrame({'geometry': [polygon]}, geometry='geometry') | |
| points = polygon_gdf.sample_points(size=1000) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 ( |