Skip to content

Instantly share code, notes, and snippets.

@Cadair
Created September 16, 2022 15:00
Show Gist options
  • Save Cadair/f1bbefe959eff21212945c5784d4be19 to your computer and use it in GitHub Desktop.
Save Cadair/f1bbefe959eff21212945c5784d4be19 to your computer and use it in GitHub Desktop.
import os
os.environ["QT_QPA_PLATFORM"] = "wayland"
from tqdm import tqdm
from pathlib import Path
from itertools import groupby
import numpy as np
import sunpy.map
from sunpy.coordinates import Helioprojective
import matplotlib.pyplot as plt
from reproject import reproject_interp
from reproject.mosaicking import reproject_and_coadd
files = list(sorted(Path("/home/stuart/Downloads/L2/20220402/").glob("*.fits")))
# Split out the tile number from the filename.
# It's almost certainly cleaner to get this out of the header, but I was being lazy.
tiled_files = {k: list(v) for k, v in (groupby(files, lambda k: int(str(k).split("-")[1].split("_")[0][0])))}
# Which tile do we reproject all the others to?
reference_index = 3
stiched_maps = []
for tiles in tqdm(list(zip(*tiled_files.values()))[:50:10]):
maps = sunpy.map.Map(tiles)
with Helioprojective.assume_spherical_screen(center=maps[reference_index].observer_coordinate):
data, footpoint = reproject_and_coadd(maps,
maps[reference_index].wcs,
shape_out=np.array(maps[reference_index].data.shape)*2,
reproject_function=reproject_interp)
output_map = sunpy.map.Map(data, maps[reference_index].wcs)
output_map.meta = maps[reference_index].meta
stiched_maps.append(output_map)
seq = sunpy.map.Map(stiched_maps, sequence=True)
fig = plt.figure(figsize=(10,10))
ani = seq.peek(fig=fig)
plt.show()
@hayesla
Copy link

hayesla commented Sep 16, 2022

this makes me so happy how straight forward it looks

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