Beispiel #1
0
    def _transform(self):
        #self.method = Abel_methods[self.transform_method.get()]
        self.method = self.transform.get()
        self.fi = self.direction.get()
    
        if self.method != self.old_method or self.fi != self.old_fi:
            # Abel transform of whole image
            self.text.insert(tk.END,"\n{:s} {:s} Abel transform:".\
                             format(self.method, self.fi))
            if "basex" in self.method:
                self.text.insert(tk.END,
                              "\nbasex: first time calculation of the basis"
                              " functions may take a while ...")
            if "onion" in self.method:
               self.text.insert(tk.END,"\nonion_peeling: method is in early "
                              "testing and may not produce reliable results")
            if "direct" in self.method:
               self.text.insert(tk.END,"\ndirect: calculation is slowed if Cython"
                                       " unavailable ...")
            self.canvas.show()
    
            self.AIM = abel.transform(self.IM, method=self.method, 
                                      direction=self.fi,
                                      symmetry_axis=None)['transform']
            self.rmin.delete(0, tk.END)
            self.rmin.insert(0, self.rmx[0])
            self.rmax.delete(0, tk.END)
            self.rmax.insert(0, self.rmx[1])
    
        if self.old_method != self.method or self.fi != self.old_fi or\
           self.action not in ["speed", "anisotropy"]:
            self.plt[2].set_title(self.method+" {:s} Abel transform".format(self.fi),
                            fontsize=10)
            self.plt[2].imshow(self.AIM, vmin=0, vmax=self.AIM.max()/5.0)
            #self.f.colorbar(self.c.get_children()[2], ax=self.f.gca())
            #self.text.insert(tk.END, "{:s} inverse Abel transformed image".format(self.method))

        self.text.see(tk.END)
        self.old_method = self.method
        self.old_fi = self.fi
        self.canvas.show()
  "hansenlaw": abel.hansenlaw.hansenlaw_transform,
  "basex": abel.basex.basex_transform,   
  "three_point": abel.three_point.three_point_transform,
}

# sort dictionary:
transforms = collections.OrderedDict(sorted(transforms.items()))
# number of transforms:
ntrans = np.size(transforms.keys())
  
IM = abel.tools.analytical.sample_image(n=301, name="dribinski")

h, w = IM.shape

# forward transform:
fIM = abel.transform(IM, direction="forward", method="hansenlaw")['transform']

Q0, Q1, Q2, Q3 = abel.tools.symmetry.get_image_quadrants(fIM, reorient=True)

Q0fresh = Q0.copy()    # keep clean copy
print ("quadrant shape {}".format(Q0.shape))

# process Q0 quadrant using each method --------------------

iabelQ = []  # keep inverse Abel transformed image

for q, method in enumerate(transforms.keys()):

    Q0 = Q0fresh.copy()   # top-right quadrant of O2- image

    print ("\n------- {:s} inverse ...".format(method))  
           " center_image()".format(cols))
    im = abel.tools.center.center_image(im, center="com", odd_size=True)
    # alternative
    #im = shift(im,(0.5,0.5))
    #im = im[:-1, 1::]  # drop left col, bottom row
    (rows,cols) = np.shape(im)

c2 = cols//2   # half-image width
r2 = rows//2   # half-image height
print ('image size {:d}x{:d}'.format(rows,cols))

# Hansen & Law inverse Abel transform
print('Performing Hansen and Law inverse Abel transform:')

# quad = (True ... => combine the 4 quadrants into one
reconH = abel.transform (im, method="hansenlaw", direction="inverse", 
                         verbose=True, symmetry_axis=None)['transform']
rH, speedsH = abel.tools.vmi.angular_integration(reconH)

# Basex inverse Abel transform
print('Performing basex inverse Abel transform:')
reconB = abel.transform (im, method="basex", direction="inverse", 
                         verbose=True, symmetry_axis=None)['transform']
rB, speedsB = abel.tools.vmi.angular_integration(reconB)

# plot the results - VMI, inverse Abel transformed image, speed profiles
# Set up some axes
fig = plt.figure(figsize=(15,4))
ax1 = plt.subplot(131)
ax2 = plt.subplot(132)
ax3 = plt.subplot(133)
import abel
original     = abel.tools.analytical.sample_image()
forward_abel = abel.transform(original,     direction='forward', method='hansenlaw'  )['transform']
inverse_abel = abel.transform(forward_abel, direction='inverse', method='three_point')['transform']


# plot the original and transform
import matplotlib.pyplot as plt
import numpy as np
fig, axs = plt.subplots(1, 2, figsize=(6, 4))
axs[0].imshow(forward_abel, clim=(0, np.max(forward_abel)*0.6), origin='lower', extent=(-1,1,-1,1))
axs[1].imshow(inverse_abel, clim=(0, np.max(inverse_abel)*0.4), origin='lower', extent=(-1,1,-1,1))

axs[0].set_title('Forward Abel Transform')
axs[1].set_title('Inverse Abel Transform')

plt.tight_layout()
plt.savefig('example.png', dpi=150)
plt.show()
# Step 1: Load an image file as a numpy array
print('Loading ' + filename)
raw_data = plt.imread(filename).astype('float64')

# Step 2: Specify the center in y,x (vert,horiz) format
center = (245,340)
# or, use automatic centering
# center = 'com'
# center = 'gaussian'

# Step 3: perform the BASEX transform!
print('Performing the inverse Abel transform:')

recon = abel.transform(raw_data, direction='inverse', method='basex',
                       center=center, transform_options={'basis_dir':'./'},
                       verbose=True)['transform']
                      
speeds = abel.tools.vmi.angular_integration(recon)

# Set up some axes
fig = plt.figure(figsize=(15,4))
ax1 = plt.subplot(131)
ax2 = plt.subplot(132)
ax3 = plt.subplot(133)

# Plot the raw data
im1 = ax1.imshow(raw_data,origin='lower',aspect='auto')
fig.colorbar(im1,ax=ax1,fraction=.1,shrink=0.9,pad=0.03)
ax1.set_xlabel('x (pixels)')
ax1.set_ylabel('y (pixels)')
rows, cols = IM.shape    # image size

# Image center should be mid-pixel, i.e. odd number of colums
if cols % 2 != 1: 
    print ("HL: even pixel width image, re-adjusting image centre")
    IM = shift(IM, (-1/2, -1/2))[:-1, :-1]
    rows, cols = IM.shape   # new image size

r2 = rows//2   # half-height image size
c2 = cols//2   # half-width image size
print ('image size {:d}x{:d}'.format(rows, cols))

# Hansen & Law inverse Abel transform
print('Performing Hansen and Law inverse Abel transform:')

AIM = abel.transform(IM, method="hansenlaw", direction="inverse",
                     symmetry_axis=None)['transform']

# PES - photoelectron speed distribution  -------------
print('Calculating speed distribution:')

r, speed  = abel.tools.vmi.angular_integration(AIM)

# normalize to max intensity peak
speed /= speed[200:].max()  # exclude transform noise near centerline of image

# PAD - photoelectron angular distribution  ------------
print('Calculating angular distribution:')
# radial ranges (of spectral features) to follow intensity vs angle
# view the speed distribution to determine radial ranges
r_range = [(93, 111), (145, 162), (255, 280), (330, 350), (350, 370), 
           (370, 390), (390, 410), (410, 430)]
output_image = name + '_inverse_Abel_transform_HansenLaw.png'
output_text  = name + '_speeds_HansenLaw.dat'
output_plot  = name + '_comparison_HansenLaw.pdf'

# Step 1: Load an image file as a numpy array
print('Loading ' + filename)
#im = np.loadtxt(filename)
im = plt.imread(filename) 
(rows,cols) = np.shape(im)
print ('image size {:d}x{:d}'.format(rows,cols))


# Step 2: perform the Hansen & Law transform!
print('Performing Hansen and Law inverse Abel transform:')

recon = abel.transform(im, method="hansenlaw", direction="inverse", 
                       symmetry_axis=None, verbose=True, center=(240,340))['transform']
                       
r, speeds = abel.tools.vmi.angular_integration(recon)


# save the transform in 8-bit format:
#scipy.misc.imsave(output_image,recon)

# save the speed distribution
#np.savetxt(output_text,speeds)

## Finally, let's plot the data

# Set up some axes
fig = plt.figure(figsize=(15,4))
ax1 = plt.subplot(131)
# Image center should be mid-pixel, i.e. odd number of colums
if cols % 2 == 0:
    print("HL: even pixel width image, re-adjust image centre")
    # re-center image based on horizontal and vertical slice profiles
    # covering the radial range [300:400] pixels from the center
    IM = abel.tools.center.center_image(IM, center="com", odd_size=True)
    rows, cols = IM.shape  # new image size

c2 = cols // 2  # half-image
print("image size {:d}x{:d}".format(rows, cols))

# Step 2: perform the Hansen & Law transform!
print("Performing Hansen and Law inverse Abel transform:")

AIM = abel.transform(IM, method="hansenlaw", use_quadrants=(True, True, True, True), symmetry_axis=None, verbose=True)[
    "transform"
]

rs, speeds = abel.tools.vmi.angular_integration(AIM, dr=1)

# Set up some axes
fig = plt.figure(figsize=(15, 4))
ax1 = plt.subplot(131)
ax2 = plt.subplot(132)
ax3 = plt.subplot(133)

# Plot the raw data
im1 = ax1.imshow(IM, origin="lower", aspect="auto")
fig.colorbar(im1, ax=ax1, fraction=0.1, shrink=0.9, pad=0.03)
ax1.set_xlabel("x (pixels)")
ax1.set_ylabel("y (pixels)")