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')) self.spectra.append({'name':name, 'spectrum':spectrum})
def test_importers(data_files): from wwb_scanner.file_handlers import BaseImporter spec = {} for fkey, d in data_files.items(): if fkey not in spec: spec[fkey] = {} for skey, fn in d.items(): spectrum = BaseImporter.import_file(fn) spec[fkey][skey] = spectrum for fkey, d in spec.items(): start_freq, end_freq = fkey for spectrum in d.values(): freqs = spectrum.sample_data['frequency'] assert freqs.min() <= start_freq assert freqs.max() >= end_freq assert not np.any(np.isnan(spectrum.sample_data['magnitude'])) assert not np.any(np.isnan(spectrum.sample_data['dbFS']))
def test_dbstore(tmp_db_store, data_files, random_samples): from wwb_scanner.file_handlers import BaseImporter from wwb_scanner.scan_objects import Spectrum from wwb_scanner.utils.dbstore import db_store spec = {} for fkey, d in data_files.items(): for skey, fn in d.items(): spectrum = BaseImporter.import_file(fn) spectrum.save_to_dbstore() assert spectrum.eid is not None spec[spectrum.eid] = spectrum rs = 1.024e6 nsamp = 256 step_size = 0.5e6 freq_range = [572e6, 636e6] spectrum = Spectrum() fc = freq_range[0] while True: freqs, sig, Pxx = random_samples(n=nsamp, rs=rs, fc=fc) spectrum.add_sample_set(frequency=freqs, iq=Pxx) if spectrum.sample_data['frequency'].max() >= freq_range[1] / 1e6: break fc += step_size spectrum.save_to_dbstore() assert spectrum.eid is not None spec[spectrum.eid] = spectrum for eid, spectrum in spec.items(): db_spectrum = Spectrum.from_dbstore(eid=spectrum.eid) for attr in Spectrum._serialize_attrs: assert getattr(spectrum, attr) == getattr(db_spectrum, attr) assert np.array_equal(spectrum.sample_data, db_spectrum.sample_data) db_data = db_store.get_all_scans() assert set(db_data.keys()) == set(spec.keys())
def __init__(self, **kwargs): self.filename = kwargs.get('filename') if self.filename is not None: self.spectrum = BaseImporter.import_file(self.filename) else: self.spectrum = kwargs.get('spectrum')
def load_from_file(self, uri): filename = uri.toLocalFile() spectrum = BaseImporter.import_file(filename) spectrum.set_data_updated() self.spectrum = spectrum self.update_spectrum_data()
def on_browser_success(self, instance): filename = instance.selection[0] self.dismiss() spectrum = BaseImporter.import_file(filename) self.app.root.plot_container.add_plot(spectrum=spectrum, filename=filename)