Skip to content

Instantly share code, notes, and snippets.

@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
@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
@celoyd
celoyd / BMP085.csv
Created October 16, 2021 22:10
BMP085 output: timestamp, temperature in C, pressure in Pa
1634422106.41013 25.8 101336
1634422103.86678 25.8 101330
1634422101.32353 25.8 101330
1634422098.78481 25.8 101325
1634422096.24276 25.9 101327
1634422093.40026 25.8 101334
1634422090.86181 25.9 101331
1634422088.32217 25.8 101338
1634422085.78382 25.8 101330
1634422083.24592 25.9 101331
@celoyd
celoyd / despeckling.md
Last active September 1, 2021 14:47
Learning to despeckle sar with speckly targets

Learning to despeckle sar with speckly targets

These are notes from a one-day project to test a hunch. The idea is to train a convolutional neural network to remove speckle from sar (synthetic aperture radar) using only one other observation – with its own speckles – as the target. This method does not come close to state of the art despeckling, and can be biased by the skewed distribution of noise in a way that makes it useless for quantitative research. However, I hadn’t noticed it in the literature and I think it’s kind of funny, so I’m writing it up.

Everything here is about Sentinel-1 L1 GRD-HD data, since it’s what I used, since it’s free.

Speckle

Sar observations contain speckle, a form of interference related to the sparkles in reflected laser light. By some definitions speckle is not noise, since it’s physically real outside the sensor and contains information, but we will treat it as noise. Speckle is (close enough to) independent between radar chirps, a.k.a. looks, and even its distributio

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
# Demo a brightened luminance-only inversion on 8-bit images
from skimage import io
import numpy as np
from sys import argv
# RGB <-> YCoCg-R almost straight from Wikipedia
#!/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.

Free Idea: Enhancing Astronaut Photography of Earth

Beta version. May contain bad ideas.

By a free idea I mean something that I think is probably fun and probably possible but that I don’t have the combination of time, skill, energy, patience, etc. to do myself. I hope someone does this. I hope someone reads this and does just the specific part that they’re interested in. I’m trying to get the idea out there without giving the impression that it’s my project. It’s just an idea.

To do the whole thing as laid out here I think you’d need at least an intermediate understanding of convolutional neural networks for image processing, access to a GPU, some sense of geography and astronomy (to gut-check your intermediate results), and a reasonable internet connection to download the images.

The idea

import himawari.HimawariScene as hsd
from sys import argv
import rasterio as rio
import numpy as np
scaleup = 64
scene = hsd.HimawariScene(argv[1])
rad = scene.radiances()