Differential Phase Contrast


In [1]:
# all the imports
import os
import tempfile
from subprocess import call
import scipy
import numpy as np
import matplotlib.pyplot as plt
from pims import ImageSequence
import zipfile
from skxray.core import dpc
%matplotlib notebook

dpc.logger.setLevel(dpc.logging.DEBUG)


/home/edill/miniconda/envs/skxray/lib/python3.4/site-packages/IPython/kernel/__init__.py:13: ShimWarning: The `IPython.kernel` package has been deprecated. You should import from ipykernel or jupyter_client instead.
  "You should import from ipykernel or jupyter_client instead.", ShimWarning)

In [2]:
# some helper functions
def load_image(filename):
    """
    Load an image

    Parameters
    ----------
    filename : string
        the location and name of an image

    Return
    ----------
    t : 2-D numpy array
        store the image data

    """

    if os.path.exists(filename):
        t = plt.imread(filename)

    else:
        print('Please download and decompress the test data to your home directory\n\
               Dropbox link, https://www.dropbox.com/s/ntvk7866h23jdpr/SOFC.zip?dl=0')
        raise Exception('File not found: %s' % filename)

    return t

In [3]:
import download
download.run()


current_folder = /home/edill/dev/python/scikit-xray-examples/demos/dpc
Downloading url --> https://www.dropbox.com/s/ntvk7866h23jdpr/SOFC.zip?dl=1
to --> /home/edill/dev/python/scikit-xray-examples/demos/dpc/SOFC.zip
extracting to --> /home/edill/dev/python/scikit-xray-examples/demos/dpc/SOFC

In [4]:
# Set parameters
start_point = [1, 0]
first_image = 1
pixel_size = (55, 55)
focus_to_det = 1.46e6
scan_xstep = 0.1
scan_ystep = 0.1
scan_rows = 121
scan_cols = 121
energy = 19.5
roi = None
padding = 0
weighting = 1.
bad_pixels = None
solver = 'Nelder-Mead'
images = ImageSequence(os.path.join('SOFC', '*.tif'))
img_size = images[0].shape
ref_image = np.ones(img_size)
scale = True
negate = True

In [5]:
# Use skxray.dpc.dpc_runner
phase, amplitude = dpc.dpc_runner(
    ref_image, images, start_point, pixel_size, focus_to_det, scan_rows,
    scan_cols, scan_xstep, scan_ystep, energy, padding, weighting, solver,
    roi, bad_pixels, negate, scale)


DEBUG:skxray.core.dpc:dpc 0% complete
DEBUG:skxray.core.dpc:dpc 1% complete
DEBUG:skxray.core.dpc:dpc 2% complete
DEBUG:skxray.core.dpc:dpc 3% complete
DEBUG:skxray.core.dpc:dpc 4% complete
DEBUG:skxray.core.dpc:dpc 5% complete
DEBUG:skxray.core.dpc:dpc 6% complete
DEBUG:skxray.core.dpc:dpc 7% complete
DEBUG:skxray.core.dpc:dpc 8% complete
DEBUG:skxray.core.dpc:dpc 9% complete
DEBUG:skxray.core.dpc:dpc 10% complete
DEBUG:skxray.core.dpc:dpc 11% complete
DEBUG:skxray.core.dpc:dpc 12% complete
DEBUG:skxray.core.dpc:dpc 13% complete
DEBUG:skxray.core.dpc:dpc 14% complete
DEBUG:skxray.core.dpc:dpc 15% complete
DEBUG:skxray.core.dpc:dpc 16% complete
DEBUG:skxray.core.dpc:dpc 17% complete
DEBUG:skxray.core.dpc:dpc 18% complete
DEBUG:skxray.core.dpc:dpc 19% complete
DEBUG:skxray.core.dpc:dpc 20% complete
DEBUG:skxray.core.dpc:dpc 21% complete
DEBUG:skxray.core.dpc:dpc 22% complete
DEBUG:skxray.core.dpc:dpc 23% complete
DEBUG:skxray.core.dpc:dpc 24% complete
DEBUG:skxray.core.dpc:dpc 25% complete
DEBUG:skxray.core.dpc:dpc 26% complete
DEBUG:skxray.core.dpc:dpc 27% complete
DEBUG:skxray.core.dpc:dpc 28% complete
DEBUG:skxray.core.dpc:dpc 29% complete
DEBUG:skxray.core.dpc:dpc 30% complete
DEBUG:skxray.core.dpc:dpc 31% complete
DEBUG:skxray.core.dpc:dpc 32% complete
DEBUG:skxray.core.dpc:dpc 33% complete
DEBUG:skxray.core.dpc:dpc 34% complete
DEBUG:skxray.core.dpc:dpc 35% complete
DEBUG:skxray.core.dpc:dpc 36% complete
DEBUG:skxray.core.dpc:dpc 37% complete
DEBUG:skxray.core.dpc:dpc 38% complete
DEBUG:skxray.core.dpc:dpc 39% complete
DEBUG:skxray.core.dpc:dpc 40% complete
DEBUG:skxray.core.dpc:dpc 41% complete
DEBUG:skxray.core.dpc:dpc 42% complete
DEBUG:skxray.core.dpc:dpc 43% complete
DEBUG:skxray.core.dpc:dpc 44% complete
DEBUG:skxray.core.dpc:dpc 45% complete
DEBUG:skxray.core.dpc:dpc 46% complete
DEBUG:skxray.core.dpc:dpc 47% complete
DEBUG:skxray.core.dpc:dpc 48% complete
DEBUG:skxray.core.dpc:dpc 49% complete
DEBUG:skxray.core.dpc:dpc 50% complete
DEBUG:skxray.core.dpc:dpc 51% complete
DEBUG:skxray.core.dpc:dpc 52% complete
DEBUG:skxray.core.dpc:dpc 53% complete
DEBUG:skxray.core.dpc:dpc 54% complete
DEBUG:skxray.core.dpc:dpc 55% complete
DEBUG:skxray.core.dpc:dpc 56% complete
DEBUG:skxray.core.dpc:dpc 57% complete
DEBUG:skxray.core.dpc:dpc 58% complete
DEBUG:skxray.core.dpc:dpc 59% complete
DEBUG:skxray.core.dpc:dpc 60% complete
DEBUG:skxray.core.dpc:dpc 61% complete
DEBUG:skxray.core.dpc:dpc 62% complete
DEBUG:skxray.core.dpc:dpc 63% complete
DEBUG:skxray.core.dpc:dpc 64% complete
DEBUG:skxray.core.dpc:dpc 65% complete
DEBUG:skxray.core.dpc:dpc 66% complete
DEBUG:skxray.core.dpc:dpc 67% complete
DEBUG:skxray.core.dpc:dpc 68% complete
DEBUG:skxray.core.dpc:dpc 69% complete
DEBUG:skxray.core.dpc:dpc 70% complete
DEBUG:skxray.core.dpc:dpc 71% complete
DEBUG:skxray.core.dpc:dpc 72% complete
DEBUG:skxray.core.dpc:dpc 73% complete
DEBUG:skxray.core.dpc:dpc 74% complete
DEBUG:skxray.core.dpc:dpc 75% complete
DEBUG:skxray.core.dpc:dpc 76% complete
DEBUG:skxray.core.dpc:dpc 77% complete
DEBUG:skxray.core.dpc:dpc 78% complete
DEBUG:skxray.core.dpc:dpc 79% complete
DEBUG:skxray.core.dpc:dpc 80% complete
DEBUG:skxray.core.dpc:dpc 81% complete
DEBUG:skxray.core.dpc:dpc 82% complete
DEBUG:skxray.core.dpc:dpc 83% complete
DEBUG:skxray.core.dpc:dpc 84% complete
DEBUG:skxray.core.dpc:dpc 85% complete
DEBUG:skxray.core.dpc:dpc 86% complete
DEBUG:skxray.core.dpc:dpc 87% complete
DEBUG:skxray.core.dpc:dpc 88% complete
DEBUG:skxray.core.dpc:dpc 89% complete
DEBUG:skxray.core.dpc:dpc 90% complete
DEBUG:skxray.core.dpc:dpc 91% complete
DEBUG:skxray.core.dpc:dpc 92% complete
DEBUG:skxray.core.dpc:dpc 93% complete
DEBUG:skxray.core.dpc:dpc 94% complete
DEBUG:skxray.core.dpc:dpc 95% complete
DEBUG:skxray.core.dpc:dpc 96% complete
DEBUG:skxray.core.dpc:dpc 97% complete
DEBUG:skxray.core.dpc:dpc 98% complete
DEBUG:skxray.core.dpc:dpc 99% complete
/home/edill/dev/python/scikit-xray/skxray/core/dpc.py:281: RuntimeWarning: invalid value encountered in true_divide
  c = -1j * (kappax * tx * (1 - weighting) + kappay * ty * weighting) / div_v

In [7]:
# display results
fig, ax = plt.subplots(ncols=2)
ax[0].imshow(phase, cmap='gray')
ax[1].imshow(amplitude, cmap='gray')
ax[0].set_title('Phase')
ax[1].set_title('Amplitude')


Out[7]:
<matplotlib.text.Text at 0x7fc082b7fe10>

In [8]:
import skxray

In [9]:
skxray.__version__


Out[9]:
'0.0.4+95.gb764d5c'

In [ ]: