from extractors import Rect_Evaluator
from plotter import Plotter
import numpy as np
import matplotlib.pyplot as plt
from spin_image import SpinImage
from lattices import SCC_Lattice, VO2_Lattice
import logging
logger = logging.getLogger('fft')
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter(
    '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)


def test_scc():
    LEN = 40
    #scc = SCC_Lattice(LEN, LEN)
    scc = VO2_Lattice(LEN, LEN)
    phases = scc.get_phases()
    logger.info(f"Phases: {phases}")
    si = SpinImage(phases)
    re = Rect_Evaluator(scc.get_spots())
    si.apply_mask(scc.parse_mask(np.ones((LEN, LEN))))
    si.gaussian(20)
    fft = si.fft()
    fft.clean()

    re.generate_mask(fft, merge=True)

    fig, axs = plt.subplots(3, 2)
    plot = Plotter(scc)
    plot.plot_spins(si, ax_lin=axs[0, 0])
    #plot.plot_fft(fft, ax_lin=axs[1, 0], ax_log=axs[2, 0])
    plot.plot_fft(fft, ax_lin=axs[1, 0], ax_log=axs[2, 0], evaluator=re)
    plt.show()


test_scc()
plt.show()
