# Path: wwb_scanner/scan_objects/spectrum.py
# def compare_spectra(spec1, spec2):
#     diff_spec = Spectrum()
#     for sample in spec1.iter_samples():
#         other_sample = spec2.samples.get(sample.frequency)
#         if other_sample is None:
#             continue
#         magnitude = sample.magnitude - other_sample.magnitude
#         diff_spec.add_sample(frequency=sample.frequency, magnitude=magnitude)
#     return diff_spec
# 
# Path: wwb_scanner/file_handlers/importers.py
# class BaseImporter(object):
#     def __init__(self, **kwargs):
#         self.spectrum = Spectrum()
#         self.filename = kwargs.get('filename')
#     @classmethod
#     def import_file(cls, filename):
#         ext = os.path.splitext(filename)[1].strip('.').lower()
#         def find_importer(_cls):
#             if getattr(_cls, '_extension', None) == ext:
#                 return _cls
#             for _subcls in _cls.__subclasses__():
#                 r = find_importer(_subcls)
#                 if r is not None:
#                     return r
#             return None
#         cls = find_importer(BaseImporter)
#         fh = cls(filename=filename)
#         return fh()
#     def __call__(self):
#         self.file_data = self.load_file()
#         self.parse_file_data()
#         return self.spectrum
#     def load_file(self):
#         with open(self.filename, 'r') as f:
#             s = f.read()
#         return s
#     def parse_file_data(self):
#         raise NotImplementedError('Method must be implemented by subclasses')


import numpy as np
import matplotlib.pyplot as plt
from wwb_scanner.scan_objects.spectrum import compare_spectra
from wwb_scanner.file_handlers import BaseImporter
        self.plot.set_ydata(y)
        #self.figure.canvas.draw_event(self.figure.canvas)
        self.figure.canvas.draw_idle()
    def build_plot(self):
        pass

class SpectrumPlot(BasePlot):
    def build_plot(self):
        self.figure = plt.figure()
        self.plot = plt.plot(*self.build_data())[0]
        plt.xlabel('frequency (MHz)')
        plt.ylabel('dBm')
        center_frequencies = self.spectrum.center_frequencies
        if len(center_frequencies):
            samples = [self.spectrum.samples.get(f) for f in center_frequencies]
            ymin = self.y.min()
            plt.vlines(center_frequencies,
                       [ymin] * len(center_frequencies),
                       [s.magnitude-5 if s.magnitude-5 > ymin else s.magnitude for s in samples])
        plt.show()

class DiffSpectrum(object):
    def __init__(self, **kwargs):
        self.spectra = []
        self.figure, self.axes = plt.subplots(3, 1, sharex='col')
    def add_spectrum(self, spectrum=None, **kwargs):
        name = kwargs.get('name')
        if name is None:
            name = str(len(self.spectra))
        if spectrum is None:

# Path: wwb_scanner/scan_objects/spectrum.py
# def compare_spectra(spec1, spec2):
#     diff_spec = Spectrum()
#     for sample in spec1.iter_samples():
#         other_sample = spec2.samples.get(sample.frequency)
#         if other_sample is None:
#             continue
#         magnitude = sample.magnitude - other_sample.magnitude
#         diff_spec.add_sample(frequency=sample.frequency, magnitude=magnitude)
#     return diff_spec
# 
# Path: wwb_scanner/file_handlers/importers.py
# class BaseImporter(object):
#     def __init__(self, **kwargs):
#         self.spectrum = Spectrum()
#         self.filename = kwargs.get('filename')
#     @classmethod
#     def import_file(cls, filename):
#         ext = os.path.splitext(filename)[1].strip('.').lower()
#         def find_importer(_cls):
#             if getattr(_cls, '_extension', None) == ext:
#                 return _cls
#             for _subcls in _cls.__subclasses__():
#                 r = find_importer(_subcls)
#                 if r is not None:
#                     return r
#             return None
#         cls = find_importer(BaseImporter)
#         fh = cls(filename=filename)
#         return fh()
#     def __call__(self):
#         self.file_data = self.load_file()
#         self.parse_file_data()
#         return self.spectrum
#     def load_file(self):
#         with open(self.filename, 'r') as f:
#             s = f.read()
#         return s
#     def parse_file_data(self):
#         raise NotImplementedError('Method must be implemented by subclasses')


# Path: wwb_scanner/ui/plots.py
import numpy as np
import matplotlib.pyplot as plt
from wwb_scanner.scan_objects.spectrum import compare_spectra
from wwb_scanner.file_handlers import BaseImporter

        self.plot.set_ydata(y)
        #self.figure.canvas.draw_event(self.figure.canvas)
        self.figure.canvas.draw_idle()
    def build_plot(self):
        pass

class SpectrumPlot(BasePlot):
    def build_plot(self):
        self.figure = plt.figure()
        self.plot = plt.plot(*self.build_data())[0]
        plt.xlabel('frequency (MHz)')
        plt.ylabel('dBm')
        center_frequencies = self.spectrum.center_frequencies
        if len(center_frequencies):
            samples = [self.spectrum.samples.get(f) for f in center_frequencies]
            ymin = self.y.min()
            plt.vlines(center_frequencies,
                       [ymin] * len(center_frequencies),
                       [s.magnitude-5 if s.magnitude-5 > ymin else s.magnitude for s in samples])
        plt.show()

class DiffSpectrum(object):
    def __init__(self, **kwargs):
        self.spectra = []
        self.figure, self.axes = plt.subplots(3, 1, sharex='col')
    def add_spectrum(self, spectrum=None, **kwargs):
        name = kwargs.get('name')
        if name is None:
            name = str(len(self.spectra))
        if spectrum is None:

            spectrum = BaseImporter.import_file(kwargs.get('filename'))