Esempio n. 1
0
    def __init__(self,
                 ap_series,
                 illu_ref=None,
                 reverse_y=False,
                 N=4096,
                 verbosity=1):
        """
    ap_series ... names of tif-images of the shifted aperture, shape (Nap,)
    illu_ref  ... (opt) name of reference to correct non-homogeneous illumination
    reverse_y ... (opt) True if y-axis should be inversed
    N         ... (opt) number of pixels of camera
    verbosity ... (opt) 0: silent, 1: minimal, 2: verbose, >10: debug
    """
        self.Npx = N
        self.ap_names = ap_series
        self.ref_name = illu_ref
        self.verbosity = verbosity
        self.history = []

        # load image files
        self.ref_img  = tif.imread(illu_ref,verbosity=verbosity) \
                                if illu_ref is not None else None
        # Ny,Nx
        self.ap_stack = tif.imread(ap_series, verbosity=verbosity)
        # Nap,Ny,Nx

        # reverse images
        if reverse_y:
            print "WARNING: in QDispersion: reverse_y==True"
            self.ref_img = self.ref_img[::-1]
            self.ap_stack = self.ap_stack[:, ::-1]

        # set image parameters
        self.Nap, self.Ny, self.Nx = self.ap_stack.shape
        self.ybin, self.xbin = self.Npx / float(self.Ny), self.Npx / float(
            self.Nx)
        self.crop_img()

        # transformations (identity by default)
        self.u2x = trafo.I()
        # normalised coordinates
        self.s2u = trafo.I()
        # slit coordinates = distortions of iso-q-lines
        self.q2s = trafo.I()
        # non-linear dispersion on q-axis

        # History + DEBUG
        self.history = [
            "momentum_dispersion.py, version %s (%s)" %
            (Release.version, Release.version_id)
        ]
        self.__dbg_fig = []
Esempio n. 2
0
  def __init__(self,ap_series,illu_ref=None,reverse_y=False,N=4096,verbosity=1):
    """
    ap_series ... names of tif-images of the shifted aperture, shape (Nap,)
    illu_ref  ... (opt) name of reference to correct non-homogeneous illumination
    reverse_y ... (opt) True if y-axis should be inversed
    N         ... (opt) number of pixels of camera
    verbosity ... (opt) 0: silent, 1: minimal, 2: verbose, >10: debug
    """
    self.Npx = N;
    self.ap_names = ap_series;
    self.ref_name = illu_ref;
    self.verbosity= verbosity
    self.history  = [];

    # load image files
    self.ref_img  = tif.imread(illu_ref,verbosity=verbosity) \
                            if illu_ref is not None else None; # Ny,Nx
    self.ap_stack = tif.imread(ap_series,verbosity=verbosity); # Nap,Ny,Nx

    # reverse images
    if reverse_y:
      print "WARNING: in QDispersion: reverse_y==True";
      self.ref_img= self.ref_img[::-1];
      self.ap_stack=self.ap_stack[:,::-1];

    # set image parameters
    self.Nap, self.Ny, self.Nx = self.ap_stack.shape;  
    self.ybin,self.xbin        = self.Npx/float(self.Ny), self.Npx/float(self.Nx);
    self.crop_img();

    # transformations (identity by default)
    self.u2x = trafo.I();  # normalised coordinates
    self.s2u = trafo.I();  # slit coordinates = distortions of iso-q-lines
    self.q2s = trafo.I();  # non-linear dispersion on q-axis

    # History + DEBUG
    self.history  = ["momentum_dispersion.py, version %s (%s)" % 
                     (Release.version, Release.version_id)];
    self.__dbg_fig=[];     # list of figures
Esempio n. 3
0
def get_peak_pos(filename, refname=None, medfilt_radius=5, sort=False, border=10, ampl_cut=0.5, verbosity=1):
  """
    calculate the position-dependent energy dispersion from 
    the distance between two peaks (ZLP and plasmon reference)

    filename ... file containing the spectrum image (Nspectra, Npx)
    refname  ... (opt) filename of reference spectrum for second peak
    medfilt_radius... (opt) median filter radius for smoothing of spectra
    sort     ... (opt) if True, sort spectra according to ZLP position
    border   ... (opt) skip peaks which are too close to the border (in pixel)
    ampl_cut ... (opt) skip peaks with amplitude smaller than ampl_cut*maximum
    verbosity... (opt) 0 (silent), 1 (minimal), 2 (plot), 3 (debug)

    RETURNS 
      x(N), zl(N) or 
      x(N), zl(N), pl(N) which are one-dimensional arrays of length N
       containing the x-value of the spectrum, the zero-loss and 
       plasmon-peak position.
       (N=Nspectra)
  """

  # 1. read EELS spectra of series
  if verbosity>0: print "Loading spectra from file '%s'"%filename;
  IN         = tiff.imread(filename); # Ny, Ns+1 
  data       = IN[:,:-1];
  x          = IN[:,-1];              # last line in image corresponds
                                      # to energie values
  
  # 2. fit ZLP to spectra
  zl,spectra = fit_zlp(data, border=border, medfilt_radius=medfilt_radius, 
                       ampl_cut=ampl_cut, verbosity=verbosity, sort=sort);

  if refname is None:
    if verbosity>2: plot_peaks(spectra, None, zl, None, filename=filename);
    return x,zl;

  # 3. fit second peak from correlation with reference spectrum
  spectra_noZLP=spectra.copy();
  for s in range(len(spectra)):  # for each spectrum, we remove the ZLP
    x0,I,fwhm = zl[s];           # parameters from ZLP
    xmin,xmax = max(0,x0-5*fwhm), min(len(spectra[s]),x0+5*fwhm);
    spectra_noZLP[s,xmin:xmax]=0;

  REF = MSA(refname).get_data();
  pl  = fit_plasmon(spectra_noZLP, REF, border=border,
      ampl_cut=ampl_cut, medfilt_radius=medfilt_radius, verbosity=verbosity);
  
  if verbosity>2: plot_peaks(spectra, REF, zl, pl, filename=filename);

  return x,zl,pl  
# 1. get calibration object
qdisp_name = 'QDisp.pkl';
FILE = open(qdisp_name,'r');
qcal= pickle.Unpickler(FILE).load();
FILE.close();
s2u,q2s = qcal['s2u'],qcal['q2s']; # unpack the single trafos
history = qcal['history'];
history+= "\n\nremove_qdistortion.py, version %s (%s)" % \
                     (Release.version, Release.version_id);
print 'READ QDispersion: ' + qcal['descr'];

# 2. distorted E-q map and normalize q-axis
# TODO: automatic fit for border ?
filename= '../tests/qseries_sum.tif';
img     = tiff.imread(filename);
Ny,Nx   = img.shape;
ybin,xbin=N/float(Ny), N/float(Nx);

x0,y0 = 2377,967;                  # position of reference point in WQmap
xl,xr = 0,N;                       # (opt) slit borders in WQmap (fine-tuning of spec-mag)
Gl,Gr = 1193,3527;                 # coordinates of left+right Bragg spot at y0
G = 2.96;                          # length |G| corresponding to x0-Gl and Gr-x0
u2x = trafo.Normalize(x0,y0,xl,xr);# (u,v) -> (x,y)
s2x = trafo.Seq(u2x,s2u);          # s -> u -> x
sl,_= s2x.inverse(Gl,y0);
sr,_= s2x.inverse(Gr,y0);
q2s = calibrate_qaxis(q2s,sl,sr,G);

history+="\nRawfile: %s"%filename;
history+="\n"+u2x.info(3);
Esempio n. 5
0
# -- main ----------------------------------------
if __name__ == '__main__':
    import TEMareels.tools.tifffile as tiff

    coeff = [[[8.53185497e-06, 5.74373869e-02, 6.63128635e+02],
              [7.69501010e-06, 4.65273936e-02, 7.89253445e+02]],
             [[6.45514206e-06, 4.10327089e-02, 9.00378881e+02],
              [6.12716673e-06, 2.82385482e-02, 1.07283189e+03]]]

    stack = []
    info = []
    lines = []
    for i in (1, 2):
        # read image from file
        filename = '../tests/qseries%d.tif' % i
        stack.append(tiff.imread(filename))

        # info for image
        info.append({
            'desc': 'WQStackBrowser: ' + filename,
            'filename': filename,
            'xperchan': 4.,
            'yperchan': 64.
        })

        # additional line plots
        y = np.arange(150, 4096)
        l1 = plt.Line2D(np.poly1d(coeff[i - 1][0])(y), y, color='r', ls='-')
        l2 = plt.Line2D(np.poly1d(coeff[i - 1][1])(y), y, color='g', ls='-')
        lines.append([l1, l2])
Esempio n. 6
0
# -- main ----------------------------------------
if __name__ == '__main__':
  import TEMareels.tools.tifffile as tiff
  
  coeff = [
[[  8.53185497e-06, 5.74373869e-02, 6.63128635e+02],
[   7.69501010e-06, 4.65273936e-02, 7.89253445e+02]],
[[  6.45514206e-06, 4.10327089e-02, 9.00378881e+02],
[   6.12716673e-06, 2.82385482e-02, 1.07283189e+03]]];


  stack = []; info = []; lines = [];
  for i in (1,2):
    # read image from file
    filename = '../tests/qseries%d.tif'%i;
    stack.append(tiff.imread(filename));

    # info for image
    info.append(  {'desc': 'WQStackBrowser: '+filename,
                   'filename':filename, 
                   'xperchan':4., 'yperchan':64.} );

    # additional line plots
    y  = np.arange(150,4096);
    l1 = plt.Line2D(np.poly1d(coeff[i-1][0])(y),y,color='r',ls='-');
    l2 = plt.Line2D(np.poly1d(coeff[i-1][1])(y),y,color='g',ls='-');
    lines.append([l1,l2]);

  # show single image
  IB =WQBrowser(stack[0],{'desc': 'WQBrowser'},aspect='auto',verbosity=4);
Esempio n. 7
0
   image[:,i] = image[:,i]-ref_line;
  offset += sector_width;
  #print offset 
 image[:,0:5]= image[:,-5:] = 0; 
 if verbosity > 0:
  plt.title("Remove Stripes: difference between old and new image");
  plt.imshow(image - old_image, aspect='auto')
  plt.show();
 return image;

 
 # -- main ----------------------------------------
if __name__ == '__main__':
  import TEMareels.tools.tifffile as tiff
  from TEMareels.tools import tvips


  image_file = '../tests/wqmap.tif';
  image = tiff.imread(image_file).astype(float);
  binning = 8;
  intstart= np.array([0,1025,2900,3800])/binning;
  
  img = remove_stripes(image, intwidth=100/binning, 
          intstart=intstart, sector_width=1024/binning, verbosity=1);
          
  #outfile = "script_test_.tif";
  #tvips.write_tiff(img, outfile);
  
 
  
Esempio n. 8
0
 y_start = y0;


 for i in range(0,Nx):
  peak_value = img[:,i].max();
  peak_index = img[:,i].argmax();
  if np.abs(peak_index - y_start)<delta:
   peaks.append([i,peak_index]);
   if verbosity > 9:
    plt.plot(i,peak_index, 'ro', linewidth=5);
 
 peaks = np.asarray(peaks);
 fit = np.polyfit(peaks[:,0],peaks[:,1],2);
 fitFunc = np.poly1d(fit)

 if verbosity > 9:
  plt.title('Find Zero-Loss Peak');
  plt.plot(x,fitFunc(x)); 
  plt.imshow(img, vmin=0, vmax=vmax, cmap='gray', aspect='auto');

 return fitFunc;
 
# -- main ----------------------------------------
if __name__ == '__main__':
  import TEMareels.tools.tifffile as tiff

  image = "../tests/wqmap.tif"; 
  img = tiff.imread(image)
  find_zlp(img, delta=10, vmax=img.max(), verbosity=11);
  plt.show();
Esempio n. 9
0
            image[:, i] = image[:, i] - ref_line
        offset += sector_width
        #print offset
    image[:, 0:5] = image[:, -5:] = 0
    if verbosity > 0:
        plt.title("Remove Stripes: difference between old and new image")
        plt.imshow(image - old_image, aspect='auto')
        plt.show()
    return image

    # -- main ----------------------------------------


if __name__ == '__main__':
    import TEMareels.tools.tifffile as tiff
    from TEMareels.tools import tvips

    image_file = '../tests/wqmap.tif'
    image = tiff.imread(image_file).astype(float)
    binning = 8
    intstart = np.array([0, 1025, 2900, 3800]) / binning

    img = remove_stripes(image,
                         intwidth=100 / binning,
                         intstart=intstart,
                         sector_width=1024 / binning,
                         verbosity=1)

    #outfile = "script_test_.tif";
    #tvips.write_tiff(img, outfile);
Esempio n. 10
0
   peak_value = img[:,iq].max();
   peak_index = ybin*img[:,iq].argmax();
   if np.abs(peak_index-y_start) < delta:
     peaks.append([q,peak_index]);
 
 peaks = np.asarray(peaks);
 fit = np.polyfit(peaks[:,0],peaks[:,1],2);
 fitFunc = np.poly1d(fit)

 if verbosity > 9:
  info = {'desc': 'Find Zero-Loss Peak',
          'yperchan':ybin, 'xperchan':qaxis[1]-qaxis[0], 
          'xlabel':'q', 'xunits':'1/A','xoffset' :qaxis[0]};
  WQB  = WQBrowser(img,info,aspect='auto');
  WQB.axis.plot(peaks[:,0],peaks[:,1], 'ro');  
  WQB.axis.plot(qaxis,fitFunc(qaxis)); 


 return fitFunc;
 
# -- main ----------------------------------------
if __name__ == '__main__':
  import TEMareels.tools.tifffile as tiff

  image = "../tests/wqmap.tif"; 
  img = tiff.imread(image);
  N,nq= img.shape;
  qaxis = np.linspace(-3,3,nq);
  find_zlp(img, qaxis, delta=10, vmax=img.max(),verbosity=11);
  plt.show();