In [16]:
%matplotlib notebook
import numpy as np
import matplotlib.pyplot as plt
import h5py
In [2]:
fpath = '/Users/lili/Research/Experiment/SRX_Aakriti/2015_11_13_22_26_pyxrf.h5'
In [3]:
with h5py.File(fpath, 'r') as f:
d = f['xrfmap/detsum/counts'][:]
In [4]:
# 3D fluorescence data
# shape is [number of row, number of col, number of points in spectrum]
d.shape
Out[4]:
In [11]:
# x axis as energy in kev
x = np.arange(4096)
x = 0.01*x # approximately transfer channel number to kev
# choose two areas
d1 = d[0:5,0:5,:] # define y position from 0 to 5, x from 0 to 5, top left area
d2 = d[5:10,5:10,:] # define y position from 5 to 10, choose x from 5 to 10, bottom right area
# sum spectrum in those two areas
y1 = np.sum(d1, axis=(0,1)) # sum along axis 0 and 1 to get summed 1D spectrum curve
y2 = np.sum(d2, axis=(0,1))
In [23]:
# compare spectrum in those two areas
fig, ax = plt.subplots()
ax.plot(x, y1, label='area1')
ax.plot(x, y2, label='area2')
ax.legend()
Out[23]:
In [24]:
# log plot
fig, ax = plt.subplots()
ax.semilogy(x, y1, label='area1')
ax.semilogy(x, y2, label='area2')
ax.legend()
Out[24]:
In [25]:
# log plot and zoom in
fig, ax = plt.subplots()
ax.semilogy(x, y1, label='area1')
ax.semilogy(x, y2, label='area2')
ax.legend()
ax.set_xlim([1,13])
Out[25]:
In [15]:
# choose a roi to plot 2D image, like Fe
d_fe = d[:, :, 610:660]
fe = np.sum(d_fe, axis=(2)) # sum along axis 2
fig, ax = plt.subplots()
ax.imshow(fe)
Out[15]:
In [ ]: