Ejemplo n.º 1
0
 def set_plot(self, spectrum, annotate):
     if len(spectrum) > 0:
         total = count_points(spectrum)
         if total > 0:
             spectrum = sort_spectrum(spectrum)
             extent = Extent(spectrum)
             self.graph.set_plot(spectrum, self.settings.pointsLimit, self.settings.pointsMax, extent, annotate)
Ejemplo n.º 2
0
    def __spectrum_range(self, start, end):
        sweeps = {}
        for timeStamp, sweep in self.spectrum.items():
            if start <= timeStamp <= end:
                sweeps[timeStamp] = sweep

        self.sweeps = sort_spectrum(sweeps)
Ejemplo n.º 3
0
    def __spectrum_range(self, start, end):
        sweeps = {}
        for timeStamp, sweep in self.spectrum.items():
            if start <= timeStamp <= end:
                sweeps[timeStamp] = sweep

        self.sweeps = sort_spectrum(sweeps)
Ejemplo n.º 4
0
    def __init__(self, parent, spectrum, settings):
        self.spectrum = sort_spectrum(spectrum)
        self.settings = settings
        self.smoothed = None

        wx.Dialog.__init__(self, parent=parent, title='Smooth Spectrum')

        self.queue = Queue.Queue()
        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.__on_timer, self.timer)
        self.timer.Start(self.POLL)

        self.figure = matplotlib.figure.Figure(facecolor='white')
        self.canvas = FigureCanvas(self, -1, self.figure)
        settings = copy.copy(settings)
        settings.plotFunc = PlotFunc.NONE
        self.plot = Plotter(self.queue, self.figure, settings)

        textFunc = wx.StaticText(self, label='Window function')
        self.choiceFunc = wx.Choice(self, choices=WINFUNC[::2])
        self.choiceFunc.SetSelection(WINFUNC[::2].index(settings.smoothFunc))

        textRatio = wx.StaticText(self, label='Smoothing')
        self.slideRatio = wx.Slider(self, value=settings.smoothRatio,
                                    minValue=2, maxValue=100,
                                    style=wx.SL_INVERSE)

        buttonSmooth = wx.Button(self, label='Smooth')
        self.Bind(wx.EVT_BUTTON, self.__on_smooth, buttonSmooth)

        sizerButtons = wx.StdDialogButtonSizer()
        self.buttonOk = wx.Button(self, wx.ID_OK)
        self.buttonOk.Disable()
        buttonCancel = wx.Button(self, wx.ID_CANCEL)
        sizerButtons.AddButton(self.buttonOk)
        sizerButtons.AddButton(buttonCancel)
        sizerButtons.Realize()
        self.Bind(wx.EVT_BUTTON, self.__on_ok, self.buttonOk)

        sizerGrid = wx.GridBagSizer(5, 5)
        sizerGrid.Add(self.canvas, pos=(0, 0), span=(10, 6),
                      flag=wx.EXPAND | wx.ALL, border=5)
        sizerGrid.Add(textFunc, pos=(0, 6),
                      flag=wx.ALL, border=5)
        sizerGrid.Add(self.choiceFunc, pos=(1, 6), span=(1, 2),
                      flag=wx.EXPAND | wx.ALL, border=5)
        sizerGrid.Add(textRatio, pos=(2, 6),
                      flag=wx.ALL, border=5)
        sizerGrid.Add(self.slideRatio, pos=(3, 6), span=(1, 2),
                      flag=wx.EXPAND | wx.ALL, border=5)
        sizerGrid.Add(buttonSmooth, pos=(4, 6), span=(1, 2),
                      flag=wx.ALL | wx.ALIGN_CENTRE, border=5)
        sizerGrid.Add(sizerButtons, pos=(10, 6), span=(1, 2),
                      flag=wx.ALIGN_RIGHT | wx.ALL, border=5)

        self.SetSizerAndFit(sizerGrid)

        self.__draw_plot(self.spectrum)
Ejemplo n.º 5
0
def export_plot(dirname, filename, exportType, spectrum):
    spectrum = sort_spectrum(spectrum)
    handle = open(os.path.join(dirname, filename), 'wb')
    if exportType == File.PlotType.CSV:
        export_csv(handle, spectrum)
    elif exportType == File.PlotType.GNUPLOT:
        export_plt(handle, spectrum)
    elif exportType == File.PlotType.FREEMAT:
        export_freemat(handle, spectrum)
    handle.close()
Ejemplo n.º 6
0
 def __set_plot(self, spectrum, annotate):
     if len(spectrum) > 0:
         total = count_points(spectrum)
         if total > 0:
             spectrum = sort_spectrum(spectrum)
             extent = Extent(spectrum)
             self.graph.set_plot(spectrum, self.settings.pointsLimit,
                                 self.settings.pointsMax, extent, annotate)
     else:
         self.graph.clear_plots()
Ejemplo n.º 7
0
def export_plot(filename, exportType, spectrum):
    spectrum = sort_spectrum(spectrum)
    handle = open(filename, 'wb')
    if exportType == File.PlotType.CSV:
        export_csv(handle, spectrum)
    elif exportType == File.PlotType.GNUPLOT:
        export_plt(handle, spectrum)
    elif exportType == File.PlotType.FREEMAT:
        export_freemat(handle, spectrum)
    elif exportType == File.PlotType.WWB:
        export_wwb(handle, spectrum)
    handle.close()
Ejemplo n.º 8
0
def open_plot(dirname, filename):
    pickle = True
    error = False
    dwell = 0.131
    nfft = 1024
    name = None
    gain = None
    lo = None
    calibration = None
    tuner = 0
    spectrum = OrderedDict()
    time = None
    lat = None
    lon = None
    desc = ''
    location = OrderedDict()

    path = os.path.join(dirname, filename)
    if not os.path.exists(path):
        return None, None, None
    handle = open(path, 'rb')
    try:
        header = cPickle.load(handle)
    except cPickle.UnpicklingError:
        pickle = False
    except EOFError:
        pickle = False

    if pickle:
        try:
            _version = cPickle.load(handle)
            start = cPickle.load(handle)
            stop = cPickle.load(handle)
            spectrum[1] = {}
            spectrum[1] = cPickle.load(handle)
        except pickle.PickleError:
            error = True
    else:
        try:
            handle.seek(0)
            data = json.loads(handle.read())
            header = data[0]
            version = data[1]['Version']
            start = data[1]['Start']
            stop = data[1]['Stop']
            if version > 1:
                dwell = data[1]['Dwell']
                nfft = data[1]['Nfft']
            if version > 2:
                name = data[1]['Device']
                gain = data[1]['Gain']
                lo = data[1]['LO']
                calibration = data[1]['Calibration']
            if version > 4:
                tuner = data[1]['Tuner']
            if version > 5:
                time = data[1]['Time']
                lat = data[1]['Latitude']
                lon = data[1]['Longitude']
            if version < 7:
                spectrum[1] = {}
                for f, p in data[1]['Spectrum'].iteritems():
                    spectrum[1][float(f)] = p
            else:
                for t, s in data[1]['Spectrum'].iteritems():
                    spectrum[float(t)] = {}
                    for f, p in s.iteritems():
                        spectrum[float(t)][float(f)] = p
            if version > 7:
                desc = data[1]['Description']
            if version > 8:
                location = {}
                for t, l in data[1]['Location'].iteritems():
                    location[float(t)] = l

        except ValueError:
            error = True
        except KeyError:
            error = True

    handle.close()

    if error or header != File.HEADER:
        wx.MessageBox('Invalid or corrupted file', 'Warning',
                      wx.OK | wx.ICON_WARNING)
        return None, None, None

    scanInfo = ScanInfo()
    scanInfo.start = start
    scanInfo.stop = stop
    scanInfo.dwell = dwell
    scanInfo.nfft = nfft
    scanInfo.name = name
    scanInfo.gain = gain
    scanInfo.lo = lo
    scanInfo.calibration = calibration
    scanInfo.tuner = tuner
    scanInfo.time = time
    scanInfo.lat = lat
    scanInfo.lon = lon
    scanInfo.desc = desc

    spectrum = sort_spectrum(spectrum)

    return scanInfo, spectrum, location
Ejemplo n.º 9
0
 def __open(self, dirname, filename):
     _info, spectrum, _locs = open_plot(dirname, filename)
     self.directory = dirname
     self.__plot(sort_spectrum(spectrum))
     vv.title(filename)
Ejemplo n.º 10
0
def open_plot(dirname, filename):
    pickle = True
    error = False
    dwell = 0.131
    nfft = 1024
    name = None
    gain = None
    lo = None
    calibration = None
    tuner = 0
    spectrum = OrderedDict()
    time = None
    lat = None
    lon = None
    desc = ''
    location = OrderedDict()

    path = os.path.join(dirname, filename)
    if not os.path.exists(path):
        return None, None, None
    handle = open(path, 'rb')
    try:
        header = cPickle.load(handle)
    except cPickle.UnpicklingError:
        pickle = False
    except EOFError:
        pickle = False

    if pickle:
        try:
            _version = cPickle.load(handle)
            start = cPickle.load(handle)
            stop = cPickle.load(handle)
            spectrum[1] = {}
            spectrum[1] = cPickle.load(handle)
        except pickle.PickleError:
            error = True
    else:
        try:
            handle.seek(0)
            data = json.loads(handle.read())
            header = data[0]
            version = data[1]['Version']
            start = data[1]['Start']
            stop = data[1]['Stop']
            if version > 1:
                dwell = data[1]['Dwell']
                nfft = data[1]['Nfft']
            if version > 2:
                name = data[1]['Device']
                gain = data[1]['Gain']
                lo = data[1]['LO']
                calibration = data[1]['Calibration']
            if version > 4:
                tuner = data[1]['Tuner']
            if version > 5:
                time = data[1]['Time']
                lat = data[1]['Latitude']
                lon = data[1]['Longitude']
            if version < 7:
                spectrum[1] = {}
                for f, p in data[1]['Spectrum'].iteritems():
                    spectrum[1][float(f)] = p
            else:
                for t, s in data[1]['Spectrum'].iteritems():
                    spectrum[float(t)] = {}
                    for f, p in s.iteritems():
                        spectrum[float(t)][float(f)] = p
            if version > 7:
                desc = data[1]['Description']
            if version > 8:
                location = {}
                for t, l in data[1]['Location'].iteritems():
                    location[float(t)] = l

        except ValueError:
            error = True
        except KeyError:
            error = True

    handle.close()

    if error or header != File.HEADER:
        wx.MessageBox('Invalid or corrupted file', 'Warning',
                      wx.OK | wx.ICON_WARNING)
        return None, None, None

    scanInfo = ScanInfo()
    scanInfo.start = start
    scanInfo.stop = stop
    scanInfo.dwell = dwell
    scanInfo.nfft = nfft
    scanInfo.name = name
    scanInfo.gain = gain
    scanInfo.lo = lo
    scanInfo.calibration = calibration
    scanInfo.tuner = tuner
    scanInfo.time = time
    scanInfo.lat = lat
    scanInfo.lon = lon
    scanInfo.desc = desc

    spectrum = sort_spectrum(spectrum)

    return scanInfo, spectrum, location
Ejemplo n.º 11
0
 def __open(self, dirname, filename):
     _info, spectrum, _locs = open_plot(dirname, filename)
     self.directory = dirname
     self.__plot(sort_spectrum(spectrum))
     vv.title(filename)