In [1]:
import matplotlib.pyplot as plt
import numpy as np
from pyTOF import Block,ITA
import os
%matplotlib inline
import matplotlib as mpl
mpl.rc('axes',grid=False)
filename= os.getenv("HOMEPATH")+r"\Dropbox\TOF_SIMS\AuTi_big_40um_24_1.ita"
A = ITA.ITA(filename)
In [2]:
print("The ITA image has {N} scans and a size of {x}x{y} pixels".format(N=A.Nscan,x=A.sx,y=A.sy))
You can see all the channels you recorded and their mass (lower, average and upper mass limit)
In [3]:
A.showMassInt()
In [4]:
plt.imshow(A.getAddedImageByMass(42),cmap='hot');
In [5]:
plt.imshow(A.getXsectionByMass(0,255,511,255,0),cmap='hot');
In [6]:
fig, ax = plt.subplots(1,2,figsize=(14,7))
ax[0].imshow(A.getSumImageByMass(42,range(0,10)),cmap='hot');
ax[0].set_title("10 first scans")
ax[1].imshow(A.getSumImageByMass(42,range(10,A.Nscan)),cmap='hot');
ax[1].set_title("Skipping the 10 first scans");
In [7]:
Z,ch = A.getAddedImageByName('CN')
print("List of the selected channels")
for z in ch:
print("\t{name} ({desc}), mass: {lower:.2f} - {upper:.2f}".format(desc=z[b'desc']['utf16'],name=z[b'assign']['utf16'],lower=z[b'lmass']['float'],upper=z[b'umass']['float']))
plt.imshow(Z,cmap='hot');
Some process are quite slow depending on how many scans and channels you are summing. If you need all the scans, always use the function getAddedImageByName() and getAddedImageByMass(). Otherwise use getSumImageByName() and getSumImageByMass() which will sum manually all the selected scans.
As this progress might be slow you can display a progressbar of the current status by adding the option prog=True to your functions. Note that this requires to have the library tqdm installed [ https://pypi.python.org/pypi/tqdm ]
In [8]:
from IPython.display import HTML
fig, ax = plt.subplots(1,2,figsize=(14,7))
# Very Fast
Z,ch = A.getAddedImageByName('C')
v="<h3>List of the selected channels</h3><ul>"
for z in ch:
v+="<li>{name} ({desc}) {lower:.2f} - {upper:.2f}</li>".format(desc=z[b'desc']['utf16'],name=z[b'assign']['utf16'],lower=z[b'lmass']['float'],upper=z[b'umass']['float'])
v+="</ul>"
ax[0].imshow(Z,cmap='hot');
HTML(v)
# Slow. Add a progressbar
Z,ch = A.getSumImageByName('C',prog=True)
ax[1].imshow(Z,cmap='hot');
In [9]:
B = ITA.ITA_collection(filename,['Ti','Au','C'])
print("Channel selected")
print(B.msg)
The channel selected is listed in the B.msg string. In case you want only the Au,AuO and AuO_2 channels, you can use regexp (https://docs.python.org/2/library/re.html) to target the channel more acurately:
In [10]:
B = ITA.ITA_collection(filename,['Ti','Au[O_0-9]*-$','C'])
print("Channel selected")
print(B.msg)
This will lead to a channel name with a weird name (regexp string). You can use your own name by using a dictionnary as follow:
In [11]:
B = ITA.ITA_collection(filename,{'Ti':'Ti','Au':'Au[O_0-9]*-$','C':'C'},name='Example')
print("Channel selected")
print(B.msg)
Plotting all the channel of interest (here Ti, Au carbons) has never been so easy:
In [12]:
B.show()
In [13]:
B.showPCA()
print(B.loadings())
The PCA object is the variable P (so B.P is this example). You can call various PCA functions (still in development for the moment).
In [14]:
B.P.screeplot()
In [15]:
B.P.pca_scatter()
In [16]:
# Shows the correlation matrix
B.P.corrShow()
In [17]:
# Shows the hinton plot of the correlation matrix
B.P.hinton()
In [18]:
B.P.pca_summary()
Out[18]:
In [19]:
B.P.showStand()
Out[19]:
This library is far from complete and you might want to hack the raw data to find useful information out of your data like the date, comments, beam energy, etc.
The raw data are represented by hierarchic blocks. The root block is the object A.root (if A is the ITA.ITA object). Each children can be listed as follow:
In [20]:
A.root.showList()
You can reach a specific children throught it's path as a file in a folder with:
A.root.goto("filterdata/TofCorrection/ImageStack")
Large binary data, such as images are compressed with the zlib library. The following example show you how to plot the firt image saved (the total counts).
In [21]:
import zlib
import struct
import matplotlib as mpl
RAW=A.root.goto("filterdata/TofCorrection/ImageStack/Reduced Data/ImageStackScansAdded/Image/ImageArray.Long").value
D = zlib.decompress(RAW)
V = np.array(struct.unpack('<'+str(A.sx*A.sy)+'I',D),dtype=np.float).reshape((A.sy,A.sx))
mpl.rc('axes',grid=False)
plt.imshow(V,cmap='hot');