Skip to content

Instantly share code, notes, and snippets.

# 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
@celoyd
celoyd / t.py
Last active October 2, 2018 23:36
A simple, mostly-not-mine Twitter stream consumer and s3 bucketer
#!/usr/bin/env python
'''
This code is adapted from the consensus best practice python Twitter feed
consumer that's been floating around for a while now on StackOverflow etc.
My only addition to speak of is TenminWriter. (A "tenmin" is ten minutes
worth of stream. It's just a convenient chunk; you might want to make it
shorter or longer.)
THERE ARE BUGS HERE. THIS IS BARELY TESTED. DO NOT TRUST IT.
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

I've rendered out two map layers with pre-typhoon Landsat 8 imagery. This is very low resolution (15 m) but may help fill in major highways and rivers for areas that still lack better coverage. They include clouds because I found that splicing them together can introduce seam artifacts that could be mistaken for roads.

The layer templates are:

@celoyd
celoyd / ndvi.py
Last active October 4, 2022 11:03
#!/usr/bin/env python
# ndvi.py red.tif nir.tif output-ndvi.tif
# Calculate NDVI (see Wikipedia). Assumes atmospheric correction.
# (Although I use it without all the time for quick experiments.)
import numpy as np
from sys import argv
from osgeo import gdal, gdalconst
traceroute to www.e-kyzylorda.gov.kz (92.46.237.194), 64 hops max, 52 byte packets
1 192.168.1.1 (192.168.1.1) 3.980 ms 0.825 ms 0.732 ms
2 192.168.0.1 (192.168.0.1) 6.564 ms 3.823 ms 2.980 ms
3 ptld-dsl-gw48.ptld.qwest.net (207.225.84.48) 21.866 ms 22.800 ms 21.859 ms
4 ptld-agw1.inet.qwest.net (207.225.86.121) 28.812 ms 21.379 ms 21.606 ms
5 sea-brdr-02.inet.qwest.net (67.14.41.18) 24.620 ms 25.222 ms 27.285 ms
6 ae14.edge2.seattle1.level3.net (4.68.62.189) 24.411 ms 27.195 ms 28.180 ms
7 ae-32-52.ebr2.seattle1.level3.net (4.69.147.182) 377.227 ms 213.377 ms 579.056 ms
8 ae-2-2.ebr2.denver1.level3.net (4.69.132.54) 417.806 ms 218.987 ms 375.214 ms
9 ae-3-3.ebr1.chicago2.level3.net (4.69.132.62) 273.500 ms 248.338 ms 626.253 ms