# Path: wwb_scanner/core.py
# class JSONMixin(object):
#     @classmethod
#     def from_json(cls, data, **kwargs):
#         if isinstance(data, basestring):
#             data = json.loads(data)
#         kwargs.update(data)
#         kwargs['__from_json__'] = True
#         obj = cls(**kwargs)
#         obj._deserialize(**kwargs)
#         return obj
#     def instance_from_json(self, data, **kwargs):
#         if isinstance(data, basestring):
#             data = json.loads(data)
#         kwargs.update(data)
#         self._deserialize(**kwargs)
#     def to_json(self, **kwargs):
#         d = self._serialize()
#         return json.dumps(d, **kwargs)
#     def _serialize(self):
#         raise NotImplementedError('method must be implemented by subclasses')
#     def _deserialize(self, **kwargs):
#         pass


import time
import threading
import numpy as np
import logging
from scipy.signal.windows import __all__ as WINDOW_TYPES
from scipy.signal import welch, get_window, hilbert
from wwb_scanner.core import JSONMixin
        xlator.real = np.cos(phase_rot)
        xlator.imag = np.sin(phase_rot)
        samples *= xlator
        return samples
    def process_samples(self):
        rs = self.scanner.sample_rate
        fc = self.center_frequency

        samples = self.raw.flatten()

        win_size = self.window_size
        win = get_window(self.scanner.sampling_config.window_type, win_size)
        freqs, Pxx = welch(samples, fs=rs, window=win, detrend=False,
            nperseg=win_size, scaling='density', return_onesided=False)

        iPxx = np.fft.irfft(Pxx)
        iPxx = self.translate_freq(iPxx, fc, rs)
        Pxx = np.abs(np.fft.rfft(iPxx.real))

        freqs, Pxx = sort_psd(freqs, Pxx)
        freqs = np.around(freqs)

        freqs += fc
        freqs /= 1e6

        self.powers = Pxx
        if not np.array_equal(freqs, self.frequencies):
            logger.warning('freq not equal: %s, %s' % (self.frequencies.size, freqs.size))
            self.frequencies = freqs
        self.raw = None

# Path: wwb_scanner/core.py
# class JSONMixin(object):
#     @classmethod
#     def from_json(cls, data, **kwargs):
#         if isinstance(data, basestring):
#             data = json.loads(data)
#         kwargs.update(data)
#         kwargs['__from_json__'] = True
#         obj = cls(**kwargs)
#         obj._deserialize(**kwargs)
#         return obj
#     def instance_from_json(self, data, **kwargs):
#         if isinstance(data, basestring):
#             data = json.loads(data)
#         kwargs.update(data)
#         self._deserialize(**kwargs)
#     def to_json(self, **kwargs):
#         d = self._serialize()
#         return json.dumps(d, **kwargs)
#     def _serialize(self):
#         raise NotImplementedError('method must be implemented by subclasses')
#     def _deserialize(self, **kwargs):
#         pass


# Path: wwb_scanner/scanner/sample_processing.py
import time
import threading
import numpy as np
import logging
from scipy.signal.windows import __all__ as WINDOW_TYPES
from scipy.signal import welch, get_window, hilbert
from wwb_scanner.core import JSONMixin

        xlator.real = np.cos(phase_rot)
        xlator.imag = np.sin(phase_rot)
        samples *= xlator
        return samples
    def process_samples(self):
        rs = self.scanner.sample_rate
        fc = self.center_frequency

        samples = self.raw.flatten()

        win_size = self.window_size
        win = get_window(self.scanner.sampling_config.window_type, win_size)
        freqs, Pxx = welch(samples, fs=rs, window=win, detrend=False,
            nperseg=win_size, scaling='density', return_onesided=False)

        iPxx = np.fft.irfft(Pxx)
        iPxx = self.translate_freq(iPxx, fc, rs)
        Pxx = np.abs(np.fft.rfft(iPxx.real))

        freqs, Pxx = sort_psd(freqs, Pxx)
        freqs = np.around(freqs)

        freqs += fc
        freqs /= 1e6

        self.powers = Pxx
        if not np.array_equal(freqs, self.frequencies):
            logger.warning('freq not equal: %s, %s' % (self.frequencies.size, freqs.size))
            self.frequencies = freqs
        self.raw = None

        self.collection.on_sample_set_processed(self)