Skip to content

Instantly share code, notes, and snippets.

@LongHairedHacker
Last active July 3, 2018 22:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LongHairedHacker/fe144c5c615783969e9e9c1810888364 to your computer and use it in GitHub Desktop.
Save LongHairedHacker/fe144c5c615783969e9e9c1810888364 to your computer and use it in GitHub Desktop.
NOAA APT sync marker finder
#!/usr/bin/env python3
import sys
from PIL import Image
import matplotlib.pyplot as plt
SYNCA_SEQ = [False, False, False, False,
True, True, False, False, # Pulse 1
True, True, False, False, # Pulse 2
True, True, False, False, # Pulse 3
True, True, False, False, # Pulse 4
True, True, False, False, # Pulse 5
True, True, False, False, # Pulse 6
True, True, False, False, # Pulse 7
False, False, False, False,
False, False, False, False];
SYNCB_SEQ = [False, False, False, False,
True, True, True, False, False,
True, True, True, False, False,
True, True, True, False, False,
True, True, True, False, False,
True, True, True, False, False,
True, True, True, False, False,
True, True, True, False, False,
False];
SYNC_LEN = 40
AVERAGE_ALPHA = 0.25
SYNC_THRESH = 35
def match_seq(buff, seq):
pairs = zip(buff, seq)
count = sum([1 if (x > 0 and y) or (x < 0 and not y) else 0 for x,y in pairs])
return count
def main():
img = Image.open(sys.argv[1])
w, h = img.size
img_color = img.convert('RGB')
average = 0
buff = [0.0] * SYNC_LEN
for y in range(0, h):
for x in range(0, w):
cur_pixel = img.getpixel((x,y))
sample = cur_pixel / 255.0
average = AVERAGE_ALPHA * sample + (1.0 - AVERAGE_ALPHA) * average;
sample = sample - average
buff = buff[1:] + [sample]
if match_seq(buff, SYNCA_SEQ) > SYNC_THRESH:
print("A %d %d" % (x,y))
img_color.putpixel((x,y), (255, 0, 0))
elif match_seq(buff, SYNCB_SEQ) > SYNC_THRESH:
img_color.putpixel((x,y), (0, 0, 255))
print("B %d %d" % (x, y))
img_color.save('marked.png')
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment