diff --git a/cfg/logging_config.ini b/cfg/logging_config.ini index 39b42d5..9e71a20 100644 --- a/cfg/logging_config.ini +++ b/cfg/logging_config.ini @@ -13,7 +13,7 @@ handlers=stream_handler,file_handler [handler_stream_handler] class=StreamHandler -level=INFO +level=DEBUG formatter=stream_formatter args=(sys.stdout,) diff --git a/measurement/experiment.py b/measurement/experiment.py index 979fbac..790d440 100644 --- a/measurement/experiment.py +++ b/measurement/experiment.py @@ -527,7 +527,7 @@ def measure(self): raise NotImplementedError("Method 'project' not implemented in worker (sub)class") def initialize_progress_counter(self): - """ initialize the progress counter which helps keep track of measurement loop status""" + """ initialize the progress _counter which helps keep track of measurement loop status""" self.n_of_steps = 1 for i in self.__max_ranges: self.n_of_steps *= i diff --git a/measurement/fastscan.py b/measurement/fastscan.py index dfd3283..5690302 100644 --- a/measurement/fastscan.py +++ b/measurement/fastscan.py @@ -23,13 +23,15 @@ import logging # for experiment-like classes import multiprocessing as mp +from queue import Empty as QueueEmpty + import os import sys import time import traceback import h5py -import nidaqmx +# import nidaqmx import numpy as np import xarray as xr from PyQt5 import QtCore @@ -45,12 +47,14 @@ from instruments.cryostat import ITC503s as Cryostat from utilities.math import sech2_fwhm, sin, gaussian_fwhm, gaussian, transient_1expdec, update_average from utilities.settings import parse_setting, parse_category, write_setting + try: from measurement.cscripts.project import project, project_r0 except: print('warning: failed loading cython projector, loading python instead') from measurement.cscripts.projectPy import project, project_r0 + # ----------------------------------------------------------------------------- # thread management # ----------------------------------------------------------------------------- @@ -76,31 +80,36 @@ def __init__(self): self.logger = logging.getLogger('{}.FastScanThreadManager'.format(__name__)) self.logger.info('Created Thread Manager') - self.__stream_queue = mp.Queue() # Queue where to store unprocessed streamer data + # multiprocessing variables + self._stream_queue = mp.Queue() # Queue where to store unprocessed streamer data + self._processed_queue = mp.Queue() # Queue where to store projected data + self.pool = QtCore.QThreadPool() + self.pool.setMaxThreadCount(self.n_processors) + # Data containers self.all_curves = None self.running_average = None self.streamer_average = None self.n_streamer_averages = 0 + # running control parameters self._calculate_autocorrelation = None - self.should_stop = False - self.streamerRunning = False - - self.current_iteration = None - self.spos_fit_pars = None # initialize the fit parameters for shaker position - - self.cryo = Cryostat(parse_setting('instruments','cryostat_com')) + self._recording_iteration = False # for iterative temperature measurement + self._max_avg_calc_time = 10 + self._skip_average = 0 # number of iterations to skipp average calculation + self._should_stop = False + self._streamer_running = False + self._current_iteration = None + self._spos_fit_pars = None # initialize the fit parameters for shaker position + self._counter = 0 # Counter for thread safe wait function + + self.cryo = Cryostat(parse_setting('instruments', 'cryostat_com')) # self.delay_stage = DelayStage() self.timer = QtCore.QTimer() self.timer.setInterval(1) self.timer.timeout.connect(self.on_timer) self.timer.start() - self.counter = 0 - - self.pool = QtCore.QThreadPool() - self.pool.setMaxThreadCount(self.n_processors) self.create_streamer() @@ -114,16 +123,15 @@ def start_projector(self, stream_data): stream_data: np.array data acquired by streamer. """ - self.logger.debug('Projecting data with shape {}'.format(stream_data.shape)) + self.logger.debug('Starting projector'.format(stream_data.shape)) runnable = Runnable(projector, stream_data=stream_data, - spos_fit_pars=self.spos_fit_pars, + spos_fit_pars=self._spos_fit_pars, use_dark_control=self.dark_control, adc_step=self.shaker_position_step, time_step=self.shaker_time_step, use_r0=self.use_r0, ) - self.pool.start(runnable) runnable.signals.result.connect(self.on_projector_data) @@ -134,164 +142,9 @@ def fit_autocorrelation(self, da): # runnable.signals.result.connect(self.on_fit_result) runnable.signals.result.connect(self.newFitResult.emit) - def calibrate_shaker(self, iterations, integration): - """ - Shaker calibration method. - - TODO: add description of shakercalib method. - Args: - iterations: - number of full time scales to acquire. - integration: - number of shaker cycles to integrate on for each iteration. - Returns: - plots the result of the calibration. Prints output result. - - """ - assert not self.streamerRunning, 'Cannot run Shaker calibration while streamer is running' - - import matplotlib.pyplot as plt - from scipy.optimize import curve_fit - - # self.start_streamer() - write_setting(0, 'fastscan - simulation', 'center_position') - - self.create_streamer() - - # stream = self.streamer.simulate_single_shot(integration) - stream = self.streamer.measure_single_shot(integration) - - projected = project(stream, self.dark_control, - self.shaker_position_step, 0.05) - min_ = projected.time.min() - max_ = projected.time.max() - print('\n - ') - calib_positions_ = np.linspace(min_ * .7, max_ * .7, iterations // 2) - calib_positions = np.concatenate((calib_positions_, calib_positions_[::-1])) - centers = [] - # np.random.shuffle(calib_positions) - for pos in calib_positions: - print('\n - moving stage') - - self.delay_stage.move_absolute(pos) - if parse_setting('fastscan', 'simulate'): - write_setting(pos, 'fastscan - simulation', 'center_position') - - # stream = self.streamer.simulate_single_shot(integration) - stream = self.streamer.measure_single_shot(integration) - projected = project(stream, self.dark_control, - self.shaker_position_step, 1) - res = fit_autocorrelation(projected) - print('\n - fitted, result it: {}'.format(res['popt'][1])) - centers.append(res['popt'][1]) - # plt.plot(projected) - # plt.show() - - steps = [] - calib_steps = [] - print('\n - calculating shift') - - for i in range(len(centers) - 1): - dy = np.abs(centers[i] - centers[i + 1]) - dx = np.abs(calib_positions[i] - calib_positions[i + 1]) - if dx != 0: - steps.append(dy / dx) - - mean = np.mean(steps) - std = np.std(steps) - good_steps = [x for x in steps if (np.abs(x - mean) < 2 * std)] - - # correction_factor = np.mean(calib_steps)/np.mean(steps) - - # write_setting('fastscan', 'shaker_ps_per_step', pos) - print('\n\n Shaker Calibration result: {} or {}'.format(1. / np.mean(steps), 1. / np.mean(good_steps))) - - def lin(x, a, b): - return a * x + b - - # plt.plot(calib_positions, centers, 'ob') - - # try: - popt_, pcov_ = curve_fit(lin, centers, calib_positions) - - cpos_fit = lin(np.array(centers), *popt_) - calib_pos_good = [] - centers_good = [] - for i in range(len(centers)): - std = np.std(calib_positions - cpos_fit) - if np.abs(calib_positions[i] - cpos_fit[i]) < 1.2 * std: - calib_pos_good.append(calib_positions[i]) - centers_good.append(centers[i]) - popt, pcov = curve_fit(lin, centers_good, calib_pos_good) - - plt.plot(centers, calib_positions, 'o') - plt.plot(centers_good, calib_pos_good, '.') - x = np.linspace(min(centers), max(centers), 100) - plt.plot(x, lin(x, *popt)) - # except: - # pass - print('\n\n Shaker Calibration result: {} | {}'.format(np.mean(good_steps), popt[0])) - - plt.show() - - @QtCore.pyqtSlot() - def on_timer(self): - """ Timer event. - - This is used for multiple purpouses: - - to stop threads when they are supposed to - - to end an acqusition which has finite number of iterations - - to increase the counter for 'wait' function - - maybe other stuff too... - """ - if self.should_stop: - self.logger.debug('no data in queue, killing streamer') - self.streamer_thread.exit() - self.should_stop = False - self.streamerRunning = False - try: - if not self.__stream_queue.empty(): - _to_project = self.__stream_queue.get() - self.start_projector(_to_project) - - self.logger.debug('got stream from queue: {} elements remaining'.format(self.stream_qsize)) - except Exception as e: - self.logger.debug('Queue error: {}'.format(e)) - - try: - self.qsize = self.__stream_queue.qsize() - except: - self.qsize = -1 - # self.start_projector(_to_project) - - - try: - # print(self.all_curves.shape[0], self.n_averages, self.all_curves.shape[0]==self.n_averages, self.recording_iteration) - if self.all_curves.shape[0] == self.n_averages and self.recording_iteration: - self.logger.info('n of averages reached: ending iteration step') - self.end_iteration_step() - except AttributeError as e: - pass - # print(e) - self.counter += 1 - - def wait(self, n, timeout=1000): - """ Gui safe waiting function. - - Args: - n: int - number of clock cycles to wait - timeout: int - number of clock cycles after which the waiting will be terminated - notwithstanding n. - """ - self.counter = 0 - i = 0 - while self.counter < n: - i += 1 - if i > timeout: - break - + # --------------------------------- + # Streamer management methods + # --------------------------------- def create_streamer(self): """ Generate the streamer thread. @@ -309,8 +162,8 @@ def create_streamer(self): @QtCore.pyqtSlot() def start_streamer(self): """ Start the acquisition by starting the streamer thread""" - self.should_stop = False - self.streamerRunning = True + self._should_stop = False + self._streamer_running = True self.create_streamer() self.streamer_thread.start() self.logger.info('FastScanStreamer started') @@ -321,7 +174,58 @@ def stop_streamer(self): """ Stop the acquisition thread.""" self.logger.debug('\n\nFastScan Streamer is stopping.\n\n') self.streamer.stop_acquisition() - self.should_stop = True + self._should_stop = True + + # --------------------------------- + # data handling pipeline + # --------------------------------- + @QtCore.pyqtSlot() + def on_timer(self): + """ Timer event. + + This is used for multiple purpouses: + - to stop threads when they are supposed to + - to end an acqusition which has finite number of iterations + - to increase the _counter for 'wait' function + - maybe other stuff too... + """ + # Stop the streamer if button was pressed + if self._should_stop: + self.logger.debug( + 'Killing streamer: streamer queue: {} processed queue: {}'.format(self.stream_qsize, + self.processed_qsize)) + self.streamer_thread.exit() + self._should_stop = False + self._streamer_running = False + # when streamer data is available, start a projector + try: + if not self._stream_queue.empty(): + _to_project = self._stream_queue.get() + self.start_projector(_to_project) + self.logger.debug('Projecting an element from streamer queue: {} elements remaining'.format(self.stream_qsize)) + except Exception as e: + self.logger.debug('Queue error: {}'.format(e)) + + # when projected data is available, calculate the new average + # try: + # if not self._stream_queue.empty(): + # _to_project = self._stream_queue.get() + # self.start_projector(_to_project) + # self.logger.debug( + # 'Projecting an element from streamer queue: {} elements remaining'.format(self.stream_qsize)) + # except Exception as e: + # self.logger.debug('Queue error: {}'.format(e)) + + # manage iterative measurement. Start next step whien n_averages has been reached. + if self._recording_iteration: + try: + if self.all_curves.shape[0] == self.n_averages: + self.logger.info('n of averages reached: ending iteration step') + self.end_iteration_step() + except AttributeError as e: + pass + + self._counter += 1 # increase the waiting counter @QtCore.pyqtSlot(np.ndarray) def on_streamer_data(self, streamer_data): @@ -332,20 +236,22 @@ def on_streamer_data(self, streamer_data): streamer data queue, ready to be processed by a processor thread. """ self.newStreamerData.emit(streamer_data) + t0 = time.time() if self.streamer_average is None: self.streamer_average = streamer_data self.n_streamer_averages = 1 else: self.n_streamer_averages += 1 self.streamer_average = update_average(streamer_data, self.streamer_average, self.n_streamer_averages) - - self.__stream_queue.put(streamer_data) - self.logger.debug('added data to stream queue, with shape {}'.format(streamer_data.shape)) - # _to_project = self.__stream_queue.get() + self.logger.debug('{:.2f} ms| Streamer average updated ({} scans)'.format((time.time() - t0) * 1000, + self.n_streamer_averages)) + self._stream_queue.put(streamer_data) + self.logger.debug('Added data to stream queue, with shape {}'.format(streamer_data.shape)) + # _to_project = self._stream_queue.get() # print('got stream from queue: {}'.format(_to_project.shape)) # self.start_projector(_to_project) - @QtCore.pyqtSlot(tuple)#xr.DataArray, list) + @QtCore.pyqtSlot(tuple) # xr.DataArray, list) def on_projector_data(self, processed_dataarray_tuple): """ Slot to handle processed data. @@ -355,22 +261,43 @@ def on_projector_data(self, processed_dataarray_tuple): it launches the thread to calculate the autocorrelation function. This emits data to the main window, so it can be plotted...""" - processed_dataarray, spos_fit_pars = processed_dataarray_tuple + processed_dataarray, self._spos_fit_pars = processed_dataarray_tuple self.newProcessedData.emit(processed_dataarray) - self.spos_fit_pars = spos_fit_pars - t0 = time.time() - if self.all_curves is None: - self.all_curves = processed_dataarray - self.running_average = processed_dataarray.dropna('time') + self._processed_queue.put(processed_dataarray) - else: - self.all_curves = xr.concat([self.all_curves[-self.n_averages + 1:], processed_dataarray], 'avg') - self.running_average = self.all_curves.mean('avg').dropna('time') + if self._skip_average == 0: + self.logger.debug('\nstarting average calculation: {} elements in queue'.format(self.processed_qsize)) - self.newAverage.emit(self.running_average) - - self.logger.debug('calculated average in {:.2f} ms'.format((time.time() - t0) * 1000)) + t0 = time.time() + all_last_projected = [] + + for i in range(self.processed_qsize): + try: + all_last_projected.append(self._processed_queue.get(block=True,timeout=0.01).dropna('time')) # drop values where no data was recorded (nans) + except QueueEmpty: + self.logger.debug('queue reported empty. actual size: {}'.format(self.processed_qsize)) + pass + self.logger.debug('\n{} elements taken from the processed queue'.format(len(all_last_projected))) + + if self.all_curves is None: + self.all_curves = processed_dataarray + self.running_average = all_last_projected.pop(0).dropna('time') + + n_left = len(all_last_projected) + if n_left>0: + self.all_curves = xr.concat([self.all_curves[-self.n_averages + n_left:], *all_last_projected], 'avg') + self.running_average = self.all_curves.mean('avg').dropna('time') + + self.newAverage.emit(self.running_average) + + t_tot = (time.time() - t0) * 1000 + if t_tot > self._max_avg_calc_time: + self._skip_average = t_tot // self._max_avg_calc_time + self.logger.debug('calculated average in {:.2f} ms'.format(t_tot)) + else: + self.logger.debug('skipping average calculation, {} , queue size: {}'.format(-self._skip_average, self.processed_qsize)) + self._skip_average -= 1 if self._calculate_autocorrelation: self.fit_autocorrelation(self.running_average) @@ -380,6 +307,9 @@ def on_fit_result(self, fitDict): """ Slot to bounce the fit result signal.""" self.newFitResult.emit(fitDict) + # --------------------------------- + # data I/O + # --------------------------------- @QtCore.pyqtSlot() def reset_data(self): """ Reset the data in memory, by reinitializing all data containers. @@ -432,6 +362,112 @@ def save_data(self, filename, all_data=True): self.logger.info('no data to save yet...') # f.create_group('/settings') + # --------------------------------- + # shaker calibration + # --------------------------------- + def calibrate_shaker(self, iterations, integration): + """ + Shaker calibration method. + + TODO: add description of shakercalib method. + Args: + iterations: + number of full time scales to acquire. + integration: + number of shaker cycles to integrate on for each iteration. + Returns: + plots the result of the calibration. Prints output result. + + """ + assert not self._streamer_running, 'Cannot run Shaker calibration while streamer is running' + + import matplotlib.pyplot as plt + from scipy.optimize import curve_fit + + # self.start_streamer() + write_setting(0, 'fastscan - simulation', 'center_position') + + self.create_streamer() + + # stream = self.streamer.simulate_single_shot(integration) + stream = self.streamer.measure_single_shot(integration) + + projected = project(stream, self.dark_control, + self.shaker_position_step, 0.05) + min_ = projected.time.min() + max_ = projected.time.max() + print('\n - ') + calib_positions_ = np.linspace(min_ * .7, max_ * .7, iterations // 2) + calib_positions = np.concatenate((calib_positions_, calib_positions_[::-1])) + centers = [] + # np.random.shuffle(calib_positions) + for pos in calib_positions: + print('\n - moving stage') + + self.delay_stage.move_absolute(pos) + if parse_setting('fastscan', 'simulate'): + write_setting(pos, 'fastscan - simulation', 'center_position') + + # stream = self.streamer.simulate_single_shot(integration) + stream = self.streamer.measure_single_shot(integration) + projected = project(stream, self.dark_control, + self.shaker_position_step, 1) + res = fit_autocorrelation(projected) + print('\n - fitted, result it: {}'.format(res['popt'][1])) + centers.append(res['popt'][1]) + # plt.plot(projected) + # plt.show() + + steps = [] + calib_steps = [] + print('\n - calculating shift') + + for i in range(len(centers) - 1): + dy = np.abs(centers[i] - centers[i + 1]) + dx = np.abs(calib_positions[i] - calib_positions[i + 1]) + if dx != 0: + steps.append(dy / dx) + + mean = np.mean(steps) + std = np.std(steps) + good_steps = [x for x in steps if (np.abs(x - mean) < 2 * std)] + + # correction_factor = np.mean(calib_steps)/np.mean(steps) + + # write_setting('fastscan', 'shaker_ps_per_step', pos) + print('\n\n Shaker Calibration result: {} or {}'.format(1. / np.mean(steps), 1. / np.mean(good_steps))) + + def lin(x, a, b): + return a * x + b + + # plt.plot(calib_positions, centers, 'ob') + + # try: + popt_, pcov_ = curve_fit(lin, centers, calib_positions) + + cpos_fit = lin(np.array(centers), *popt_) + calib_pos_good = [] + centers_good = [] + for i in range(len(centers)): + std = np.std(calib_positions - cpos_fit) + if np.abs(calib_positions[i] - cpos_fit[i]) < 1.2 * std: + calib_pos_good.append(calib_positions[i]) + centers_good.append(centers[i]) + popt, pcov = curve_fit(lin, centers_good, calib_pos_good) + + plt.plot(centers, calib_positions, 'o') + plt.plot(centers_good, calib_pos_good, '.') + x = np.linspace(min(centers), max(centers), 100) + plt.plot(x, lin(x, *popt)) + # except: + # pass + print('\n\n Shaker Calibration result: {} | {}'.format(np.mean(good_steps), popt[0])) + + plt.show() + + # --------------------------------- + # iterative temperature measurement + # --------------------------------- def start_iterative_measurement(self, temperatures, savename): """ Starts a temperature dependence scan series. @@ -451,7 +487,7 @@ def start_iterative_measurement(self, temperatures, savename): # self.stop_streamer() # self.reset_data() self.logger.info('starting measurement loop') - self.current_iteration = 0 + self._current_iteration = 0 # self.stop_streamer() self.start_next_iteration() @@ -464,14 +500,14 @@ def start_next_iteration(self): """ self.stop_streamer() - if self.current_iteration >= len(self.temperatures): - self.current_iteration = None + if self._current_iteration >= len(self.temperatures): + self._current_iteration = None print('\n\n\n\nMEASUREMENT FINISHED\n\n\n') self.logger.info('Iterative mesasurement complete!!') else: self.cryo.connect() self.logger.info('Connected to Cryostat: setting temperature....') - self.cryo.set_temperature(self.temperatures[self.current_iteration]) + self.cryo.set_temperature(self.temperatures[self._current_iteration]) runnable = Runnable(self.cryo.check_temp, tolerance=.1, sleep_time=1) self.pool.start(runnable) runnable.signals.finished.connect(self.measure_current_iteration) @@ -480,30 +516,29 @@ def start_next_iteration(self): def measure_current_iteration(self): """ Start the acquisition for the current measurement iteration.""" self.cryo.disconnect() - self.logger.info('Temperature stable, measuring interation {}, {}K'.format(self.current_iteration, + self.logger.info('Temperature stable, measuring interation {}, {}K'.format(self._current_iteration, self.temperatures[ - self.current_iteration])) + self._current_iteration])) self.stop_streamer() self.reset_data() self.start_streamer() - self.recording_iteration = True + self._recording_iteration = True @QtCore.pyqtSlot() def end_iteration_step(self): """ Complete and finalize the current measurement iteration.""" - self.logger.info('Stopping iteration') - self.recording_iteration = False + self._recording_iteration = False - t = self.temperatures[self.current_iteration] + t = self.temperatures[self._current_iteration] temp_string = '_{:0.2f}K'.format(float(t)).replace('.', ',') - savename = self.iterative_measurement_name+temp_string - self.logger.info('Iteration {} complete. Saved data as {}'.format(self.current_iteration,savename)) + savename = self.iterative_measurement_name + temp_string + self.logger.info('Iteration {} complete. Saved data as {}'.format(self._current_iteration, savename)) self.save_data(savename) self.stop_streamer() - self.current_iteration += 1 + self._current_iteration += 1 self.start_next_iteration() @staticmethod @@ -519,6 +554,23 @@ def check_temperature_stability(cryo, tolerance=.2, sleep_time=.1): diff = max([abs(x - cryo.temperature_target) for x in temp]) print(f'cryo stabilizing: delta={diff}') + def wait(self, n, timeout=1000): + """ Gui safe waiting function. + + Args: + n: int + number of clock cycles to wait + timeout: int + number of clock cycles after which the waiting will be terminated + notwithstanding n. + """ + self._counter = 0 + i = 0 + while self._counter < n: + i += 1 + if i > timeout: + break + @QtCore.pyqtSlot() def close(self): """ stop the streamer when closing this widget.""" @@ -530,12 +582,20 @@ def close(self): def stream_qsize(self): """ State of dark control. If True it's on.""" try: - val = self.__stream_queue.qsize() + val = self._stream_queue.qsize() except: val = -1 return val @property + def processed_qsize(self): + """ State of dark control. If True it's on.""" + try: + val = self._processed_queue.qsize() + except: + val = -1 + return val + @property def dark_control(self): """ State of dark control. If True it's on.""" return parse_setting('fastscan', 'dark_control') @@ -819,7 +879,8 @@ def sech_wings(x, a, xc, t, off, wing_sep, wing_ratio): return fitDict -def projector(stream_data, spos_fit_pars=None, use_dark_control=True, adc_step=0.000152587890625, time_step=.05, use_r0=True): +def projector(stream_data, spos_fit_pars=None, use_dark_control=True, adc_step=0.000152587890625, time_step=.05, + use_r0=True): """ Args: @@ -836,13 +897,13 @@ def projector(stream_data, spos_fit_pars=None, use_dark_control=True, adc_step=0 Returns: """ - assert isinstance(stream_data,np.ndarray) - # assert stream_data.ndim >2, 'stream data must be 3 or 4 dimensional' + assert isinstance(stream_data, np.ndarray) + t0 = time.time() + logger = logging.getLogger('{}.Projector'.format(__name__)) - if stream_data.shape[0] == 4 and use_r0: # calculate dR/R only when required and when data for R0 is there + if stream_data.shape[0] == 4 and use_r0: # calculate dR/R only when required and when data for R0 is there use_r0 = True else: - print('Not using r0:\n ndim = {}\n use_r0 = {}'.format(stream_data.ndim ,use_r0)) use_r0 = False spos_analog = stream_data[0] signal = stream_data[1] @@ -864,14 +925,18 @@ def projector(stream_data, spos_fit_pars=None, use_dark_control=True, adc_step=0 if use_r0: reference = stream_data[3] - result = project_r0(spos,signal,dark_control,reference, use_dark_control) + result = project_r0(spos, signal, dark_control, reference, use_dark_control) else: result = project(spos, signal, dark_control, use_dark_control) time_axis = np.arange(spos.min(), spos.max() + 1, 1) * time_step output = xr.DataArray(result, coords={'time': time_axis}, dims='time').dropna('time') + logger.debug( + '{:.2f} ms | projecting time r0:{}. dc:{} '.format((time.time() - t0) * 1000, use_r0, use_dark_control)) + return (output, spos_fit_pars) + def project_OLD(stream_data, use_dark_control=True, adc_step=0.000152587890625, time_step=.05, r0=True): spos_analog = stream_data[0] x = np.arange(0, len(spos_analog), 1) @@ -939,7 +1004,8 @@ class FastScanStreamer(QtCore.QObject): finished = QtCore.pyqtSignal() newData = QtCore.pyqtSignal(np.ndarray) error = QtCore.pyqtSignal(Exception) - niChannel_order = ['shaker_position','signal','dark_control','reference'] + niChannel_order = ['shaker_position', 'signal', 'dark_control', 'reference'] + def __init__(self, ): super().__init__() self.logger = logging.getLogger('{}.FastScanStreamer'.format(__name__)) @@ -963,22 +1029,21 @@ def init_ni_channels(self): self.niTriggers = { # default triggers 'shaker_trigger': "/Dev1/PFI1", 'laser_trigger': "/Dev1/PFI0"} -# try: -# self.niChannels = {} -# for k, v in parse_category('ni_signal_channels').items(): -# self.niChannels[k] = v -# except: -# self.logger.critical('failed reading signal from SETTINGS, using default channels.') -# try: -# self.niTriggers = {} -# for k, v in parse_category('ni_trigger_channels').items(): -# self.niTriggers[k] = v -# except: -# self.logger.critical('failed reading trigger channels from SETTINGS, using default channels.') + # try: + # self.niChannels = {} + # for k, v in parse_category('ni_signal_channels').items(): + # self.niChannels[k] = v + # except: + # self.logger.critical('failed reading signal from SETTINGS, using default channels.') + # try: + # self.niTriggers = {} + # for k, v in parse_category('ni_trigger_channels').items(): + # self.niTriggers[k] = v + # except: + # self.logger.critical('failed reading trigger channels from SETTINGS, using default channels.') self.data = np.zeros((len(self.niChannels), self.n_samples)) - @QtCore.pyqtSlot() def start_acquisition(self): if self.simulate: @@ -1051,7 +1116,7 @@ def measure_triggered(self): except KeyError: self.logger.critical('No {} channel found'.format(chan)) except: - self.logger.critical('Failed connecting to {} channel @ {}'.format(chan,self.niChannels[chan])) + self.logger.critical('Failed connecting to {} channel @ {}'.format(chan, self.niChannels[chan])) self.logger.debug('added {} tasks'.format(loaded_channels)) task.triggers.start_trigger.cfg_dig_edge_start_trig(trigger_source=self.niTriggers['shaker_trigger'], @@ -1079,7 +1144,7 @@ def measure_triggered(self): def measure_single_shot(self, n): try: with nidaqmx.Task() as task: - for k,v in self.niChannels: # add all channels to be recorded + for k, v in self.niChannels: # add all channels to be recorded task.ai_channels.add_ai_voltage_chan(v) self.logger.debug('added {} tasks'.format(len(self.niChannels))) diff --git a/measurement/fastscan_gui.py b/measurement/fastscan_gui.py index 6589c2f..a4de664 100644 --- a/measurement/fastscan_gui.py +++ b/measurement/fastscan_gui.py @@ -387,10 +387,11 @@ def on_main_clock(self): fps = 0 - string = 'Data Size :\n streamer: {} - {:10.3f} Kb\n projected: {} - {:10.3f} Kb\n Streams queued: {}\n Cycles per Second [Hz]: {:10.3f} '.format( + string = 'Data Size :\n streamer: {} - {:10.3f} Kb\n projected: {} - {:10.3f} Kb\n Queues: Stream: {} Projected: {}\n Cycles per Second [Hz]: {:10.3f} '.format( streamer_shape, np.prod(streamer_shape) / (1024), projected_shape, np.prod(projected_shape) / (1024), self.data_manager.stream_qsize, + self.data_manager.processed_qsize, fps, )