Esempio n. 1
0
    def plot_data(axes_list, data):
        plot_fluorescence_new(data['image_data'], data['extent'], axes_list[0])

        initial_point = data['initial_point']
        patch = patches.Circle((initial_point['x'], initial_point['y']),
                               .001,
                               ec='g',
                               fc='none',
                               ls='dashed')
        axes_list[0].add_patch(patch)
        axes_list[0].text(initial_point['x'],
                          initial_point['y'] - .002,
                          'initial point',
                          color='g',
                          fontsize=8)

        # plot marker
        if data['maximum_point']:
            maximum_point = data['maximum_point']
            patch = patches.Circle((maximum_point['x'], maximum_point['y']),
                                   .001,
                                   ec='r',
                                   fc='none',
                                   ls='dashed')
            axes_list[0].add_patch(patch)
            axes_list[0].text(maximum_point['x'],
                              maximum_point['y'] - .002,
                              'found NV',
                              color='r',
                              fontsize=8)
Esempio n. 2
0
    def _plot(self, axes_list, data=None):
        # fit the data and set piezo to focus spot
        if data is None:
            data = self.data
        axis_focus, axis_image = axes_list

        # if take image is running we take the data from there otherwise we use the scripts own image data
        if self._current_subscript_stage['current_subscript'] is self.scripts['take_image']:

            if 'image_data' in self.scripts['take_image'].data:
                current_image = self.scripts['take_image'].data['image_data']
                extent = self.scripts['take_image'].data['extent']
            else:
                current_image = None
        elif self._current_subscript_stage['current_subscript'] is self.scripts['take_image_2']:

            if 'image_data' in self.scripts['take_image_2'].data:
                current_image = self.scripts['take_image_2'].data['image_data']
                extent = self.scripts['take_image_2'].data['extent']
            else:
                current_image = None
        else:
            current_image = data['current_image']
            extent = data['extent']
        if current_image is not None:
            plot_fluorescence_new(current_image, extent, axis_image)

        if ('focus_function_result' in data) and ('focus_function_result_2' in data):
            focus_data = data['focus_function_result']
            focus_data_2 = data['focus_function_result_2']
            sweep_voltages = data['sweep_voltages']
            if len(focus_data) > 0:
                axis_focus.plot(sweep_voltages[0:len(focus_data)], focus_data, sweep_voltages[0:len(focus_data_2)], focus_data_2)
                if not (np.array_equal(data['fit_parameters'], [0, 0, 0, 0])):
                    axis_focus.plot(sweep_voltages[0:len(focus_data)],
                                    self.gaussian(sweep_voltages[0:len(focus_data)], *self.data['fit_parameters']),
                                    'k')
                if not (np.array_equal(data['fit_parameters_2'], [0, 0, 0, 0])):
                    axis_focus.plot(sweep_voltages[0:len(focus_data_2)],
                                    self.gaussian(sweep_voltages[0:len(focus_data_2)], *self.data['fit_parameters_2']),
                                    'g')
                axis_focus.hold(False)

        axis_focus.set_xlabel('Piezo Voltage [V]')

        if self.settings['focusing_optimizer'] == 'mean':
            ylabel = 'Image Mean [kcounts]'
        elif self.settings['focusing_optimizer'] == 'standard_deviation':
            ylabel = 'Image Standard Deviation [kcounts]'
        elif self.settings['focusing_optimizer'] == 'normalized_standard_deviation':
            ylabel = 'Image Normalized Standard Deviation [arb]'
        else:
            ylabel = self.settings['focusing_optimizer']

        axis_focus.set_ylabel(ylabel)
        axis_focus.set_title('Autofocusing Routine')
Esempio n. 3
0
 def _plot(self, axes_list, data=None):
     """
     Plots the galvo scan image
     Args:
         axes_list: list of axes objects on which to plot the galvo scan on the first axes object
         data: data (dictionary that contains keys image_data, extent) if not provided use self.data
     """
     if data is None:
         data = self.data
     plot_fluorescence_new(data['image_data'],
                           data['extent'],
                           axes_list[0],
                           max_counts=self.settings['max_counts_plot'])
Esempio n. 4
0
    def _plot(self, axes_list):
        '''
        Plots the newly taken galvo scan to axis 2, and the correlation image to axis 1
        Args:
            axes_list: list of axes to plot to. Uses two axes.

        '''
        if self.scripts['GalvoScan'].is_running:
            self.scripts['GalvoScan']._plot(axes_list)
        else:
            if not self.data['new_image'] == [] and not self.data[
                    'image_extent'] == []:
                data = self.data['new_image']
                extent = self.data['image_extent']
                plot_fluorescence_new(data, extent, axes_list[1])
                if not self.data['correlation_image'] == []:
                    axes_list[0].imshow(self.data['correlation_image'])
            else:
                self.scripts['GalvoScan']._plot(axes_list)
Esempio n. 5
0
    def _plot(self, axes_list):
        '''
        Plots the newly taken galvo scan to axis 2, and the correlation image to axis 1
        Args:
            axes_list: list of axes to plot to. Uses two axes.

        '''
        if self.scripts['take_baseline_image'].is_running:
            self.scripts['take_baseline_image']._plot(axes_list)
        elif self.scripts['take_new_image'].is_running:
            self.scripts['take_new_image']._plot(axes_list)
        else:
            #when clicking on script to select it for the first time, don't attempt to plot as no data avaliable
            if self.data['baseline_image'] == []:
                return

            if not self.settings['display_processed_images'] or self.baseline_processed_image == []:
                plot_fluorescence_new(self.data['baseline_image'],
                                      self.data['baseline_extent'],
                                      axes_list[0])
            else:
                plot_fluorescence_new(self.baseline_processed_image,
                                      self.data['baseline_extent'],
                                      axes_list[0])

            #for the first run when only the baseline is taken, plot only that image
            if self.data['new_image'] == []:
                return

            # add patch that marks the region of interest
            x, y = self.data['new_image_extent'][0], self.data[
                'new_image_extent'][3]
            w, h = (self.data['new_image_extent'][1] -
                    self.data['new_image_extent'][0]), (
                        self.data['new_image_extent'][2] -
                        self.data['new_image_extent'][3])
            patch = patches.Rectangle((x, y),
                                      w,
                                      h,
                                      ec='c',
                                      fc='none',
                                      ls='dashed')
            axes_list[0].add_patch(patch)

            # add patch that marks the region of interest
            x, y = self.data['new_image_extent'][0] - self.data['shift'][
                0], self.data['new_image_extent'][3] - self.data['shift'][1]
            w, h = (self.data['new_image_extent'][1] -
                    self.data['new_image_extent'][0]), (
                        self.data['new_image_extent'][2] -
                        self.data['new_image_extent'][3])
            patch = patches.Rectangle((x, y),
                                      w,
                                      h,
                                      ec='r',
                                      fc='none',
                                      ls='dashed')
            axes_list[0].add_patch(patch)

            # plot correlation image
            if not self.data['correlation_image'] == []:
                # axes_list[1].imshow(self.data['correlation_image'], interpolation="nearest")
                plot_fluorescence_new(self.data['correlation_image'], [
                    0, self.data['correlation_image'].shape[0],
                    self.data['correlation_image'].shape[1], 0
                ], axes_list[1])
                axes_list[1].set_title('correlation image')

            # plot new image
            if not self.data['new_image'] == []:
                if not self.settings['display_processed_images']:
                    plot_fluorescence_new(self.data['new_image'],
                                          self.data['new_image_extent'],
                                          axes_list[2])
                else:
                    plot_fluorescence_new(self.new_processed_image,
                                          self.data['new_image_extent'],
                                          axes_list[2])
                axes_list[2].set_title(
                    'new image shifted by dx={:0.3f} dy={:0.3f}'.format(
                        self.data['shift'][0], self.data['shift'][1]))
Esempio n. 6
0
def perform_affine_transform(img_path_old, img_path_new, done_queue,
                             return_queue):
    import time

    pt11_widget = widgets.HTML("Pt 1: 0,0")
    pt12_widget = widgets.HTML("Pt 2: 0,0")
    pt13_widget = widgets.HTML("Pt 3: 0,0")
    pt21_widget = widgets.HTML("Pt 1: 0,0")
    pt22_widget = widgets.HTML("Pt 2: 0,0")
    pt23_widget = widgets.HTML("Pt 3: 0,0")

    display(pt11_widget)
    display(pt12_widget)
    display(pt13_widget)
    display(pt21_widget)
    display(pt22_widget)
    display(pt23_widget)

    #     f = plt.figure(figsize=(12, 6))

    #     ax0 = plt.subplot(121)
    #     ax1 = plt.subplot(122)

    f = plt.figure(figsize=(16, 8))
    gs = gridspec.GridSpec(1, 2, width_ratios=[1, 2])
    ax0 = plt.subplot(gs[0])
    ax1 = plt.subplot(gs[1])

    def onclick_old(event):
        if ax0.in_axes(event):
            if event.key == '1':
                pt11_widget.value = 'Pt 1: ' + str(event.xdata) + ',' + str(
                    event.ydata)
            elif event.key == '2':
                pt12_widget.value = 'Pt 2: ' + str(event.xdata) + ',' + str(
                    event.ydata)
            elif event.key == '3':
                pt13_widget.value = 'Pt 3: ' + str(event.xdata) + ',' + str(
                    event.ydata)
        elif ax1.in_axes(event):
            if event.key == '1':
                pt21_widget.value = 'Pt 1: ' + str(event.xdata) + ',' + str(
                    event.ydata)
            elif event.key == '2':
                pt22_widget.value = 'Pt 2: ' + str(event.xdata) + ',' + str(
                    event.ydata)
            elif event.key == '3':
                pt23_widget.value = 'Pt 3: ' + str(event.xdata) + ',' + str(
                    event.ydata)

    cid = f.canvas.mpl_connect('button_press_event', onclick_old)

    data_im_old = Script.load_data(img_path_old)
    image_old = data_im_old['image_data']
    extent_old = data_im_old['extent']
    nv_pts_old = data_im_old['nv_locations']

    plot_fluorescence_new(image_old, extent_old, ax0)
    f.get_axes()[2].remove()

    data_im_new = Script.load_data(img_path_new)
    image_new = data_im_new['image_data']
    extent_new = data_im_new['extent']
    nv_pts_new = data_im_new['nv_locations']

    plot_fluorescence_new(image_new, extent_new, ax1)
    f.get_axes()[2].remove()

    plt.show()

    while done_queue.empty():
        time.sleep(.5)

    pt11 = map(
        float,
        pt11_widget.value.replace(" ", "").replace(':', ',').split(',')[1:3])
    pt12 = map(
        float,
        pt12_widget.value.replace(" ", "").replace(':', ',').split(',')[1:3])
    pt13 = map(
        float,
        pt13_widget.value.replace(" ", "").replace(':', ',').split(',')[1:3])
    pt21 = map(
        float,
        pt21_widget.value.replace(" ", "").replace(':', ',').split(',')[1:3])
    pt22 = map(
        float,
        pt22_widget.value.replace(" ", "").replace(':', ',').split(',')[1:3])
    pt23 = map(
        float,
        pt23_widget.value.replace(" ", "").replace(':', ',').split(',')[1:3])

    Avec = calc_transform_matrix((pt11, pt12, pt13), (pt21, pt22, pt23))
    Amat = [[Avec[0], Avec[1], Avec[2]], [Avec[3], Avec[4], Avec[5]],
            [0, 0, 1]]

    shifted_nv_pts_old = []

    for pt in nv_pts_old:
        circ = patches.Circle((pt[0], pt[1]), .0005, fc='k', ec='k')
        ax0.add_patch(circ)

        vec = [pt[0], pt[1], 1]
        vec_prime = np.dot(Amat, vec)

        circ = patches.Circle((vec_prime[0], vec_prime[1]),
                              .0005,
                              fc='k',
                              ec='k')
        ax1.add_patch(circ)

        shifted_nv_pts_old.append([vec_prime[0], vec_prime[1]])

    for pt in nv_pts_new:
        circ = patches.Circle((pt[0], pt[1]), .0005, fc='g', ec='g')
        ax1.add_patch(circ)

    tree = scipy.spatial.KDTree(shifted_nv_pts_old)
    _, new_to_old_map = tree.query(nv_pts_new, distance_upper_bound=.005)
    #kd tree returns value of len(new_to_old_map) if no match found, change this to -1
    new_to_old_map = [
        x if x != len(nv_pts_old) else -1 for x in new_to_old_map
    ]

    return_queue.put(new_to_old_map)