Skip to content

Instantly share code, notes, and snippets.

View celoyd's full-sized avatar

Charlie Loyd celoyd

View GitHub Profile
@celoyd
celoyd / l8_toa.py
Last active October 30, 2015 19:04
Simple Landsat 8 TOA, working with MTLs as of mid-2015. NOT CAREFULLY TESTED! Scale factor of 55k.
import click
import rasterio as rio
import os
import numpy as np
import re
from sys import argv, exit
from math import sin, radians
def get_mtl_path(bundle_path):
mtls = [
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#!/usr/bin/env python
import rasterio as rio
import numpy as np
import sys
with rio.open(sys.argv[1], 'r') as src:
meta = src.meta
cplx = src.read(1)
#!/usr/bin/env python
import numpy as np
import sys
import rasterio as rio
chip = open(sys.argv[1]).read(4096)
chip = np.fromstring(chip, dtype='uint8')
chip = chip.reshape(64, 64)
@celoyd
celoyd / ndvi.py
Last active October 20, 2018 19:39
#!/usr/bin/env python
# Very simple rasterio NDVI (or general normalized difference ratio) demo.
# python ndvi.py $landsat_scene/*B{4,5}.TIF ndvi.tif
import rasterio as rio
from sys import argv
import numpy as np
math_type = np.float32 # type for internal calculations
-- copy eight from '/Users/ch/Desktop/meta/LANDSAT_8.csv' delimiter ',' CSV header;
create type sensor_t as enum ('OLI_TIRS', 'OLI', 'TIRS');
create type daynight_t as enum ('DAY', 'NIGHT');
create type datatype_t as enum ('L1GT', 'L1T', 'PR');
create type nadir_t as enum ('NADIR', 'OFFNADIR');
create table eight (
sceneID text primary key,
sensor sensor_t,
#!/usr/bin/env python
import sys
import os
import numpy
from osgeo import gdal, gdal_array
TAIL_TRIM = 0.01
#!/usr/bin/env python
# not properly tested
from sys import argv
from PIL import Image
import numpy as np
A, B = (
np.asarray(Image.open(x)).astype(np.float32)
# Beta-quality Landsat 8-oriented windowed pansharpener by Charlie Loyd
# python3 panchunk.py $SCENE/*B{4,3,2,8}.TIF ${SCENE}-pansharp.tif
# Then you may want something like this to brighten it up:
# convert -channel B -gamma 0.96 -channel RGB -sigmoidal-contrast 40,14% ${SCENE}-pansharp.tif ${SCENE}-pretty.tif
# But that will strip geo tags.
import asyncio
import rasterio as rio
# To help with https://xkcd.com/936/
randword () {
dict=/usr/share/dict/words
r=$((($RANDOM * $RANDOM) % `wc -l $dict | awk '{print $1}'`))
head -n $r $dict | tail -n 1
}