Skip to content

Instantly share code, notes, and snippets.

@PetteriAimonen
Created November 8, 2022 10:56
Show Gist options
  • Save PetteriAimonen/b83ed3cc1b5e087c4aac23af61ca7f11 to your computer and use it in GitHub Desktop.
Save PetteriAimonen/b83ed3cc1b5e087c4aac23af61ca7f11 to your computer and use it in GitHub Desktop.
Python script to combine eclipse images
#!/usr/bin/env python3
# Usage: python combine.py SEatlas*.GIF
# Images from https://eclipse.gsfc.nasa.gov/SEatlas/SEatlas.html
import sys
from PIL import Image
import numpy as np
images = [Image.open(filename).convert('RGB') for filename in sys.argv[1:]]
result = images[0].copy()
def palette(i):
return (255 - i * 5, 255 - i * 5, i * 5)
for y in range(126, 1234):
if (y % 10) == 0: print(y)
for x in range(160, 1863):
result.putpixel((x, y), (204, 204, 255))
for i in range(len(images)):
p = images[i].getpixel((x, y))
if p == (76, 76, 255):
result.putpixel((x, y), palette(i))
break
elif p == (153, 255, 153):
result.putpixel((x, y), (153, 255, 153))
for x in range(0, 1900):
for y in range(1290, 1330):
result.putpixel((x, y), (153, 153, 255))
for i in range(50):
for dx in range(20):
for dy in range(20):
result.putpixel((100 + dx + i * 25, 1300 + dy), palette(i))
result.save('output.png')
@PetteriAimonen
Copy link
Author

The NASA solar eclipse map files available as easier download: https://jpa.kapsi.fi/stuff/other/NASA_SEatlas_maps.zip

@PetteriAimonen
Copy link
Author

Modified version to count number of eclipses:

#!/usr/bin/env python3
# Usage: python combine.py SEatlas*.GIF
# Images from https://eclipse.gsfc.nasa.gov/SEatlas/SEatlas.html

import sys
from PIL import Image
import numpy as np


images = [Image.open(filename).convert('RGB') for filename in sys.argv[1:]]

result = images[0].copy()

def palette(i):
    if i == 0:
        return (0, 0, 0)
    else:
        return (i * 40, i * 40, i * 40)

for y in range(126, 1234):
    if (y % 10) == 0: print(y)
    for x in range(160, 1863):
        
        result.putpixel((x, y), (204, 204, 255))
        count = 0
        
        for i in range(len(images)):
            p = images[i].getpixel((x, y))

            if p == (76, 76, 255):
                count += 1
        
        if count > 6: count = 6
        result.putpixel((x, y), palette(count))

for x in range(0, 1900):
    for y in range(1290, 1330):
        result.putpixel((x, y), (153, 153, 255))

for i in range(7):
    for dx in range(20):
        for dy in range(20):
            result.putpixel((100 + dx + i * 25, 1300 + dy), palette(i))

result.save('output3.png')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment