Skip to content

Instantly share code, notes, and snippets.

@celoyd
Last active June 27, 2023 22:35
Show Gist options
  • Save celoyd/3c21c999348fda2141bc2a4ec668b891 to your computer and use it in GitHub Desktop.
Save celoyd/3c21c999348fda2141bc2a4ec668b891 to your computer and use it in GitHub Desktop.
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
def parse_line(line):
line = line.split(",")
if len(line) < 6:
return None
else:
return {
"time": int(time.mktime(parse_datetime(line[0][:-4]).timetuple())),
"lon": float(line[2]),
"lat": float(line[3]),
}
takeoffs = sorted(
filter(lambda e: e is not None, [parse_line(x) for x in open(argv[1])]),
key=lambda x: x["time"],
)
first_timestep = takeoffs[0]["time"] // timestep
last_timestep = takeoffs[-1]["time"] // timestep
total_timesteps = last_timestep - first_timestep
img = np.zeros((total_timesteps + 1, int(lonsteps * 360)), dtype=np.float32)
for t in takeoffs:
row = int((180 + t["lon"]) * lonsteps)
col = t["time"] // timestep - last_timestep
img[col, row] += 1
img = ((img / np.max(img)) * 255).astype(np.uint8) # FIXME
io.imsave(argv[2], img)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment