Skip to content

Instantly share code, notes, and snippets.

@celoyd
celoyd / antisdpa.md
Last active July 31, 2025 06:27
The usual implementaiton of attention transformers (SDPA) is kind of bad, actually

Introduction

I was writing a note to a friend that mentioned my tedious opinions on “AI” discourse. It veered off into my usual argument that big “AI” companies are shaping the industry ecosystem to their own ends by setting up a situation where expensive-to-run models are overvalued. I think they’re doing this because they have a competitive advantage in that tier of the market, having bought (time on) a lot of GPUs. It’s like how a company that owns diamond mines will probably promote the idea that large, mined diamonds are important and valuable, and that there’s something off about running a sub-industrial mine or lab-growing diamonds. You can do this without lying at all, but I still dislike it. Large mined diamonds here are $O(n^2)$ models.

To support this argument, I started making my case against the necessity of the standard transformer model. I admit that the case is scattershot and circumstantial. It’s not that SDPA (the normal transformer architecture) is a fraud, or that there is something m

@celoyd
celoyd / slitscan.py
Last active October 27, 2024 20:19
Simple but reasonably flexible
#!/usr/bin/env python
"""Simple slitscan generator
$ slitscan.py source slice destination
Where:
- source is a video or a directory of images;
- slice is either "c" for column or "r" for row
and an integer, e.g., r1 or c42; and
from skimage import io
from pathlib import Path
from sys import argv
srtm_dir = Path(argv[1])
width = 3601 # pixel width of one of these srtm tiffs
starting_lon = -2
ending_lon = 143

Notes on a big SAR swath

Introduction

I just had a big mug of coffee and now I have some black tea and here is a slapdash devlog about a “A lightly annotated SAR view from Los Angeles to Woss”.

Summary

This is basically a combination of several conversations I’ve had with friends about different aspects of the project.

@celoyd
celoyd / howto.md
Last active September 15, 2023 17:04
A little CLI workflow for visualizing OSM tile traffic data

This is how to make animations like this (alternate), inspired by Paul Norman’s. This is a write-up of a one-off 45 minute project, so it’s rough around the edges and probably has a few typos; feel free to point them out. It’s mostly command-line work, using tools like GNU parallel and ImageMagick convert; it’s slow and wastes a lot of filesystem space compared to a more monolithic approach in (say) python, but it’s very flexible.

1. Get data

I use curl globs, for example:

mkdir xzs
cd xzs
curl -O 'https://planet.openstreetmap.org/tile_logs/tiles-2022-[01-12]-[01-31].txt.xz'
@celoyd
celoyd / draw_osm_day.py
Last active September 14, 2023 21:38
Draw an OSM daily aggregate tile traffic log to an image (proof of concept quality)
"""
draw_osm_day.py osm_tile_traffic_file.txt output_image.tiff
Write a float32 TIFF representing tile traffic in the OSM aggregate log.
Charlie Loyd, 2023-09-14. Inspired by https://en.osm.town/@pnorman/111062780453196500.
I recommend downloading the .xz compressed files and using xzcat to feed
them to this script. (Doing xz decompression in-script was slow.) E.g.,

Dear Ms Liang,

I am an Oakland resident and a past and future user of OAK.

I want a plan to make OAK a source of local pride and global leadership in responding to the climate crisis. That is not the plan on the table today. This plan only gestures at the climate crisis and aviation’s role in it, and invests nothing serious to help solve it. In fact, what’s proposed would make OAK an increasing part of the problem for years to come.

The plan is insufficient to our moment. I oppose it firmly enough to invest my personal time and resources to publicly work against it.

I hope you will reconsider and submit a better plan. I would expect it to start from the principle that any change to OAK must make it responsible for less CO2e emission. That is, the net climate impact of the airport, calculated globally and not just to the mixing level, and operating as designed, must be at worst steady.

import numpy as np
from skimage import io
import time
import datetime
from ciso8601 import parse_datetime
from sys import argv
timestep = 60 # in seconds
lonsteps = 1 # pixels per degree, i.e., 1 means an image 360 wide, 2 means 720
@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