Created
January 5, 2023 09:00
-
-
Save cbassa/255fc345a48df0a9ede978de9a3c6c27 to your computer and use it in GitHub Desktop.
Create a keogram for 24h of images
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import sys | |
import tqdm | |
from pathlib import Path | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import astropy.units as u | |
from astropy.time import Time | |
if __name__ == "__main__": | |
p = Path(".") | |
date = sys.argv[1] | |
fpaths = list(p.glob(f"../**/{date}T??:??:??.???.jpg")) | |
tstr = [fpath.name.replace(".jpg", "") for fpath in fpaths] | |
t = Time(tstr, format="isot", scale="utc") | |
idx = np.argsort(t.mjd) | |
nfiles = len(t) | |
for i in tqdm.tqdm(range(nfiles)): | |
fname = fpaths[idx[i]] | |
try: | |
img = plt.imread(fname) | |
ny, nx, nz = img.shape | |
if i == 0: | |
raw_keogram = np.zeros(ny * nfiles * nz).reshape(ny, nfiles, nz).astype(img.dtype) | |
raw_keogram[:, i, :] = img[:, nx // 2, :] | |
except: | |
print(f"Error processing {fname}") | |
pass | |
plt.imsave(f"raw_{date}.png", raw_keogram) | |
tplots = Time(f"{date}T00:00:30", format="isot", scale="utc") + np.arange(1440) * u.min | |
keogram = np.zeros(ny * 1440 * nz).reshape(ny, 1440, nz).astype(img.dtype) | |
for i, tplot in enumerate(tqdm.tqdm(tplots)): | |
dt = t[idx] - tplot | |
c = np.abs(dt.to(u.s).value) < 30 | |
if np.sum(c) > 0: | |
mean = np.mean(raw_keogram[:, c, :], axis=1) | |
keogram[:, i, :] = mean | |
plt.imsave(f"keogram_{date}.png", keogram) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment