In [4]:
import numpy as np
from matplotlib.ticker import MaxNLocator
from matplotlib.colors import LogNorm
import matplotlib.pyplot as plt
import matplotlib.patches as mp
from matplotlib import cm
import matplotlib as mpl
%matplotlib notebook
import skbeam.core.correlation as corr
import skbeam.core.roi as roi
import skbeam.core.mask as mask
In [5]:
num_levels = 6
num_bufs = 8
# if we are 1.5 or later
if float('.'.join(mpl.__version__.split('.')[:2])) >= 1.5:
cmap = 'viridis'
else:
cmap = 'CMRmap'
# load the data
img_stack = np.load("100_500_NIPA_GEL.npy")
fig, ax = plt.subplots()
# plot the first image to make sure the data loaded correctly
ax.imshow(img_stack[0], cmap=cmap)
ax.set_title("NIPA_GEL_250K")
Out[5]:
In [6]:
# define the ROIs
roi_start = 78 # in pixels
roi_width = 9 # in pixels
#roi_spacing = (5.0, 4.0)
x_center = 7. # in pixels
y_center = (129.) # in pixels
num_rings = 1
# get the edges of the rings
edges = roi.ring_edges(roi_start, width=roi_width, num_rings=num_rings)
# get the label array from the ring shaped 3 region of interests(ROI's)
labeled_roi_array = roi.rings(
edges, (y_center, x_center), img_stack.shape[1:])
In [7]:
fig, ax = plt.subplots()
ax.imshow(labeled_roi_array)
plt.show()
In [9]:
y = []
for i in range(10000):
y.append(img_stack[0])
In [10]:
g2y, lag_steps = corr.multi_tau_auto_corr(num_levels, num_bufs,
labeled_roi_array, np.asarray(y))
In [11]:
fig, ax = plt.subplots()
ax.semilogx(lag_steps, g2y[:, 0], "o", label="No bad imgs")
ax.set_ylim(bottom=1.014, top=1.018)
ax.legend()
plt.show()
In [12]:
bad_list = np.random.choice(np.arange(10000), size=10)
imgs = mask.bad_to_nan_gen(y, bad_list)
bad_list
Out[12]:
In [13]:
g2_10, lag_steps_n = corr.multi_tau_auto_corr(num_levels, num_bufs,
labeled_roi_array, imgs)
In [14]:
fig, ax = plt.subplots()
ax.semilogx(lag_steps, g2y[:, 0], "bo", label="No bad imgs")
ax.semilogx(lag_steps, g2_10[:, 0], "r*", label="with bad imgs")
ax.set_ylim(bottom=1.014, top=1.018)
ax.set_title("10 bad images")
ax.legend()
plt.show()
In [ ]:
## 20 bad images
In [15]:
bad_list_2 = np.random.choice(np.arange(10000), size=20)
imgs = mask.bad_to_nan_gen(y, bad_list_2)
bad_list_2
Out[15]:
In [16]:
g2_20, lag_steps_n = corr.multi_tau_auto_corr(num_levels, num_bufs,
labeled_roi_array, imgs)
In [17]:
fig, ax = plt.subplots()
ax.semilogx(lag_steps, g2y[:, 0], "bo", label="No bad imgs")
ax.semilogx(lag_steps, g2_20[:, 0], "r*", label="With bad imgs")
ax.set_ylim(bottom=1.014, top=1.018)
ax.set_title("20 bad images")
ax.legend()
plt.show()
In [18]:
bad_list_3 = np.random.choice(np.arange(10000), size=50)
bad_list_3
Out[18]:
In [19]:
imgs = mask.bad_to_nan_gen(y, bad_list_3)
g2_50, lag_steps_n = corr.multi_tau_auto_corr(num_levels, num_bufs,
labeled_roi_array, imgs)
fig, ax = plt.subplots()
ax.semilogx(lag_steps, g2y[:, 0], "bo", label="No bad imgs")
ax.semilogx(lag_steps, g2_50[:, 0], "r*", label="With bad imgs")
ax.set_ylim(bottom=1.014, top=1.018)
ax.set_title("50 bad images")
ax.legend()
plt.show()
In [20]:
bad_list_100 = np.random.choice(np.arange(10000), size=100)
bad_list_100
Out[20]:
In [22]:
imgs = mask.bad_to_nan_gen(y, bad_list_100)
g2_100, lag_steps_n = corr.multi_tau_auto_corr(num_levels, num_bufs,
labeled_roi_array, imgs)
fig, ax = plt.subplots()
ax.semilogx(lag_steps, g2y[:, 0], "bo", label="No bad imgs")
ax.semilogx(lag_steps, g2_100[:, 0], "r*", label="With bad imgs")
ax.set_ylim(bottom=1.014, top=1.018)
ax.set_title("100 bad images")
ax.legend()
plt.show()
In [23]:
bad_list_200 = np.random.choice(np.arange(10000), size=200)
bad_list_200
Out[23]:
In [24]:
imgs = mask.bad_to_nan_gen(y, bad_list_200)
g2_200, lag_steps_n = corr.multi_tau_auto_corr(num_levels, num_bufs,
labeled_roi_array, imgs)
fig, ax = plt.subplots()
ax.semilogx(lag_steps, g2y[:, 0], "bo", label="No bad imgs")
ax.semilogx(lag_steps, g2_200[:, 0], "r*", label="With bad imgs")
ax.set_ylim(bottom=1.014, top=1.018)
ax.set_title("200 bad images")
ax.legend()
plt.show()
In [25]:
bad_list_300 = np.random.choice(np.arange(10000), size=300)
bad_list_300
Out[25]:
In [26]:
imgs = mask.bad_to_nan_gen(y, bad_list_300)
g2_300, lag_steps_n = corr.multi_tau_auto_corr(num_levels, num_bufs,
labeled_roi_array, imgs)
fig, ax = plt.subplots()
ax.semilogx(lag_steps, g2y[:, 0], "bo", label="No bad imgs")
ax.semilogx(lag_steps, g2_300[:, 0], "r*", label="With bad imgs")
ax.set_ylim(bottom=1.014, top=1.018)
ax.set_title("300 bad images")
ax.legend()
plt.show()
In [28]:
bad_list_500 = np.random.choice(np.arange(10000), size=500)
imgs = mask.bad_to_nan_gen(y, bad_list_500)
g2_500, lag_steps_n = corr.multi_tau_auto_corr(num_levels, num_bufs,
labeled_roi_array, imgs)
fig, ax = plt.subplots()
ax.semilogx(lag_steps, g2y[:, 0], "bo", label="No bad imgs")
ax.semilogx(lag_steps, g2_500[:, 0], "r*", label="With bad imgs")
ax.set_ylim(bottom=1.014, top=1.018)
ax.set_title("500 bad images")
ax.legend()
plt.show()
In [31]:
bad_list_1000 = np.random.choice(np.arange(10000), size=1000)
imgs = mask.bad_to_nan_gen(y, bad_list_1000)
g2_1000, lag_steps_n = corr.multi_tau_auto_corr(num_levels, num_bufs,
labeled_roi_array, imgs)
fig, ax = plt.subplots()
ax.semilogx(lag_steps, g2y[:, 0], "bo", label="No bad imgs")
ax.semilogx(lag_steps_n, g2_1000[:, 0], "r*", label="With bad imgs")
ax.set_ylim(bottom=1.014, top=1.018)
ax.set_title("1000 bad images")
ax.legend()
plt.show()
In [32]:
bad_list_2000 = np.random.choice(np.arange(10000), size=2000)
imgs = mask.bad_to_nan_gen(y, bad_list_2000)
g2_2000, lag_steps_n = corr.multi_tau_auto_corr(num_levels, num_bufs,
labeled_roi_array, imgs)
fig, ax = plt.subplots()
ax.semilogx(lag_steps, g2y[:, 0], "bo", label="No bad imgs")
ax.semilogx(lag_steps_n, g2_2000[:, 0], "r*", label="With bad imgs")
ax.set_ylim(bottom=1.014, top=1.018)
ax.set_title("5000 bad images")
ax.legend()
plt.show()
In [33]:
bad_list_2500 = np.random.choice(np.arange(10000), size=2500)
imgs = mask.bad_to_nan_gen(y, bad_list_2500)
g2_2500, lag_steps_n = corr.multi_tau_auto_corr(num_levels, num_bufs,
labeled_roi_array, imgs)
fig, ax = plt.subplots()
ax.semilogx(lag_steps, g2y[:, 0], "bo", label="No bad imgs")
ax.semilogx(lag_steps_n, g2_2500[:, 0], "r*", label="With bad imgs")
ax.set_ylim(bottom=1.014, top=1.018)
ax.set_title("2500 bad images")
ax.legend()
plt.show()
In [34]:
import skbeam
In [35]:
skbeam.__version__
Out[35]:
In [ ]: