Python for X-ray

Here are the python modules I wrote and maintain on github.

 

The spec_reader module

This is the module I use the most. I initially wrote this to practice harnessing the power of using objects in python. It is now a stand-alone module that is used to parse SPEC files.
There are two main classes: the SpecFile class is initialized with a spec file path. Upon initialization it essentially reads through the file and builds a dictionary of scan numbers and binary positions in the file which allows for fast scan retrieval afterwards (no need to read through the whole file again to find a scan later). The Scan class is an object that represent the scan itself. It has the different parameters and measurements of the scan as attributes.

example:

from spec_reader import SpecFile, Scan
import matplotlib.pyplot as plt

# read the spec file
sf = SpecFile('gonio.14Dec16')

# get the scan number 135
sn = 135
s = Scan(sf, sn)

# plot some data
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(s.tth,s.detc)
ax.set_xlabel(r'$2 \theta$ ($^\circ$)')
ax.set_ylabel('Intensity (arb. units)')
plt.show()

 

The LiveFourierTransform module

Based on an idea from Brian R. Pauw (LookingAtNothing), this module was used for pedagogical purposes: it features the live Fourier transform of the video stream from a webcam, including the intensity, amplitude and phase components. Very useful for the discussions with students. While there seems to be something broken within the current module, a nice version can also be found on Brian’s blog.

 

The xray_tools module

Nothing revolutionary, just a few functions to go back and forth between energy and wavelength or calculate a 2theta angle for a cubic structure

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>