Example Notebook for Correcting and loading FastCCD Images

This example reads data from the FastCCD and corrects and rotates the images. Included are some example of widgets to interact with the data

Getting Started

Load the databroker moudle, csxtools and various other dependencies


In [1]:
import numpy as np
from databroker import DataBroker, get_table
from csxtools.utils import get_fastccd_images, get_images_to_4D, get_images_to_3D
from csxtools.ipynb import image_stack_to_movie, show_image_stack
%matplotlib inline
from matplotlib import pyplot as plt
import timeit
import psutil

Set the logger level to info to see logging output, if required!


In [ ]:
#import logging
#logging.getLogger().setLevel(logging.INFO)

Get the data headers from the DataBroker!


In [ ]:
bgnd = DataBroker['ce5042b7-00ae-49ca-9b11-b10c5661aaaa'] #[52440]

In [ ]:
data = DataBroker['b2596f8e-d220-4aea-8a55-8ccb17cbdacc'] #[52436]

Correct the FastCCD Images

Now correct the CCD images, using only a single background image.

In the future this should be taken from the metadata associated with the data, or from the darkfield entry

First lets just look at the background stack as a "lightfield"


In [ ]:
images = get_fastccd_images(data, (bgnd, None, None), tag='fccd_image_lightfield')

Format of returned object

The returned images object is a 4D stack of images of shape (N, M, y, x) where N is the number of events. This is - for example - the number of data points in a scan. M is the number of images collected at each point, while y and x are the size of the CCD chip.

As the data was collected as a single ct(), there is only one event. Lets select that.


In [ ]:
stack = images[0]

In [ ]:
stack[0]

We can use this as a PIMS object, or we could convert it to a image stack using the get_images_to_4D() function


In [ ]:
arr = get_images_to_4D(images)
arr.shape

In [ ]:
arr_3d = get_images_to_3D(images)
arr_3d.shape

In [ ]:
arr[0][0] # The first image, corrected

Now lets do an interactive plotting widget!

We can, however use the pims object in most functions to look at the data. There are a couple of nice interactive objects which can be used to look at image stacks.


In [ ]:
show_image_stack(stack, (-100, 100))

And lets do a movie of the stack of images

This produces an HTML5 movie which can be viewed in most browsers


In [ ]:
image_stack_to_movie(stack[20:120], figsize=(12, 10), vmin=-20, vmax=20)

If we don't want all the image ....

An ROI can be specified on the function call


In [ ]:
images = get_fastccd_images(data, (bgnd, None, None), tag='fccd_image_lightfield', roi = [200,100,150,175])

In [ ]:
stack = images[0]
stack.shape

In [ ]:
show_image_stack(stack, (-100, 100))

Now do some timing calculations

How well are we really doing ....


In [ ]:
n_runs = 5

In [ ]:
t = timeit.timeit('get_fastccd_images(data, (bgnd, None, None), tag=\'fccd_image_lightfield\')', 
                  globals=globals(), number=n_runs)
print("Image conversion took {:.3f} seconds".format(t / n_runs))

In [ ]:
t = timeit.timeit('get_fastccd_images(data, (bgnd, None, None), tag=\'fccd_image_lightfield\', roi = (200,100,400,100))', 
              globals=globals(), number=n_runs)
print("Image conversion took {:.3f} seconds".format(t / n_runs))

What version are we running?


In [ ]:
import csxtools
csxtools.__version__

In [ ]:
import databroker
databroker.__version__

In [16]:
mem = psutil.virtual_memory()
mem


Out[16]:
svmem(total=541998759936, available=524986118144, percent=3.1, used=43332927488, free=498665832448, active=23554088960, inactive=12996972544, buffers=1711259648, cached=24609026048)

In [19]:
mem.precent


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-19-fed18840d03b> in <module>()
----> 1 mem.precent

AttributeError: 'svmem' object has no attribute 'precent'

In [ ]: