Skip to content

Instantly share code, notes, and snippets.

View celoyd's full-sized avatar

Charlie Loyd celoyd

View GitHub Profile
from __future__ import division
from skbio.diversity.alpha import simpson
import rasterio as rio
from sys import argv
import numpy as np
import affine
scale = 20
#!/usr/bin/env python
# Reeeeallly simple 4:1 un-Bayer for the Chang'e
# mosaicked PNGs posted here:
# http://planetary.s3.amazonaws.com/data/change3/tcam.html
# See also:
# http://www.planetary.org/blogs/emily-lakdawalla/2016/01281656-fun-with-a-new-data-set-change.html
# Usage: python demosaic.py TCAM-[...].png x.png
#!/usr/bin/env zsh
# ./day.sh month_number morning_day evening_day zoom_level
# Strictly alpha: for example, does not know how to handle
# month edges or unscheduled missing images.
set -eu
year=$1
from skimage import io, filters
import numpy as np
import sys
# ./hi8-deband.py input.png output.png
# Cherrypicked sample before/after: http://basecase.org/2016/1/hi8corr
'''
Himawari-8 has slight noise along scanlines. It seems basically uncorrelated
between rows, and varies smoothly on the scale of about 100 columns.
@celoyd
celoyd / hi8-fetch.py
Last active August 8, 2023 05:05
Fetch and untile tiled Himawari-8 images from the http://himawari8.nict.go.jp PNG endpoint
import requests as req
import sys
from dateutil.parser import parse
from PIL import Image
from StringIO import StringIO
# hi8-fetch.py <date> <zoom level> <output>
# E.g.: hi8-fetch.py 2016-01-13T22:10:00 8 2016-01-13T221000-z8.png
# Fetch Himawari-8 full disks at a given zoom level.
# Valid zoom levels seem to be powers of 2, 1..16, and 20.
#!/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:]
# python pca_multiband.py input.jpeg output.tif
# n-band image -> PCA -> n-band TIFF image
# with lots of hackety assumptions
# (e.g., output is same type as input)
from sys import argv
import rasterio as rio
import numpy as np
from sklearn import decomposition
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],
@celoyd
celoyd / hi8-anim-howto.md
Last active August 1, 2022 15:37
A way to make Himawari-8 animations

Himawari-8 animation tutorial

Here’s how to make animations like this one. It requires intermediate Unix command-line knowledge, to install some tools and to debug if they don’t work. You’ll need these utilities:

  • curl (or you can translate to wget)
  • convert and montage, part of ImageMagick
  • ffmpeg, plus whatever codecs
  • parallel, for iteration that’s nicer than shell for loops or xargs
  • run everything in zsh for leading 0s in numerical ranges to work
#!/usr/bin/env python
'''
Makes template filenames for interpolating Himawari-8 data.
Assumes filenames like "2015-11-28T023500.png".
I do this: python betwixt.py day-color | parallel --colsep ' ' convert -average {1} {2} {3}
'''
import os
import sys