Map Algebra with NumPy
Project description
Map Algebra with NumPy
Inspired by the ARC/INFO GRID implementation of Map Algebra.
pip install glidergun
Creating a hillshade from SRTM DEM
from glidergun import grid, mosaic
dem1 = grid(".data/n55_e008_1arc_v3.bil")
dem2 = grid(".data/n55_e009_1arc_v3.bil")
dem = mosaic(dem1, dem2)
hillshade = dem.hillshade()
# hillshade.save(".output/hillshade.tif", "uint8")
# hillshade.save(".output/hillshade.png")
# hillshade.save(".output/hillshade.kmz")
dem, hillshade
Calculating the NDVI from Landsat bands
from glidergun import grid
band4 = grid(".data/LC08_L2SP_197021_20220324_20220330_02_T1_SR_B4.TIF")
band5 = grid(".data/LC08_L2SP_197021_20220324_20220330_02_T1_SR_B5.TIF")
ndvi = (band5 - band4) / (band5 + band4)
ndvi.plot("gist_earth")
Interpolation
from glidergun import Defaults, grid
Defaults.display = "cividis"
dem = grid(".data/n55_e008_1arc_v3.bil").resize(10, 10)
sparse_dem = dem.set_nan(dem.randomize() > 0.1)
sparse_dem, sparse_dem.interp_idw(), sparse_dem.interp_rbf()
Rising Sea Level Simulation
from glidergun import grid
dem = grid(".data/n55_e008_1arc_v3.bil")
dem.set_nan(dem > 2).color("Blues").map(opacity=0.5, basemap="OpenStreetMap")
Conway's Game of Life
from glidergun import animate, grid
def tick(g):
count = g.focal_sum() - g
return (g == 1) & (count == 2) | (count == 3)
def simulate(g):
md5s = set()
while g.md5 not in md5s:
md5s.add(g.md5)
yield -(g := tick(g))
seed = grid((120, 80)).randomize() < 0.5
animation = animate(simulate(seed), interval=40)
# animation.save("game_of_life.gif")
animation
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
glidergun-0.8.71.tar.gz
(33.7 kB
view details)
Built Distribution
File details
Details for the file glidergun-0.8.71.tar.gz
.
File metadata
- Download URL: glidergun-0.8.71.tar.gz
- Upload date:
- Size: 33.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd93be07064fb755f9f6828c9e4c36030ccdc9572fba13ba81b221f5fedd7c40 |
|
MD5 | 66a5a1cb6a33af0599f8442707b5cac2 |
|
BLAKE2b-256 | 0381f8d59d360c34a9663f14f361d9e9122e4a3721715f05050795c67eebbe41 |
File details
Details for the file glidergun-0.8.71-py3-none-any.whl
.
File metadata
- Download URL: glidergun-0.8.71-py3-none-any.whl
- Upload date:
- Size: 25.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a36838f972d7e481030f60e4848a43b8a4de6db5935ecc392490976a1b00315 |
|
MD5 | ebacc10a78aa7f0303ef7b0a89d1d778 |
|
BLAKE2b-256 | 00146443ca2ffebad0cf4def71688be1d650c3d5f119384a2d6dfc393881692e |