Example #1
0
def analysis(powers,
             freqs,
             ampdata,
             phasedata=None,
             plot_type=POWER,
             fig=None,
             txt=''):
    if fig is None:
        fig = plt.figure()
        fig.add_subplot(111)

    for ipower, power in enumerate(powers):
        txt += 'Power %.02f dB' % power
        fig.axes[0].plot(freqs / 1e6, ampdata[ipower, :], label=txt)

    fs = freqs
    amps = ampdata[0, :]
    f = fit.Lorentzian(fs, amps)
    h0 = np.max(amps)
    w0 = 2e6
    pos = fs[np.argmax(amps)]
    p0 = [np.min(amps), w0 * h0, pos, w0]
    p = f.fit(p0)
    txt += 'Center = %.03f MHz' % (p[2] / 1e6, )
    #    print 'Fit gave: %s' % (txt,)
    #        plt.plot(fs/1e6, f.func(p, fs), label=txt)

    fig.axes[0].legend()
    fig.axes[0].set_ylabel('Intensity [AU]')
    fig.axes[0].set_xlabel('Frequency [MHz]')

    #    fig.canvas.draw()

    return [f._fit_params, f._fit_err]
Example #2
0
	def fitPeak(self,spectrum=1,freq_axis=1):
		'''
		fitPeak(self,spectrum=1,freq_axis=1)
		by default it takes current soectrum to fit
		by defualt it takes current span to fit
		'''
		if (freq_axis==1):
			freq_axis=self.makeFreqAxis()
		if (spectrum==1):
			spectrum=self.get_spectrum()
		lor=f.Lorentzian()
		lor.fittin(freq_axis,spectrum)
		return lor
Example #3
0
def analysis(powers, freqs, ampdata, phasedata=None, plot_type=POWER, ax=None, plot_phase = True):
    if ax is None:
        ax = plt.figure().add_subplot(111)
    if plot_phase:
        ax2 = ax.twinx()#plt.figure().add_subplot(211)#ax.twinx()

    if plot_type == SPEC:
        for ipower, power in enumerate(powers):
            ax.plot(freqs/1e6, ampdata[ipower,:], label='Power %.02f dB'%power)
            if plot_phase:
                ax2.plot(freqs/1e6, phasedata[ipower,:], '--', label='Power %.02f dB'%power)

        fs = freqs
        amps = ampdata[0,:]
        f = fit.Lorentzian(fs, amps)
        h0 = np.max(amps)
        w0 = 2e6
        pos = fs[np.argmax(amps)]
        p0 = [np.min(amps), w0*h0, pos, w0]
        p = f.fit(p0)
        txt = 'Center = %.03f MHz\n FWHM = %.03f MHz' % (p[2]/1e6, p[3]/1e6,)
        print 'Fit gave: %s' % (txt,)
        plt.plot(fs/1e6, f.func(p, fs), label=txt)

        ax.legend()
        ax.set_ylabel('Intensity [AU]')
        ax.set_xlabel('Frequency [MHz]')
#        ax2.legend()
        if plot_phase:
            ax2.set_ylabel('Phase [deg]')
            ax2.set_xlabel('Frequency [MHz]')
        
        return [f._fit_params, f._fit_err]

    if plot_type == POWER:
#        ax1 = f.add_subplot(2,1,1)
#        ax2 = f.add_subplot(2,1,2)
        for ifreq, freq in enumerate(freqs):
            ax.plot(powers, ampdata[:,ifreq], label='RF @ %.03f MHz'%(freq/1e6,))
            ax2.plot(powers, phasedata[:,ifreq], label='RF @ %.03f MHz'%(freq/1e6,), color='g')
        ax.legend()
        ax2.legend()
        ax.set_ylabel('Intensity [AU]')
        ax2.set_ylabel('Angle [deg]')
        ax.set_xlabel('Power [dB]')
        ax2.set_xlabel('Power [dB]')
Example #4
0
    def analyze(self):
        f = plt.figure()

        if self.plot_type == SPEC:
            for ipower, power in enumerate(self.ro_powers):
                plt.plot(self.q_freqs / 1e6,
                         self.ampdata[ipower, :],
                         label='Power %.01f dB' % power)
#                plt.plot(self.q_freqs/1e6, self.phasedata[ipower,:], label='Power %.01f dB'%power)

            fs = self.q_freqs
            amps = self.ampdata[0, :]
            #            amps = self.phasedata[0,:]
            f = fit.Lorentzian(fs, amps)
            h0 = np.max(amps)
            w0 = 2e6
            pos = fs[np.argmax(amps)]
            p0 = [np.min(amps), w0 * h0, pos, w0]
            p = f.fit(p0)
            txt = 'Center = %.03f MHz' % (p[2] / 1e6, )
            print 'Fit gave: %s' % (txt, )
            plt.plot(fs / 1e6, f.func(p, fs), label=txt)

            plt.legend()
            plt.ylabel('Intensity [AU]')
            plt.xlabel('Frequency [MHz]')

        if self.plot_type == POWER:
            ax1 = f.add_subplot(2, 1, 1)
            ax2 = f.add_subplot(2, 1, 2)
            for ifreq, freq in enumerate(self.q_freqs):
                ax1.plot(self.ro_powers,
                         self.ampdata[:, ifreq],
                         label='RF @ %.03f MHz' % (freq / 1e6, ))
                ax2.plot(self.ro_powers,
                         self.phasedata[:, ifreq],
                         label='RF @ %.03f MHz' % (freq / 1e6, ))
            ax1.legend()
            ax2.legend()
            ax1.set_ylabel('Intensity [AU]')
            ax2.set_ylabel('Angle [deg]')
            ax1.set_xlabel('Power [dB]')
            ax2.set_xlabel('Power [dB]')
Example #5
0
def analysis(cav_disps, cav_freqs, ampdata, phasedata=None, plot_type=POWER, fig=None):
    if fig is None:
        fig = plt.figure()

    if plot_type == SPEC:
        for idisp, disp in enumerate(cav_disps):
            fig.axes[0].plot(cav_freqs/1e6, ampdata[idisp,:], label='Amp %.03f'%disp)
            fig.axes[1].plot(cav_freqs/1e6, phasedata[idisp,:], label='Amp %.03f'%disp)

        fs = cav_freqs
        amps = ampdata[0,:]
        f = fit.Lorentzian(fs, amps)
        h0 = np.max(amps)
        w0 = 2e6
        pos = fs[np.argmax(amps)]
        p0 = [np.min(amps), w0*h0, pos, w0]
        p = f.fit(p0)
        txt = 'Center = %.03f MHz' % (p[2]/1e6,)
        print 'Fit gave: %s' % (txt,)
#        plt.plot(fs/1e6, f.func(p, fs), label=txt)

        plt.legend()
        plt.ylabel('Intensity [AU]')
        plt.xlabel('Frequency [MHz]')

    if plot_type == POWER:
        ax1 = f.add_subplot(2,1,1)
        ax2 = f.add_subplot(2,1,2)
        for ifreq, freq in enumerate(cav_freqs):
            fig.axes[0].plot(cav_disps, ampdata[:,ifreq], label='RF @ %.03f MHz'%(freq/1e6,))
            fig.axes[1].plot(cav_disps, phasedata[:,ifreq], label='RF @ %.03f MHz'%(freq/1e6,))
        ax1.legend()
        ax2.legend()
        ax1.set_ylabel('Intensity [AU]')
        ax2.set_ylabel('Angle [deg]')
        ax1.set_xlabel('Power [dB]')
        ax2.set_xlabel('Power [dB]')