示例#1
0
    def plot(self, **kwargs):
        self.configure()
        if self.figure is None:
            self.create_figure()
            self.create_axis()
        data = self.data_function(axes_manager=self.axes_manager)
        if rgb_tools.is_rgbx(data):
            self.colorbar = False
            data = rgb_tools.rgbx2regular_array(data, plot_friendly=True)
        self.optimize_contrast(data)
        if (not self.axes_manager or self.axes_manager.navigation_size == 0):
            self.plot_indices = False
        if self.plot_indices is True:
            if self._text is not None:
                self._text.remove()
            self._text = self.ax.text(
                *self._text_position,
                s=str(self.axes_manager.indices),
                transform=self.ax.transAxes,
                fontsize=12,
                color='red',
                animated=self.figure.canvas.supports_blit)
        for marker in self.ax_markers:
            marker.plot()
        self.update(**kwargs)
        if self.scalebar is True:
            if self.pixel_units is not None:
                self.ax.scalebar = widgets.ScaleBar(
                    ax=self.ax,
                    units=self.pixel_units,
                    animated=self.figure.canvas.supports_blit,
                    color=self.scalebar_color,
                )

        if self.colorbar is True:
            self._colorbar = plt.colorbar(self.ax.images[0], ax=self.ax)
            self._colorbar.set_label(self.quantity_label,
                                     rotation=-90,
                                     va='bottom')
            self._colorbar.ax.yaxis.set_animated(
                self.figure.canvas.supports_blit)

        self._set_background()
        self.figure.canvas.draw_idle()
        if hasattr(self.figure, 'tight_layout'):
            try:
                if self.axes_ticks == 'off' and not self.colorbar:
                    plt.subplots_adjust(0, 0, 1, 1)
                else:
                    self.figure.tight_layout()
            except:
                # tight_layout is a bit brittle, we do this just in case it
                # complains
                pass

        self.connect()
示例#2
0
    def plot(self, **kwargs):
        self.configure()
        if self.figure is None:
            self.create_figure()
            self.create_axis()
        data = self.data_function(axes_manager=self.axes_manager)
        if rgb_tools.is_rgbx(data):
            self.colorbar = False
            data = rgb_tools.rgbx2regular_array(data, plot_friendly=True)
        if self.vmin is not None or self.vmax is not None:
            warnings.warn('vmin or vmax value given, hence '
                          'auto_contrast is set to False')
            self.auto_contrast = False
        self.optimize_contrast(data)
        if (not self.axes_manager or self.axes_manager.navigation_size == 0):
            self.plot_indices = False
        if self.plot_indices is True:
            if self._text is not None:
                self._text.remove()
            self._text = self.ax.text(*self._text_position,
                                      s=str(self.axes_manager.indices),
                                      transform=self.ax.transAxes,
                                      fontsize=12,
                                      color='red',
                                      animated=True)
        for marker in self.ax_markers:
            marker.plot()
        self.update(**kwargs)
        if self.scalebar is True:
            if self.pixel_units is not None:
                self.ax.scalebar = widgets.ScaleBar(
                    ax=self.ax,
                    units=self.pixel_units,
                    animated=True,
                    color=self.scalebar_color,
                )

        if self.colorbar is True:
            self._colorbar = plt.colorbar(self.ax.images[0], ax=self.ax)
            self._colorbar.ax.yaxis.set_animated(True)

        self.figure.canvas.draw()
        if hasattr(self.figure, 'tight_layout'):
            try:
                self.figure.tight_layout()
            except:
                # tight_layout is a bit brittle, we do this just in case it
                # complains
                pass

        self.connect()
示例#3
0
    def plot(self, data_function_kwargs={}, **kwargs):
        self.data_function_kwargs = data_function_kwargs
        self.configure()
        if self.figure is None:
            self.create_figure()
            self.create_axis()

        if (not self.axes_manager or self.axes_manager.navigation_size == 0):
            self.plot_indices = False
        if self.plot_indices is True:
            if self._text is not None:
                self._text.remove()
            self._text = self.ax.text(
                *self._text_position,
                s=str(self.axes_manager.indices),
                transform=self.ax.transAxes,
                fontsize=12,
                color='red',
                animated=self.figure.canvas.supports_blit)
        for marker in self.ax_markers:
            marker.plot()
        for attribute in ['vmin', 'vmax']:
            if attribute in kwargs.keys():
                setattr(self, attribute, kwargs.pop(attribute))
        self.update(data_changed=True, auto_contrast=True, **kwargs)
        if self.scalebar is True:
            if self.pixel_units is not None:
                self.ax.scalebar = widgets.ScaleBar(
                    ax=self.ax,
                    units=self.pixel_units,
                    animated=self.figure.canvas.supports_blit,
                    color=self.scalebar_color,
                )

        if self.colorbar:
            self._add_colorbar()

        if hasattr(self.figure, 'tight_layout'):
            try:
                if self.axes_ticks == 'off' and not self.colorbar:
                    plt.subplots_adjust(0, 0, 1, 1)
                else:
                    self.figure.tight_layout()
            except BaseException:
                # tight_layout is a bit brittle, we do this just in case it
                # complains
                pass

        self.connect()
        self.figure.canvas.draw()
示例#4
0
  ax = fig.add_subplot(1,1,1)

  # save corrected image as png and hdf5. The 'hdf5' file contains original intensity information an can be used for the quantification of intensity.
  filename = img.metadata.General.original_filename
  img.mean(0).save("%s.png" %(filename), overwrite=True)
  img.mean(0).save("%s.hdf5" %(filename), overwrite=True)
  np.savetxt('%s.csv' %(filename),  shift, delimiter=',')
  #print("%s is aligned" %(filename))
  
  # Save images with scale bar in a different folder.

  os.chdir('scalebar')
  imgplot = ax.imshow(img.mean(0).data, extent=[0,cal*resx,0,cal*resy])
  #imgplot.set_clim(min, max)
  #scalebar = widgets.Scale_Bar(ax=ax, units='%s' %(unit), lw=4, color='white', max_size_ratio=0.12)
  scalebar = widgets.ScaleBar(ax=ax, units=unit, lw=4, color='white', max_size_ratio=0.15)
  #cbar = fig.colorbar(imgplot)
  
  ax.set_frame_on(False)
  ax.axes.get_yaxis().set_visible(False)
  ax.axes.get_xaxis().set_visible(False)
 
  filename = img.metadata.General.original_filename
  plt.rcParams['mathtext.fontset'] = "stix"
  plt.subplots_adjust(bottom=0, left=0, right=1, top=1)
  plt.savefig("%s.tiff" %(filename), frameon=False, overwrite=True, dpi=dpx)
  plt.close()
  print("%s is aligned and converted" %(filename))
  os.chdir('../')

print("Batch convert mission is completed")
示例#5
0
    cal = img.original_metadata.ImageList.TagGroup0.ImageData.Calibrations.Dimension.TagGroup0.Scale
    unit = img.original_metadata.ImageList.TagGroup0.ImageData.Calibrations.Dimension.TagGroup0.Units
    dpx = res * 100.0 / 480.0

    ## scale bar for 2nm
    #scale = 2/cal/res
    #print scale

    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)

    imgplot = ax.imshow(img.data, extent=[0, cal * res, 0, cal * res])
    imgplot.set_clim(min, max)
    scalebar = widgets.ScaleBar(ax=ax,
                                units='%s' % (unit),
                                lw=4,
                                color='white',
                                max_size_ratio=0.12)
    #cbar = fig.colorbar(imgplot)

    ax.set_frame_on(False)
    ax.axes.get_yaxis().set_visible(False)
    ax.axes.get_xaxis().set_visible(False)
    #plt.axhline(y=res*(1-0.05), xmin=0.05, xmax=0.05+scale, linewidth=4, color='w')
    #ax.set_title("Sample")
    #plt.show()
    filename = img.metadata.General.get_item('title')

    plt.rcParams['mathtext.fontset'] = "stix"

    #  plt.savefig("%s.png" %(filename), frameon=False, overwrite=True, dpi=dpx)
示例#6
0
    def plot(self, **kwargs):
        self.configure()
        if self.figure is None:
            self.create_figure()
            self.create_axis()
        data = self.data_function(axes_manager=self.axes_manager)
        if rgb_tools.is_rgbx(data):
            self.colorbar = False
            data = rgb_tools.rgbx2regular_array(data, plot_friendly=True)
        self.optimize_contrast(data)
        if (not self.axes_manager or
                self.axes_manager.navigation_size == 0):
            self.plot_indices = False
        if self.plot_indices is True:
            if self._text is not None:
                self._text.remove()
            self._text = self.ax.text(
                *self._text_position,
                s=str(self.axes_manager.indices),
                transform=self.ax.transAxes,
                fontsize=12,
                color='red',
                animated=self.figure.canvas.supports_blit)
        for marker in self.ax_markers:
            marker.plot()
        self.update(**kwargs)
        if self.scalebar is True:
            if self.pixel_units is not None:
                self.ax.scalebar = widgets.ScaleBar(
                    ax=self.ax,
                    units=self.pixel_units,
                    animated=self.figure.canvas.supports_blit,
                    color=self.scalebar_color,
                )

        if self.colorbar is True:
            self._colorbar = plt.colorbar(self.ax.images[0], ax=self.ax)
            self._colorbar.set_label(
                self.quantity_label, rotation=-90, va='bottom')
            self._colorbar.ax.yaxis.set_animated(
                self.figure.canvas.supports_blit)

        self._set_background()
        if hasattr(self.figure, 'tight_layout'):
            try:
                if self.axes_ticks == 'off' and not self.colorbar:
                    plt.subplots_adjust(0, 0, 1, 1)
                else:
                    self.figure.tight_layout()
            except BaseException:
                # tight_layout is a bit brittle, we do this just in case it
                # complains
                pass

        self.connect()
        # ask the canvas to re-draw itself the next time it
        # has a chance.
        # For most of the GUI backends this adds an event to the queue
        # of the GUI frameworks event loop.
        self.figure.canvas.draw_idle()
        try:
            # make sure that the GUI framework has a chance to run its event loop
            # and clear any GUI events.  This needs to be in a try/except block
            # because the default implementation of this method is to raise
            # NotImplementedError
            self.figure.canvas.flush_events()
        except NotImplementedError:
            pass