Tutorial

First you need to install the TaPy library

$ pip install tapy

Then in your python environment, import TaPy

>>> import tapy

First thing to do is to let the program know where are the sample, open beam (OB) and dark field (DF) images. Two options are available to load them:

  • file by file
  • full folder at once

Loading

Loading images file by file

Let’s pretend that our images are in the folder /Users/me/sample/ and named

  • image001.fits
  • image002.fits
  • image003.fits
>>> o_grating = tapy.GratingInterferometer()
>>> o_grating.load(file='/Users/me/sample/image001.fits', data_type='sample')
>>> o_grating.load(file='/Users/me/sample/image002.fits', data_type='sample')
>>> o_grating.load(file='/Users/me/sample/image003.fits', data_type='sample')

At this point all the data have been loaded in memory and can be accessed as followed

>>> image001 = o_grating.data['sample']['data'][0]
>>> image002 = o_grating.data['sample']['data'][1]

and the file names

>>> image003_file_name = o_grating.data['sample']['file_name'][2]

Let’s use the second method to retrieve files for the OB

Loading all images at once

Our OB are in the folder /Users/me/ob/ and named

  • ob001.fits
  • ob002.fits
  • ob003.fits
>>> o_grating.load(folder='/Users/me/ob', data_type='ob')

again, all the data can be retrieved as followed

>>> ob1 = o_grating.data['ob']['data'][0]
>>> ob2_file_name = o_grating.data['ob']['file_name'][1]

For this library, DF are optional but for the sake of this exercise, let’s load them

>>> o_grating.load(folder='/Users/me/df', data_type='df')

WARNING: #1 From this point, any operation on your data will overwrite the inital data loaded. Those data can be retrieved at any point by doing #2 The program won’t let you run the same algorithm twice (normalization, df_correction, oscillation, rebin). But it’s possible to overwrite this option by making a flag force equal to True. Use this feature at your own risk!

>>> data = o_grating.data['sample']['data']
>>> ob = o_grating.data['ob']['data']

Dark Field Correction

If you loaded a set of Dark Field (DF) images, you probably want to correct all your images (sample and OB) for dark field correction

>>> o_grating.df_correction()

In case you did not loaded a set of DF, this correction will leave the images untouched

Normalization

Normalization using ROI (optional)

If you want to specify a region of your sample to match with the OB

Let’s use the following region

  • x0 = 10
  • y0 = 10
  • x1 = 50
  • y1 = 50
>>> my_norm_roi = tapy.ROI(x0=10, y0=10, x1=50, y1=50)

then the normalization can be run

>>> o_grating.normalization(norm_roi=my_norm_roi)

Normalization without ROI (optional)

If you don’t want any normalization ROI, simply run the normalization

>>> o_grating.normalization()

How to get the normalized data

Each of the data set in the sample and ob will then be normalized. If a norm_roi has been provided, the sample arrays will be divided by the average of the region defined. Same thing for the ob. Those normalized array can be retrieved this way

>>> sample_normalized_array = o_grating.data['sample']['data']
>>> ob_normalized_array = o_gretting.data['ob']['data']

Cropping the data (optional)

You have the option to crop the data but if you do, this must be done after running the normalization. The algorithm only cropped the normalized sample and ob data

  • the 4 corners of the region of interest (ROI)
  • the top left corner coordinates, width and height of the ROI

let’s use the first method and let’s pretend the ROI is defined by

  • x0 = 5
  • y0 = 5
  • x1 = 200
  • y1 = 250
>>> my_crop_roi = tapy.ROI(x0=5, y0=5, x1=200, y1=250)
>>> o_grating.crop(roi=my_crop_roi)

Oscillation

Now we gonna check the mean value of the region of interest selected for each of the sample and ob data. If you don’t specify a ROI, the entire image will be used.

Let’s use a ROI defined as follow

  • x0 = 0
  • y0 = 0
  • x1 = 50
  • y1 = 50
>>> my_oscillation_roi = ROI(x0=0, y0=0, x1=50, y1=50)
>>> o_grating.oscillation(roi=my_oscillation_roi)

We can now retrieve the sample and ob data

>>> sample_oscillation = o_grating.data['sample']['oscillation']
>>> ob_oscillation = o_grating.data['ob']['oscillation']

We can now display the oscillation data

Binning

In order to improve the statistics, it’s possible to rebin the sample and ob data. If we want for example to rebin pixels 2 by 2

>>> bin = 2
>>> o_grating.rebin(bin=2)

Intererometry Images

It’s now time to produce the various images we want such as

  • Transmission
  • Differential Phase Contrast
  • Dark Field
  • visibility map

To calculate those imags, simply run

>>> o_grating.create_interferometry_images()

Then those arrays can be retrieved this way

>>> transmission = o_grating.interferometry['transmission']
>>> differential_phase_contrast = o_grating.interferometry['diff_phase_contrast']
>>> dark_field = o_grating.interferometry['dark_field']
>>> visibility_map = o_grating.interferometry['visibility_map']

Export Images

You can export into tiff or fits files, any of the interferometry images created

WARNING: the output folder must exist! The program won’t create this folder for you.

Example using ‘tif’ output files

>>> output_folder = '/Users/my_data/transmission/'
>>> o_grating.export(folder=output_folder, data_type='transmission', file_type='tif')
>>> output_folder = '/Users/my_data/diff_phase_contrast/'
>>> o_grating.export(folder=output_folder, data_type='diff_phase_contrast', file_type='tif')
>>> output_folder = '/Users/my_data/dark_field'
>>> o_grating.export(folder=output_folder, data_type='dark_field', file_type='tif')
>>> output_folder = '/Users/my_data/visibility_map'
>>> o_grating.export(folder=output_folder, data_type='visibility_map', file_type='tif')

For ‘fits’ output, just replaced the file_type by ‘fits’

>>> output_folder = '/Users/my_data/transmission/'
>>> o_grating.export(folder=output_folder, data_type='transmission', file_type='fits')