from astropy.io import fits
from astropy.time import Time
import glob

from utils.analysis import fit_star

filenames = glob.glob("../arp/arp.CLEAN*fits")
filenames.sort()

start = Time.now()

params1 = []
params2 = []
mjd = []

for f in filenames:

    data = fits.getdata(f)
    mjd.append(fits.getheader(f)["MJD-OBS"])
    
    data1 = data[data.shape[1]//2-20:data.shape[1]//2+20, data.shape[0]//2-20:data.shape[0]//2+20]
    p1 = fit_star(data1, display=False)
    params1.append(p1)
    
    data2 = data[2106-20:2106+20, 3293-20:3292+20]
    p2 = fit_star(data2, display=False)
    params2.append(p2)
    
print((Time.now()-start).to("second"))


import gnuplotlib as gp
import numpy as np

peak1 = [p.peak for p in params1]
peak2 = [p.peak for p in params2]

gp.plot(np.array(mjd), np.array(peak2)/np.array(peak1), terminal="x11 1")
