Skip to content

Instantly share code, notes, and snippets.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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 = [
import rasterio as rio
import numpy as np
import os
import sys
# Tasseled Cap with Baig et al. 2014 coefficients.
# Use: l8tc.py bundle/*B{2..7}.TIF tass.tif
coefficients = [
[0.3029, 0.2786, 0.4733 ,0.5599, 0.508, 0.1872],
#!/usr/bin/env python
# based on https://gist.github.com/celoyd/55b8876c02e968c599f8
# makes lots of big assumptions like 1280x720 video
import numpy as np
import cv2
from sys import argv
movf, outf = argv[1:]
# Quickie processing for LC81770782013190LGN00
# Cf. http://mapbox.com/blog/processing-landsat-8/
convert -combine *_B{4,3,2}.TIF rgb.tif
convert -resize 200% rgb.tif rgb-big.tif
convert -compose Colorize *_B8.TIF rgb-big.tif -composite pan.tif
convert -channel B -gamma 0.95 -channel RGB -sigmoidal-contrast 60x13% pan.tif ready.tif
convert -crop 3000x2000+8000+6000 ready.tif crater.jpeg
convert -crop 3000x2000+2000+6000 ready.tif cliff.jpeg
char@mako: identify -list format 0 ~/Desktop
Format Module Mode Description
-------------------------------------------------------------------------------
3FR DNG r-- Hasselblad CFV/H3D39II
A* RAW rw+ Raw alpha samples
AAI* AAI rw+ AAI Dune image
AI PDF rw- Adobe Illustrator CS2
ART* ART rw- PFS: 1st Publisher Clip Art
ARW DNG r-- Sony Alpha Raw Image Format
AVI MPEG r-- Microsoft Audio/Visual Interleaved
#!/usr/bin/env python
import psycopg2 as pg
import Image
from sys import argv
conn = pg.connect(database='tweets', user='char', host='localhost')
cur = conn.cursor()
pxper = 16
if tiff_h is None:
include_tiff_h = os.path.join(os.path.split(lib)[0], '..', 'include', 'tiff.h')
if not os.path.isfile(include_tiff_h):
# fix me for windows:
include_tiff_h = os.path.join('/usr','include','tiff.h')
if not os.path.isfile(include_tiff_h):
raise ValueError('Failed to find TIFF header file (may be need to run: sudo apt-get install libtiff4-dev)')
# Read TIFFTAG_* constants for the header file:
f = open (include_tiff_h, 'r')
l = []
#!/usr/bin/env python
from sys import argv, exit
import Image
import time
from numpy import *
avgtype = float32
avg = array([])
@celoyd
celoyd / corr.py
Last active December 25, 2015 19:59
World’s simplest band correlation visualizer
#!/usr/bin/env python
# Simple script to scatterplot one band's values over another's into a third image.
# Usagi Yojimbo: corr.py band_1.tif band_2.tif 2_v_3.tif
# This is for quick testing; don't use it in place of proper statistics.
# It may overflow, will fail if the inputs are not identically formatted, etc.
# You may have to scale up the output (perhaps by increasing gamma).
import Image
from sys import argv