Beispiel #1
0
    def __init__(self, instruments = None, scripts = None, name = None, settings = None, log_function = None, data_path = None):
        """
        Select points by clicking on an image
        """
        Script.__init__(self, name, settings = settings, instruments = instruments, scripts = scripts, log_function= log_function, data_path = data_path)

        self.last_execution = None
Beispiel #2
0
    def __init__(self,
                 instruments,
                 name=None,
                 settings=None,
                 log_function=None,
                 data_path=None):
        '''
        Initializes GalvoScan script for use in gui

        Args:
            instruments: list of instrument objects
            name: name to give to instantiated script object
            settings: dictionary of new settings to pass in to override defaults
            log_function: log function passed from the gui to direct log calls to the gui log
            data_path: path to save data

        '''
        Script.__init__(self,
                        name,
                        settings=settings,
                        instruments=instruments,
                        log_function=log_function,
                        data_path=data_path)
        # defines which daqs contain the input and output based on user selection of daq interface
        if self.settings['daq_type'] == 'PCI':
            self.daq_in = self.instruments['NI6259']['instance']
            self.daq_out = self.instruments['NI6259']['instance']
        elif self.settings['daq_type'] == 'cDAQ':
            self.daq_in = self.instruments['NI9402']['instance']
            self.daq_out = self.instruments['NI9263']['instance']
Beispiel #3
0
    def __init__(self,
                 instruments=None,
                 name=None,
                 settings=None,
                 scripts=None,
                 log_function=None,
                 data_path=None):
        Script.__init__(self,
                        name,
                        settings=settings,
                        instruments=instruments,
                        scripts=scripts,
                        log_function=log_function,
                        data_path=data_path)

        self.data = {
            'baseline_image': [],
            'baseline_extent': [],
            'new_image': [],
            'new_image_extent': [],
            'initial_galvo_position': [],
            'shift': [],
            'correlation_image': []
        }

        self.baseline_processed_image = self.data['baseline_image']
        self.new_processed_image = self.data['new_image']
        self.count_executions = 0  # counts how often the script has been updated
Beispiel #4
0
    def __init__(self,
                 instruments=None,
                 name=None,
                 settings=None,
                 scripts=None,
                 log_function=None,
                 data_path=None):
        """
        Example of a script that emits a QT signal for the gui
        Args:
            name (optional): name of script, if empty same as class name
            settings (optional): settings for this script, if empty same as default settings
        """
        Script.__init__(self,
                        name,
                        settings=settings,
                        instruments=instruments,
                        scripts=scripts,
                        log_function=log_function,
                        data_path=data_path)

        self.data = {
            'baseline_image': [],
            'new_image': [],
            'image_extent': [],
            'correlation_image': []
        }
Beispiel #5
0
 def __init__(self,
              scripts,
              instruments=None,
              name=None,
              settings=None,
              log_function=None,
              data_path=None):
     """
     Example of a script that emits a QT signal for the gui
     Args:
         name (optional): name of script, if empty same as class name
         settings (optional): settings for this script, if empty same as default settings
     """
     print('LOADING')
     self.scan_label = 'Piezo Voltage [V]'
     try:
         Script.__init__(self,
                         name,
                         settings,
                         instruments,
                         scripts,
                         log_function=log_function,
                         data_path=data_path)
     except:
         import sys
         import traceback
         exc_type, exc_value, exc_traceback = sys.exc_info()
         print "*** print_exception:"
         traceback.print_exception(exc_type,
                                   exc_value,
                                   exc_traceback,
                                   limit=2,
                                   file=sys.stdout)
     print('LOADED')
Beispiel #6
0
 def __init__(self,
              scripts,
              instruments=None,
              name=None,
              settings=None,
              log_function=None,
              data_path=None):
     """
     Example of a script that emits a QT signal for the gui
     Args:
         name (optional): name of script, if empty same as class name
         settings (optional): settings for this script, if empty same as default settings
     """
     Script.__init__(self,
                     name,
                     settings,
                     instruments,
                     scripts,
                     log_function=log_function,
                     data_path=data_path)
     #always want to use the autofocus's location
     self.scripts['find_NV'].settings['center_on_current_location'] = True
     self.scripts['set_laser'].settings['point'] = self.scripts[
         'take_image'].settings['point_a']
     self.scripts['set_laser'].run()
Beispiel #7
0
    def __init__(self,
                 instruments,
                 name=None,
                 settings=None,
                 log_function=None,
                 timeout=1000000000,
                 data_path=None):

        self._recording = False
        self._timeout = timeout

        Script.__init__(self,
                        name,
                        settings,
                        instruments,
                        log_function=log_function,
                        data_path=data_path)

        self.sweeper = self.instruments['zihf2']['instance'].daq.sweep(
            self._timeout)
        self.sweeper.set('sweep/device',
                         self.instruments['zihf2']['instance'].device)

        self.data = deque()

        # todo: clean this up! and plot data in gui!
        self._sweep_values = {
            'frequency': [],
            'x': [],
            'y': [],
            'phase': [],
            'r': []
        }.keys()
Beispiel #8
0
 def __init__(self, scripts, instruments = None, name = None, settings = None, log_function = None, data_path = None):
     """
     Example of a script that emits a QT signal for the gui
     Args:
         name (optional): name of script, if empty same as class name
         settings (optional): settings for this script, if empty same as default settings
     """
     Script.__init__(self, name, settings, instruments, scripts, log_function= log_function, data_path = data_path)
Beispiel #9
0
 def __init__(self, name=None, settings=None, log_function = None, data_path = None):
     """
     Example of a script
     Args:
         name (optional): name of script, if empty same as class name
         settings (optional): settings for this script, if empty same as default settings
     """
     Script.__init__(self, name, settings, log_function= log_function, data_path = data_path)
Beispiel #10
0
 def __init__(self, instruments, scripts = None, name=None, settings=None, log_function=None, data_path = None):
     Script.__init__(self, name, settings=settings, scripts=scripts, instruments=instruments, log_function=log_function, data_path = data_path)
     # defines which daqs contain the input and output based on user selection of daq interface
     if self.settings['daq_type'] == 'PCI':
         self.daq_in = self.instruments['NI6259']['instance']
         self.daq_out = self.instruments['NI6259']['instance']
     elif self.settings['daq_type'] == 'cDAQ':
         self.daq_in = self.instruments['NI9402']['instance']
         self.daq_out = self.instruments['NI9263']['instance']
    def __init__(self, scripts, name = None, settings = None, log_function = None, timeout = 1000000000, data_path = None):
        self._recording = False
        self._timeout = timeout

        Script.__init__(self, name, settings, scripts = scripts, log_function= log_function, data_path = data_path)

        self.data = deque()

        self._sweep_values =  {'frequency' : [], 'x' : [], 'y' : [], 'phase': [], 'r':[]}.keys()
Beispiel #12
0
    def __init__(self, instruments, scripts = None, name=None, settings=None, log_function=None, data_path = None):
        """
        Example of a script that emits a QT signal for the gui
        Args:
            name (optional): name of script, if empty same as class name
            settings (optional): settings for this script, if empty same as default settings
        """

        Script.__init__(self, name, settings=settings, scripts=scripts, instruments=instruments, log_function=log_function, data_path = data_path)
        self.data = {'plant_output': deque(maxlen=self.settings['buffer_length']),
                     'control_output': deque(maxlen=self.settings['buffer_length'])}
 def __init__(self,
              instruments,
              scripts=None,
              name=None,
              settings=None,
              log_function=None,
              data_path=None):
     Script.__init__(self,
                     name,
                     settings=settings,
                     scripts=scripts,
                     instruments=instruments,
                     log_function=log_function,
                     data_path=data_path)
    def plot(self, figure_list):
        '''
        Plots a dot on top of each selected NV, with a corresponding number denoting the order in which the NVs are
        listed.
        Precondition: must have an existing image in figure_list[0] to plot over
        Args:
            figure_list:
        '''
        # if there is not image data get it from the current plot
        print('here we are')
        if not self.data == {} and self.data['image_data'] is None:
            axes = figure_list[0].axes[0]
            if len(axes.images) > 0:
                self.data['image_data'] = np.array(axes.images[0].get_array())
                self.data['extent'] = np.array(axes.images[0].get_extent())
                self.plot_settings['cmap'] = axes.images[0].get_cmap().name
                self.plot_settings['xlabel'] = axes.get_xlabel()
                self.plot_settings['ylabel'] = axes.get_ylabel()
                self.plot_settings['title'] = axes.get_title()
                self.plot_settings['interpol'] = axes.images[
                    0].get_interpolation()

        if self.data['nv_locations'] == []:
            if self.settings['nv_selection_method'] == 'automatic':
                nvsauto = tp.locate(self.data['image_data'],
                                    self.settings['nv_size_est'],
                                    minmass=self.settings['nv_mass_min'],
                                    invert=False)
                nvcoords = [
                    self.pixel_to_voltage(p, self.data['extent'],
                                          np.shape(self.data['image_data']))
                    for p in nvsauto[['x', 'y']].as_matrix()
                ]
                self.data['nv_locations'] = nvcoords
                # self.data['nv_masses'] = nvsauto['mass']
                # self.data['nv_sizes'] = nvcoords['size']
            elif self.settings['nv_selection_method'] == 'loaded':
                coordstmp = np.loadtxt(self.settings['coords_file'],
                                       delimiter=',')
                coordstmp[:,
                          0] = coordstmp[:,
                                         0] + self.settings['coord_offset_x']
                coordstmp[:,
                          1] = coordstmp[:,
                                         1] + self.settings['coord_offset_y']
                coordstmp = coordstmp.tolist()
                coordstmp.pop(0)
                self.data['nv_locations'] = coordstmp

        Script.plot(self, figure_list)
Beispiel #15
0
    def __init__(self,
                 scripts,
                 name=None,
                 settings=None,
                 log_function=None,
                 timeout=1000000000,
                 data_path=None):

        Script.__init__(self,
                        name,
                        settings=settings,
                        scripts=scripts,
                        log_function=log_function,
                        data_path=data_path)
Beispiel #16
0
 def __init__(self,
              instruments=None,
              name=None,
              settings=None,
              log_function=None,
              data_path=None):
     """
     Default script initialization
     """
     Script.__init__(self,
                     name,
                     settings=settings,
                     instruments=instruments,
                     log_function=log_function,
                     data_path=data_path)
def export_default_scripts(target_folder,
                           source_folder=None,
                           raise_errors=False):
    """
    tries to instantiate all the scripts that are imported in /scripts/__init__.py
    saves each script that could be instantiated into a .b26 file in the folder path
    Args:
        target_folder: target path for .b26 files
        source_folder: location of python script files
    """
    loaded_instruments = {}
    loaded_scripts = {}

    scripts_to_load = get_classes_in_folder(source_folder, Script)

    print('attempt to load {:d} scripts: '.format(len(scripts_to_load)))

    loaded_scripts, failed, loaded_instruments = Script.load_and_append(
        scripts_to_load, raise_errors=raise_errors)

    for name, value in loaded_scripts.iteritems():
        filename = os.path.join(target_folder, '{:s}.b26'.format(name))
        value.save_b26(filename)

    print('\n================================================')
    print('================================================')
    print('saved {:d} scripts, {:d} failed'.format(len(loaded_scripts),
                                                   len(failed)))
    if failed != {}:
        for error_name, error in failed.iteritems():
            print('failed to create script: ', error_name, error)
Beispiel #18
0
    def test_loading_and_saving(self):
        from src.core.read_write_functions import load_b26_file

        filename = "Z:\Lab\Cantilever\Measurements\\__tmp\\XYX.b26"

        scripts, loaded_failed, instruments = Script.load_and_append(
            {"some script": 'ScriptDummyWithInstrument'})

        script = scripts['some script']
        script.save_b26(filename)

        data = load_b26_file(filename)
        scripts = {}
        instruments = {}
        scripts, scripts_failed, instruments_2 = Script.load_and_append(
            data['scripts'], scripts, instruments)
    def __init__(self,
                 instruments,
                 scripts=None,
                 name=None,
                 settings=None,
                 log_function=None,
                 data_path=None):
        """
        init script function see superclass for details on the parameters
        """
        Script.__init__(self,
                        name,
                        settings=settings,
                        scripts=scripts,
                        instruments=instruments,
                        log_function=log_function,
                        data_path=data_path)

        self.data = {'temperature': deque()}
Beispiel #20
0
    def __init__(self,
                 scripts,
                 name=None,
                 settings=None,
                 instruments=None,
                 log_function=None,
                 timeout=1000000000,
                 data_path=None):

        Script.__init__(self,
                        name,
                        scripts=scripts,
                        settings=settings,
                        instruments=instruments,
                        log_function=log_function,
                        data_path=data_path)

        self.scripts['scan_z'].update({'scan_axes': 'z'})
        self.scripts['scan_z'].update({'RoI_mode': 'center'})
    def __init__(self,
                 scripts,
                 name=None,
                 settings=None,
                 log_function=None,
                 data_path=None):
        """
        Default script initialization
        """
        Script.__init__(self,
                        name,
                        scripts=scripts,
                        settings=settings,
                        log_function=log_function,
                        data_path=data_path)

        self.iterator_type = self.get_iterator_type(self.settings, scripts)

        self._current_subscript_stage = None
    def to_dict(self):
        """
        Returns: itself as a dictionary
        """
        dictator = Script.to_dict(self)
        # the dynamically created ScriptIterator classes have a generic name
        # replace this with ScriptIterator to indicate that this class is of type ScriptIterator
        dictator[self.name]['class'] = 'ScriptIterator'

        return dictator
Beispiel #23
0
    def __init__(self,
                 instruments,
                 name=None,
                 settings=None,
                 log_function=None,
                 data_path=None):
        """
        Example of a script that makes use of an instrument
        Args:
            instruments: instruments the script will make use of
            name (optional): name of script, if empty same as class name
            settings (optional): settings for this script, if empty same as default settings
        """

        # call init of superclass
        Script.__init__(self,
                        name,
                        settings,
                        instruments,
                        log_function=log_function,
                        data_path=data_path)
Beispiel #24
0
 def __init__(self,
              instruments=None,
              scripts=None,
              name=None,
              settings=None,
              log_function=None,
              data_path=None):
     """
     Example of a script that emits a QT signal for the gui
     Args:
         name (optional): name of script, if empty same as class name
         settings (optional): settings for this script, if empty same as default settings
     """
     Script.__init__(self,
                     name,
                     settings=settings,
                     instruments=instruments,
                     scripts=scripts,
                     log_function=log_function,
                     data_path=data_path)
     self.azimuth_controller = self.instruments['KDC101']['instance']
Beispiel #25
0
    def plot(self, figure_list):
        '''
        Plots a dot on top of each selected NV, with a corresponding number denoting the order in which the NVs are
        listed.
        Precondition: must have an existing image in figure_list[0] to plot over
        Args:
            figure_list:
        '''
        # if there is not image data get it from the current plot
        if not self.data == {} and self.data['image_data'] is None:
            axes = figure_list[0].axes[0]
            if len(axes.images) > 0:
                self.data['image_data'] = np.array(axes.images[0].get_array())
                self.data['extent'] = np.array(axes.images[0].get_extent())
                self.plot_settings['cmap'] = axes.images[0].get_cmap().name
                self.plot_settings['xlabel'] = axes.get_xlabel()
                self.plot_settings['ylabel'] = axes.get_ylabel()
                self.plot_settings['title'] = axes.get_title()
                self.plot_settings['interpol'] = axes.images[
                    0].get_interpolation()

        Script.plot(self, figure_list)
Beispiel #26
0
    def __init__(self,
                 instruments,
                 name=None,
                 settings=None,
                 log_function=None,
                 data_path=None):
        '''
        Initializes GalvoScan script for use in gui

        Args:
            instruments: list of instrument objects
            name: name to give to instantiated script object
            settings: dictionary of new settings to pass in to override defaults
            log_function: log function passed from the gui to direct log calls to the gui log
            data_path: path to save data

        '''
        Script.__init__(self,
                        name,
                        settings=settings,
                        instruments=instruments,
                        log_function=log_function,
                        data_path=data_path)
 def __init__(self,
              instruments=None,
              scripts=None,
              name=None,
              settings=None,
              log_function=None,
              data_path=None):
     """
     Example of a script that emits a QT signal for the gui
     Args:
         name (optional): name of script, if empty same as class name
         settings (optional): settings for this script, if empty same as default settings
     """
     Script.__init__(self,
                     name,
                     settings=settings,
                     instruments=instruments,
                     scripts=scripts,
                     log_function=log_function,
                     data_path=data_path)
     if self.settings['daq_type'] == 'PCI':
         self.daq_out = self.instruments['NI6259']['instance']
     elif self.settings['daq_type'] == 'cDAQ':
         self.daq_out = self.instruments['NI9263']['instance']
Beispiel #28
0
    def _update(self, axes_list):
        """
        updates the data in already existing plots. the axes objects are provided in axes_list
        Args:
            axes_list: a list of axes objects, this should be implemented in each subscript

        Returns: None

        """
        plot_type = self.settings['plot_style']
        if plot_type == '2D':
            # we expect exactely one image in the axes object (see ScriptDummy.plot)
            implot = axes_list[1].get_images()[0]
            # now update the data
            implot.set_data(self.data['random data'])

            colorbar = implot.colorbar

            if not colorbar is None:
                colorbar.update_bruteforce(implot)

        else:
            # fall back to default behaviour
            Script._update(self, axes_list)
Beispiel #29
0
def galvo_images(data_path, target_path = None):
    """
    save load data from galvo scans and save images to target directory
    Args:
        data_path: path to image data
        target_path: target path to save images

    Returns:

    """
    if target_path == None:
        target_path = DATA_PATH

    data  = Script.load_data(DATA_PATH)
    number_of_images = len([k for k in data.keys() if len(k.split('image'))>1])

    for c in range(number_of_images):
        k  = 'image_{:d}'.format(c)
        fig = plt.figure()
        ax = plt.subplot(111)
        plot_fluorescence(data[k], extent =[0.02, 0.17, 0.05, -0.10], axes = ax)
        fig.savefig('{:s}/{:s}.png'.format(TARGET_PATH, k))
        fig.close()
Beispiel #30
0
        elif self.scripts['deer_pwr'].is_running:
            self.scripts['deer_pwr']._update_plot(axes_list)
        elif self.scripts['deer_RFpitime'].is_running:
            self.scripts['deer_RFpitime']._update_plot(axes_list)

    # def get_axes_layout(self, figure_list):
    #     """
    #     returns the axes objects the script needs to plot its data
    #     the default creates a single axes object on each figure
    #     This can/should be overwritten in a child script if more axes objects are needed
    #     Args:
    #         figure_list: a list of figure objects
    #     Returns:
    #         axes_list: a list of axes objects
    #
    #     """
    #
    #     # create a new figure list that contains only figure 1, this assures that the super.get_axes_layout doesn't
    #     # empty the plot contained on figure 2
    #     # return super(EsrRabiDeer, self).get_axes_layout([figure_list[0]])
    #
    #     return super(EsrRabiDeer, self).get_axes_layout(figure_list)


if __name__ == '__main__':
    script, failed, instr = Script.load_and_append(
        {'EsrRabiDeerXYnSpectrumAdvanced': EsrRabiDeerXYnSpectrumAdvanced})

    print(script)
    print(failed)
    print(instr)