Beispiel #1
0
    def resume(self):
        sys.stdout.write("Resuming.")
        self.progress = 'Opening quenches'

        self.qm = quench.QuenchManager()
        self.qm.open_quenches(self.open_quenches, \
                              atten_v = self.initial_atten_vs, \
                              is_on = self.quench_is_on)
        self.qm.cavities_off(self.off_quenches)

        self.progress = 'Opening digitizer'

        self.digi = digitizer.Digitizer(self.run_dictionary \
                                            .ix['Digitizer Address for ' + \
                                                'Power Combiners'].Value,
                                        ch1_range = self.ch_range,
                                        ch2_range = self.ch_range,
                                        sampling_rate = self.sampling_rate,
                                        num_samples = self.num_samples)

        self.progress = 'Opening generator'

        self.gen = generator.Generator(offset_freq = self.offset_freq, \
                                       e_field = self.rf_e_field, \
                                       scan_range = self.rf_scan_range,
                                       calib = True)
        self.gen.set_rf_frequency(910.0, offset_channel = 'A',
                                  change_power = True)

        self.fc = faradaycupclass.FaradayCup()

        self.progress = 'Resume complete'
        super(PhaseMonitor, self).resume()

        return
Beispiel #2
0
    def resume(self):
        # Perform any re-initialization actions you want here before
        # communicating with the manager.

        self.progress = 'Resuming'
        self.qm = quench.QuenchManager()
        self.qm.open_quenches(self.open_quenches, \
                              atten_v = self.initial_atten_vs, \
                              is_on = self.quench_is_on)
        self.qm.cavities_off(self.off_quenches)

        self.digi = digitizer.Digitizer(self.run_dictionary \
                                            .ix['Digitizer Address'].Value, \
                                        ch1_range = self.ch_range, \
                                        ch2_range = self.ch_range, \
                                        num_samples = self.num_samples)

        self.gen = generator.Generator(calib=True)
        self.gen.power_low('A')
        self.gen.power_low('B')

        super(QuenchCalibration, self).resume()

        return
    PULSES_TO_PLOT = 10

    setup_logging()

    # Create a simple pulse of carrier
    t = timebase(0, PULSE_WIDTH, 1e+09)
    waves = []
    for ii in range(len(CARRIER_FREQUENCIES)):
        wave = np.sin(hertz_to_rad(CARRIER_FREQUENCIES[ii]) * t)
        wave = wave * CARRIER_AMPLITUDES[ii]
        wave = np.concatenate([wave, np.zeros(100)])
        waves.append(wave)

    awg_h = awg.open(AWG_SLOT, AWG_CHANNEL)
    awg.configure("repeatedMain")
    dig = digitizer.Digitizer(DIGITIZER_SLOT, DIGITIZER_CHANNELS,
                              CAPTURE_WIDTH)

    #    awg.loadWaveform(waves[0], AWG_DELAYS[0])
    awg.loadWaveforms(waves, AWG_DELAYS)
    dig.digitize(DIGITIZER_DELAY, NUMBER_OF_PULSES)

    hvi_path = os.getcwd() + '\\SyncStartRepeated_A1_D1.hvi'
    hvi_mapping = {'AWG0': awg_h, 'DIG0': dig.handle}
    hvi.init(hvi_path, hvi_mapping)

    hvi.setupConstants(NUMBER_OF_PULSES, PRI)

    hvi.start()

    # Allow the memory to partially fill.
    time.sleep(PRI * NUMBER_OF_PULSES / 100)
Beispiel #4
0
    def initialize_acquisition(self):
        # Initialize all global variables here, including the 'progress'
        # variable.

        self.progress = 'Printing data.txt comment header'

        self.comments = qol.make_comment_string(self.run_dictionary, \
                                                self.run_dictionary['Order'] \
                                                    .values)

        data_file = open(self.folder + 'data.txt', 'w')
        data_file.write(self.comments)
        data_file.close()

        self.progress = 'Reading quench parameters'

        self.quench_file = pd.read_csv(
            self.run_dictionary.ix['Quenches'].Value)
        self.quench_file = self.quench_file.set_index('Quench Name')

        self.progress = 'Setting up quenches'

        self.qm = quench.QuenchManager()

        quench_arrays = qol.quench_arrays(self.quench_file)

        self.open_quenches = quench_arrays[0]
        self.quench_is_on = quench_arrays[1]
        self.off_quenches = quench_arrays[2]
        self.initial_atten_vs = quench_arrays[3]
        self.on_quenches = quench_arrays[4]
        self.scan_quench = self.run_dictionary.ix[
            'Quench Cavity to Scan'].Value

        self.progress = 'Opening quenches'

        self.qm.open_quenches(self.open_quenches, \
                              atten_v = self.initial_atten_vs, \
                              is_on = self.quench_is_on)
        self.qm.cavities_off(self.off_quenches)

        self.progress = 'Opening digitizer'

        self.num_samples = int(self.run_dictionary \
                                   .ix['Number of Digitizer Samples'].Value)
        self.sampling_rate = int(self.run_dictionary \
                                     .ix['Digitizer Sampling Rate [S/s]'].Value)
        self.ch_range = int(self.run_dictionary \
                                .ix['Digitizer Channel Range [V]'].Value)
        self.digi = digitizer.Digitizer(self.run_dictionary \
                                            .ix['Digitizer Address'].Value, \
                                        ch1_range = self.ch_range, \
                                        ch2_range = self.ch_range, \
                                        sampling_rate = self.sampling_rate, \
                                        num_samples = self.num_samples)
        self.digi_channel = int(self.run_dictionary.ix['Digitizer Channel ' + \
                                                       'for Detector'].Value)

        self.progress = 'Opening generator'

        self.gen = generator.Generator(calib=True)
        #self.gen.power_low('A')
        #self.gen.power_low('B')

        self.max_rep = int(self.run_dictionary.ix['Number of Repeats'].Value)
        self.max_avg = int(self.run_dictionary.ix['Number of Averages'].Value)

        v_min = float(self.run_dictionary \
                          .ix['RF Attenuator Voltage (Start) [V]'].Value)
        v_max = float(self.run_dictionary \
                          .ix['RF Attenuator Voltage (Stop) [V]'].Value)
        self.n_atten_vs = int(self.run_dictionary \
                                  .ix['Number of Scan Steps'].Value)

        self.atten_v_list = self.linear_sqpower_list(v_min, v_max,
                                                     self.n_atten_vs)
        self.atten_v_randomized = np.random.permutation(self.atten_v_list)

        self.progress = 'Setting up data table'

        cols = [
            "Repeat", "Average", "Attenuator Voltage Setting [V]",
            "Digitizer DC (Quenches On) [V]",
            "Digitizer STD (Quenches On) [V]",
            "Digitizer DC (Quenches Off) [V]",
            "Digitizer STD (Quenches Off) [V]", "Digitizer DC On/Off Ratio",
            "Time"
        ]

        for q in self.open_quenches:
            cols.append(qol.formatted_quench_name(q) + \
                        ' Power Detector Reading (Quenches On) [V]')
            cols.append(qol.formatted_quench_name(q) + \
                        ' Attenuator Voltage Reading (Quenches On) [V]')
            cols.append(qol.formatted_quench_name(q) + \
                        ' Power Detector Reading (Quenches Off) [V]')
            cols.append(qol.formatted_quench_name(q) + \
                        ' Attenuator Voltage Reading (Quenches Off) [V]')

        # Write column headers
        self.data = pd.DataFrame(columns=cols)
        data_file = open(self.folder + 'data.txt', 'a')
        self.data.to_csv(data_file, index=False)
        data_file.close()
        print('\t'.join(self.data.columns))

        self.rep = 0
        self.avg = 0
        self.atten_v_iterator = 0

        self.total_traces = self.max_rep * self.max_avg * self.n_atten_vs

        self.progress = 'Initialization complete'
        self.start_time = dt.now()
        print('Beginning acquisition...')

        return
if (__name__ == '__main__'):
    setup_logging()

    # Create a simple pulse of carrier
    t = timebase(0, PULSE_WIDTH, 1e+09)
    waves = []
    for carrier in CARRIER_FREQUENCIES:
        wave = np.sin(hertz_to_rad(carrier) * t)
        wave = np.concatenate([wave, np.zeros(100)])
        waves.append(wave)

    awg_h = awg.open(AWG_SLOT, AWG_CHANNEL)
    digitizers = []
    for dig in range(len(DIGITIZER_SLOTS)):
        digitizers.append(
            digitizer.Digitizer(DIGITIZER_SLOTS[dig], DIGITIZER_CHANNELS,
                                CAPTURE_WIDTH))
    for dig in digitizers:
        dig.digitize(DIGITIZER_DELAY, NUMBER_OF_PULSES)

#    awg.loadWaveform(waves[0], AWG_DELAYS[0])
    awg.loadWaveforms(waves, AWG_DELAYS)

    hvi_mapping = {'AWG0': awg_h}
    for ii in range(len(digitizers)):
        hvi_mapping['DIG{}'.format(ii)] = digitizers[ii].handle
    hvi_file = '\\SyncStartRepeated_A1_D{}.hvi'.format(len(digitizers))
    hvi_path = os.getcwd() + hvi_file
    hvi.init(hvi_path, hvi_mapping)

    hvi.start(NUMBER_OF_PULSES, PRI)
    def initialize_acquisition(self):
        # Initialize all global variables here, including the 'progress'
        # variable.

        self.progress = 'Printing data.txt comment header'

        self.comments = qol.make_comment_string(self.run_dictionary, \
                                                self.run_dictionary['Order'] \
                                                    .values)

        data_file = open(self.folder + 'data.txt', 'w')
        data_file.write(self.comments)
        data_file.close()

        self.progress = 'Reading quench parameters'

        self.quench_file = pd.read_csv(
            self.run_dictionary.ix['Quenches'].Value)
        self.quench_file = self.quench_file.set_index('Quench Name')

        self.progress = 'Setting up quenches'

        self.qm = quench.QuenchManager()

        quench_arrays = qol.quench_arrays(self.quench_file)

        self.open_quenches = quench_arrays[0]
        self.quench_is_on = quench_arrays[1]
        self.off_quenches = quench_arrays[2]
        self.initial_atten_vs = quench_arrays[3]
        self.on_quenches = quench_arrays[4]

        self.progress = 'Opening quenches'

        self.qm.open_quenches(self.open_quenches, \
                              atten_v = self.initial_atten_vs, \
                              is_on = self.quench_is_on)
        self.qm.cavities_off(self.off_quenches)

        self.progress = 'Opening digitizer'

        self.num_samples = int(self.run_dictionary \
                                   .ix['Number of Digitizer Samples'].Value)
        self.sampling_rate = int(self.run_dictionary \
                                     .ix['Digitizer Sampling Rate [S/s]'].Value)
        self.ch_range = int(self.run_dictionary \
                                .ix['Digitizer Channel Range [V]'].Value)
        self.digi = digitizer.Digitizer(self.run_dictionary \
                                            .ix['Digitizer Address'].Value, \
                                        ch1_range = self.ch_range, \
                                        ch2_range = self.ch_range, \
                                        sampling_rate = self.sampling_rate, \
                                        num_samples = self.num_samples)
        self.digi_channel = int(self.run_dictionary.ix['Digitizer Channel ' + \
                                                       'for Detector'].Value)

        self.progress = 'Opening generator'

        self.gen = generator.Generator(calib=True)
        self.scan_wg = self.run_dictionary.ix['Waveguide to Scan'].Value
        self.gen.power_low('A')
        self.gen.power_on('A')
        self.gen.power_low('B')
        self.gen.power_on('B')

        self.max_rep = int(self.run_dictionary.ix['Number of Repeats'].Value)
        self.max_avg = int(self.run_dictionary.ix['Number of Averages'].Value)

        p_min = float(self.run_dictionary \
                          .ix['Waveguide Power (Start) [dBm]'].Value)
        p_max = float(self.run_dictionary \
                          .ix['Waveguide Power (Stop) [dBm]'].Value)
        self.n_powers = int(self.run_dictionary \
                                .ix['Number of Power Scan Steps'].Value)

        self.gen_p_list = np.linspace(p_min, p_max, self.n_powers)
        self.gen_p_randomized = np.random.permutation(self.gen_p_list)

        f_min = float(self.run_dictionary \
                          .ix['Waveguide Frequency (Start) [MHz]'].Value)
        f_max = float(self.run_dictionary \
                          .ix['Waveguide Frequency (Stop) [MHz]'].Value)
        self.n_freqs = int(self.run_dictionary \
                                .ix['Number of Frequency Scan Steps'].Value)

        self.gen_f_list = np.linspace(f_min, f_max, self.n_freqs)
        self.gen_f_randomized = np.random.permutation(self.gen_f_list)

        self.progress = 'Setting up data table'

        cols = [
            'Generator Channel', 'Repeat', 'Waveguide Frequency Setting [MHz]',
            'Waveguide Power Setting [dBm]', 'Average',
            "Waveguide A Power Reading  (Generator On) [V]",
            "Waveguide B Power Reading (Generator On) [V]",
            "Waveguide A Power Reading  (Generator Off) [V]",
            "Waveguide B Power Reading (Generator Off) [V]",
            "Digitizer DC (Quenches On) [V]",
            "Digitizer STD (Quenches On) [V]",
            "Digitizer DC (Quenches Off) [V]",
            "Digitizer STD (Quenches Off) [V]", "Digitizer DC On/Off Ratio",
            "Time"
        ]

        for q in self.open_quenches:
            cols.append(qol.formatted_quench_name(q) + \
                        ' Power Detector Reading (Generator On) [V]')
            cols.append(qol.formatted_quench_name(q) + \
                        ' Attenuator Voltage Reading (Generator On) [V]')
            cols.append(qol.formatted_quench_name(q) + \
                        ' Power Detector Reading (Generator Off) [V]')
            cols.append(qol.formatted_quench_name(q) + \
                        ' Attenuator Voltage Reading (Generator Off) [V]')

        # Write column headers
        self.data = pd.DataFrame(columns=cols)
        data_file = open(self.folder + 'data.txt', 'a')
        self.data.to_csv(data_file, index=False)
        data_file.close()
        print('\t'.join(self.data.columns))

        self.rep = 0
        self.avg = 0
        self.gen_p_iterator = 0
        self.gen_f_iterator = 0
        self.wg_iterator = 0

        self.frequency = 0.0

        if self.scan_wg == 'A' or self.scan_wg == 'B':
            self.n_wgs = 1
            self.waveguide_list = [self.scan_wg]
        elif self.scan_wg == 'BOTH':
            self.n_wgs = 2
            self.waveguide_list = ['A', 'B']
        else:
            raise qol.Travisty("Waveguide to Scan must have value \'A\', " + \
                               "\'B\', or BOTH.")

        self.waveguide_list_randomized = np.random  \
                                           .permutation(self.waveguide_list)

        self.total_traces = self.max_rep * self.max_avg * self.n_powers * \
                            self.n_freqs * self.n_wgs

        self.progress = 'Initialization complete'
        self.start_time = dt.now()
        print('Beginning acquisition...')

        return
def main():
    # Data collection parameters
    n_repeats = 1
    n_averages = 5
    ch_range = 0.25
    sleep_time = 0.5

    # Folder in which we will save
    timestring = dt.strftime(dt.now(), '%Y%m%d-%H%M%S')
    folder = 'C:/Google Drive/data/' + timestring + ' - Detector Bandwidth Test'
    os.mkdir(folder)

    # Dataframe setup
    dataframe_columns = [
        'Repeat', 'Average', 'AM Modulation Frequency [Hz]',
        'Amplitude at AM Modulation Frequency [V]',
        '0 Hz Frequency Component (AM On) [V]',
        'Noise at AM Modulation Frequency [V]',
        '0 Hz Frequency Component (AM Off) [V]'
    ]
    dataframe = pd.DataFrame(columns=dataframe_columns)

    # Connect to generator and digitizer
    gen = generator.Generator(calib=True, b_on=False)
    digi = digitizer.Digitizer('B',
                               sampling_rate=int(1e5),
                               num_samples=int(1e5),
                               ch1_range=ch_range)

    # Determine am_frequencies to use
    am_freqs = np.array([int(i * 10) for i in range(101) if (i * 10) % 60 > 0])
    am_freqs = np.random.permutation(am_freqs)

    # Initialize generator parameters
    gen.set_rf_frequency(910.0, 'N')
    gen.set_rf_power('A', -10.0)
    gen.am_on('A', 80.0, 100)
    time.sleep(0.5)

    for rep in range(n_repeats):
        for am_mod_freq in am_freqs:
            for avg in range(n_averages):
                gen.am_on('A', 80.0, am_mod_freq)
                time.sleep(sleep_time)

                V, err = digi.ini_read(channel=1, ret_bin=False)
                V = V * ch_range / 32767
                amplitude_on, phase, dc_on = qol.fit(V, 1e-5, am_mod_freq)

                print(am_mod_freq, amplitude_on)

                gen.am_off()
                time.sleep(sleep_time)

                V, err = digi.ini_read(channel=1, ret_bin=False)
                V = V * ch_range / 32767
                amplitude_off, phase, dc_off = qol.fit(V, 1e-5, am_mod_freq)

                print(am_mod_freq, amplitude_off)

                data_to_append = [
                    rep + 1, avg + 1, am_mod_freq, amplitude_on, dc_on,
                    amplitude_off, dc_off
                ]
                dataframe = dataframe.append(pd.Series(
                    data_to_append, index=dataframe_columns),
                                             ignore_index=True)

    gen.power_low('A')
    gen.close()

    digi.close()

    dataframe = dataframe.set_index(dataframe_columns[:3])
    dataframe.to_csv(folder + '/data.csv')
Beispiel #8
0
    def initialize_acquisition(self):
        # Initialize all global variables here, including the 'progress'
        # variable.

        self.progress = 'Printing data.txt comment header'
        print(digitizer)

        self.comments = qol.make_comment_string(self.run_dictionary, \
                                                self.run_dictionary['Order'] \
                                                    .values)

        data_file = open(self.folder + 'data.txt', 'w')
        data_file.write(self.comments)

        self.progress = 'Reading quench parameters'

        self.quench_file = pd.read_csv(self.run_dictionary.ix['Quenches'].Value)
        self.quench_file = self.quench_file.set_index('Quench Name')

        self.progress = 'Setting up quenches'

        self.qm = quench.QuenchManager()

        quench_arrays = qol.quench_arrays(self.quench_file)

        self.open_quenches = quench_arrays[0]
        self.quench_is_on = quench_arrays[1]
        self.off_quenches = quench_arrays[2]
        self.initial_atten_vs = quench_arrays[3]

        self.progress = 'Opening quenches'

        self.qm.open_quenches(self.open_quenches, \
                              atten_v = self.initial_atten_vs, \
                              is_on = self.quench_is_on)
        self.qm.cavities_off(self.off_quenches)

        self.progress = 'Opening digitizer'

        self.num_samples = int(self.run_dictionary \
                                   .ix['Number of Digitizer Samples'].Value)
        self.sampling_rate = int(self.run_dictionary \
                                     .ix['Digitizer Sampling Rate [S/s]'].Value)
        self.ch_range = int(self.run_dictionary \
                                .ix['Digitizer Channel Range [V]'].Value)
        self.digi = digitizer.Digitizer(self.run_dictionary \
                                            .ix['Digitizer Address for ' + \
                                                'Power Combiners'].Value,
                                        ch1_range = self.ch_range,
                                        ch2_range = self.ch_range,
                                        sampling_rate = self.sampling_rate,
                                        num_samples = self.num_samples)
        self.digi_channel_i = int(self.run_dictionary \
                                      .ix['Digitizer Channel for Power ' + \
                                          'Combiner I'].Value)
        self.digi_channel_i -= 1

        self.digi_channel_r = int(self.run_dictionary \
                                      .ix['Digitizer Channel for Power ' + \
                                          'Combiner R'].Value)
        self.digi_channel_r -= 1

        self.progress = 'Opening generator'

        self.offset_freq = int(self.run_dictionary.ix['RF Generator ' + \
                                                      'Frequency Offset ' + \
                                                      '[Hz]'].Value)
        self.rf_e_field = int(self.run_dictionary.ix['RF Electric Field ' + \
                                                     'Peak Amplitude ' + \
                                                     '[V/cm]'].Value)
        self.rf_scan_range = self.run_dictionary.ix['RF Frequency Range'].Value
        print("OFFSET FREQUENCY")
        print(self.offset_freq)
        self.gen = generator.Generator(offset_freq = self.offset_freq, \
                                       e_field = self.rf_e_field, \
                                       scan_range = self.rf_scan_range,
                                       calib = True)
        self.gen.set_rf_frequency(910.0, offset_channel = 'A',
                                  change_power = True)

        self.max_avg = int(self.run_dictionary \
                               .ix['Number of Traces per Loop'].Value)

        self.fc = faradaycupclass.FaradayCup()

        self.progress = 'Setting up data table'

        cols = ["Repeat", \
                "Average", \
                "Power Combiner I Amplitude [V]", \
                "Power Combiner I DC Offset [V]", \
                "Power Combiner R Amplitude [V]",
                "Power Combiner R DC Offset [V]", \
                "Power Combiner Phase Difference (R - I) [rad]", \
                "Waveguide A Power Detector Reading [V]", \
                "Waveguide B Power Detector Reading [V]", \
                "Time",
                "fc1a",
                "fc1b",
                "fc1c",
                "fc1d",
                "fc2i",
                "fc2ii",
                "fc2iii",
                "fc2iv",
                "fc3",
                "fccentre" ]

        for q in self.open_quenches:
            cols.append(qol.formatted_quench_name(q) + \
                       ' Power Detector Reading [V]')
            cols.append(qol.formatted_quench_name(q) + \
                       ' Attenuator Voltage Reading [V]')

        self.data = pd.DataFrame(columns = cols)
        self.data.set_index(['Repeat','Average']).to_csv(data_file)
        data_file.close()
        print('\t'.join(self.data.columns))

        self.rep = 0
        self.avg = 0

        self.progress = 'Initialization complete'
        self.start_time = dt.now()
        print('Beginning acquisition...')

        return