In [1]:
import numpy as np
import tifffile
%matplotlib notebook
from matplotlib import pyplot as plt
from databroker import DataBroker as db
from csxtools.fastccd import phocount
from csxtools import make_panel_plot
from csxtools.utils import get_fastccd_images, get_images_to_3D
from csxtools.ipynb import image_stack_to_movie, show_image_stack
import timeit
In [2]:
flat = np.ones((960, 960), dtype=np.float32)
flat[100:250,0:(960/2)] = np.nan
flat[:,475:485] = np.nan
plt.figure()
plt.imshow(flat, cmap='prism')
flat = np.rot90(flat)
In [3]:
dark = db[58886]
light = db[58885]
images = get_fastccd_images(light, (dark, None, None), flat=flat)
stack = get_images_to_3D(images)
dark_images = get_fastccd_images(dark, (dark, None, None), flat=flat)
dark_stack = get_images_to_3D(dark_images)
In [4]:
plt.figure()
plt.imshow(stack[0], vmin=0, vmax=100, cmap='hot', interpolation='none')
plt.colorbar()
Out[4]:
In [5]:
h = np.histogram(stack.ravel(), bins=300, range=(0, 300))
h_b = np.histogram(dark_stack.ravel(), bins=300, range=(0, 300))
fig, ax = plt.subplots()
ax.semilogy(h[1][:-1], h[0], 'r-')
ax.semilogy(h_b[1][:-1], h_b[0], 'b-')
ax.semilogy(h_b[1][:-1], h[0] - h_b[0], 'g-')
Out[5]:
In [11]:
c = phocount.photon_count(stack, (30,100), (75, 120), (3, 12), 3, True)
inti = c[0][:,:,480:]
stdi = c[1][:,:,480:]
#inti[:,:,0::10] = np.nan
#inti[:,:,9::10] = np.nan
ff = np.nanmean(inti, axis=(0,2))
ffstd = np.nanstd(inti, axis=(0,2))
ffn = np.nansum(inti > 0, axis=(0,2))
ggstd = np.nanmean(stdi, axis=(0,2))
In [12]:
fig, ax = plt.subplots(1,2)
cax = ax[0].imshow(np.nansum(c[0] > 0, axis=0)[400:600,450:600], cmap='CMRmap', interpolation='none')
cax = ax[1].imshow(np.nansum(stack, axis=0)[400:600,450:600], cmap='CMRmap', interpolation='none')
#cbar = fig.colorbar(cax)
In [13]:
fig = plt.figure()
ax = make_panel_plot(n=4, fig=fig)
ax[3].plot(ggstd, 'g')
ax[2].plot(ff, 'r-')
ax[1].plot(ffn, 'k-')
ax[0].plot(ffstd, 'b-')
ax[2].set_ylabel(r'$\leftangle I \rightangle$ [ADU]')
ax[2].set_title('Results by column ')
ax[1].set_ylabel('n [photons]')
ax[0].set_ylabel('$\sigma (I)$')
ax[0].set_xlabel('Column')
for a in ax:
a.set_xlim((0,960))
In [14]:
hist_std = np.histogram(c[1], bins=200, range=(0,25))
hist_sum = np.histogram(c[0], bins=200, range=(0,200))
fig, ax = plt.subplots(1,2)
ax[0].plot(hist_sum[1][:-1], hist_sum[0], 'ro')
ax[0].set_xlabel('$\sigma$ [ADU]')
ax[0].set_ylabel('Number of photons')
ax[1].plot(hist_std[1][:-1], hist_std[0], 'ro')
ax[1].set_xlabel('$\mu$ [ADU]')
ax[1].set_ylabel('Number of photons')
Out[14]:
In [15]:
import csxtools
csxtools.__version__
Out[15]:
In [ ]:
In [ ]: