Skip to main content

Python package to quickly transform images from grazing incidence X-ray experiments using C

Project description

Installation

GixPy is distributed on PyPI and can be installed using pip:

pip install gixpy

It can be built from source by cloning https://github.com/ttortorici/gixpy.git and using Python's build tool (don't forget to cd into the repository):

pip install -U setuptools build
python -m build
pip install dist/*.whl

where * should be replaced with the actual wheel's filename, and \ should be used instead of / on Windows.

Examples

transform-GIWAXS.ipynb

This jupyter notebook can be used as a complete workflow to process an image. The sample-detector distance, critical angle, and tilt angle must be known through other experimental means.

Cell 1

Import packages, load data, and show data. If no flat field is needed, the lines of code loading the flat-field file, and plotting it should be removed.

Cell 2

Apply the flat-field correction to the image and save it. If no flat-field correction is needed, this cell can be removed and the figure in the previous cell can be saved instead.

Cell 3

If the beam center (PONI) is not known, this cell is the start of a process for locating it. The gixpy.poni.Nudger class creates a beam_finder object that plots rings and horizontal lines at the beam center and the sample horizon (a projection from the film plane to the projector).

The PONI and the tilt can be adjusted so that the horizon meets the bottom of the in-plane-scattering ring segments.

An example plot generated by the cell.

Cell 4

This cell allows you to adjust the tilt, and beam center until the features on the plot look right.

The beam_finder.radii is a list of values corresponding to the red circles seen above. The values will roughly correspond to lattice spacings in the crystal, so if you know what these roughly are, you can get the circles to roughly the right size easily (note: larger layer spacings correspond to smaller radii on the detector).

beam_finder.show() is used to set the maximum value in the color range. For example, if beam_finder.show(data.max()) is used, the full dynamic range will be used.

beam_finder.set_tilt() changes the tilt angle, and beam_finder.set_nudge() moves the beam center relative to what was initially set (in units of pixel widths).

The horizontal nudge can be adjusted until the ring segments are symmetrically intersected by red circles.

Using %matplotlib widget, the user can zoom in on ring segments along the horizontal direction (in-plane scattering). The vertical nudge, and the tilt can be adjusted so that the horizon meets the bottom of the ring segment. The tilted sample will occlude any scattering that does not scatter with in a positive vertical direction, so projecting the sample horizon to the detector (the higher of the two horizontal red lines) allows the user to line this up with the occlusion to determine both the vertical nudge and the tilt by looking at two symmetric features.

Cell 5

After finalizing the tilt and nudge, this cell will update the PONI file (named cal.poni in this example) that holds the experimental geometry.

Example PONI file

# Nota: C-Order, 1 refers to the Y axis, 2 to the X axis
# Calibration done on Fri Nov 15 20:38:56 2024
poni_version: 2.1
Detector: Detector
Detector_config: {"pixel1": 7.5e-05, "pixel2": 7.5e-05, "max_shape": [1102, 3070], "orientation": 2}
Distance: 0.1569
Poni1: 0.01345
Poni2: 0.11233821035361662
Rot1: 0
Rot2: 0
Rot3: 0
Wavelength: 1.54185e-10

Cell 6

Transform the image using the experimental geometry laid out int the PONI file and plot it.

Cell 7

This cell is used to prepare the pyFAI-calib2 GUI program for making a custom mask. Generate a string command to give to the terminal to lauch pyFAI-calib2 with the image and detector configuration loaded. This speeds up the workflow since you will not need to manually load in this information using the GUI.

On Windows, this will automatically copy the string to the clipboard. Otherwise, it will print the string to the output and it can manually be copied.

With your Python virtual environment (with pyFAI installed) activated, paste the pyFAI-calib2 command to launch the GUI. The mask tab can be used to draw a mask over, for example, a beam stop, and then saved as mask.edf.

Cell 8

Plot and save the image with the relative weights adjusted due to the pixel movement.

Cell 9

Load the mask file you created. If you did not make a mask, call transformer.load_mask() with no inputs. This will use the transformed flat field to mask out pixels which no counts were moved to from the transformation. With a custom mask, the two masks will be layered.

Cell 10

Use pyFAI to create a "cake" image (counts vs azimuthal angle vs reciprocal space) using AzimuthalIntegrator.integrate2d_ng(). This can be used to inspect the transformation. Partial rings should be represented as partial columns in this plot.

Cell 11

Creates a function to overwrite data files from the upcoming integrations, so that you can rerun them and update the data.

Cell 12

Integrate a sector from $0\degree$ to $180\degree$. The exposure_time input allows you to represent the data as intensity by dividing by the exposure time (in any units you prefer).

This cell can be duplicated and azimuthal_range and sector_name can be changed to produce different sectors.

Command line tool: gixpy-transform

Installing GixPy allows you to call the program gixpy-transform from the terminal, command prompt, PowerShell, Anaconda Prompt, or Anaconda PowerShell.

Usage

gixpy-transform [-h] [-P] [-F FLATFIELD] [-C CRITICAL_ANGLE] [-I INCIDENT_ANGLE] [-T TILT_ANGLE] [-TIF] filename poni

Positional arguments

File name

The first argument is the path to the file containing image data (usually a .tif or .edf file). This should be wrapped in quotations marks if the path to the file has spaces in it: e.g. "example directory\file.tif". A relative path from the current working directory can be used, or simply the file name can be used if the file is in the current working directory.

PONI

There are two options:

  1. You can pass a path to a pyFAI PONI file: e.g. "path\to\file\geometry.poni"

  2. You can pass the relevant data as comma-separated values in the following order:

    • poni1: distance (in meters) of the PONI from bottom edge of the detector. If the -P flag is passed, then this will be the distance (in pixels) of the PONI from the center of the top row of pixels.

    • poni2: distance (in meters) of the PONI from left edge of the detector. If the -P flag is passed, then this will be the distance (in pixels) of the PONI from the center of the left-most column of pixels.

    • pixel1: vertical width of a pixel (in meters).

    • pixel2: horizontal width of a pixel (in meters).

    • distance: distance between the sample and the detector (in meters).

    • wavelength: (optional argument: 1.54185 Angstrom will be used as default) the wavelength of X-rays (in meters). This is not used in the calculation, but is recorded in the resulting PONI file.

Example usage with comma separated values:

gixpy-transform image.tif 0.012213,0.111872,75e-6,75e-6

Example usage with the geometry stored in a PONI file called geometry.poni in the current working directory:

gixpy-transform image.tif geometry.poni

Options

Help

show the help message and exit

flags: -h, --help

Change PONI format

Use row/column index instead of pyFAI convention for beam center (PONI).

flags: -P, --row_column_pixel_index

Flat field

Path to flat field file. Will use array of ones, if not given. The transformation will transform an array of ones to account for where pixels are moved. A given flat field will be transformed instead so that the flat field correction can be applied through the transformation.

flags: -F, --flatfield

Critical angle

Critical angle $\alpha_c$ of the film (in degrees). This will optionally correct for refraction in the film. The critical angle is related to the index of refraction. The index of refraction $n$ for materials in the X-ray regime is slightly less than one, such that

$$\begin{equation}n = 1-\delta.\end{equation}$$

The critical angle is then related to the index of refraction by

$$\begin{equation}\alpha_i=\sqrt{2\delta}.\end{equation}$$

Steele, J. A., Solano, E., Hardy, D., Dayton, D., Ladd, D., White, K., Chen, P., Hou, J., Huang, H., Saha, R. A., Wang, L., Gao, F., Hofkens, J., Roeffaers, M. B. J., Chernyshov, D., & Toney, M. F. (2023). How to GIWAXS: Grazing Incidence Wide Angle X-Ray Scattering Applied to Metal Halide Perovskite Thin Films. Advanced Energy Materials, 13(27). https://doi.org/10.1002/aenm.202300760

flags: -C, --critical_angle

Incident angle

Angle of grazing incidence (in degrees). This is the angle between the incident beam and the plane of the film. Will set to 0 (small angle approximation), if not given.

flags: -I, --incident_angle

Tilt angle

Angle the sample is tilted relative to the vertical direction (in degrees). Will set to 0, if not given.

flags: -T, --tilt_angle

Save TIFF

If this flag is used, a TIFF file will also be saved.

flags: -TIF, -tiff

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gixpy-2.7.tar.gz (24.4 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

gixpy-2.7-cp313-cp313-win_amd64.whl (32.3 kB view details)

Uploaded CPython 3.13Windows x86-64

gixpy-2.7-cp312-cp312-win_amd64.whl (32.3 kB view details)

Uploaded CPython 3.12Windows x86-64

gixpy-2.7-cp311-cp311-win_amd64.whl (32.3 kB view details)

Uploaded CPython 3.11Windows x86-64

gixpy-2.7-cp310-cp310-win_amd64.whl (32.3 kB view details)

Uploaded CPython 3.10Windows x86-64

gixpy-2.7-cp39-cp39-win_amd64.whl (32.3 kB view details)

Uploaded CPython 3.9Windows x86-64

File details

Details for the file gixpy-2.7.tar.gz.

File metadata

  • Download URL: gixpy-2.7.tar.gz
  • Upload date:
  • Size: 24.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.13.0

File hashes

Hashes for gixpy-2.7.tar.gz
Algorithm Hash digest
SHA256 b4ab01b43081c824539dacc99c2482feb4b750ba825bac9a39da54b395acb344
MD5 0789800d025305380ae59f7f9de0fd3f
BLAKE2b-256 bcea49126bf5d22abf9ba8dfa80b33f076f0d69cdcf55c75eddc8866a85e237d

See more details on using hashes here.

File details

Details for the file gixpy-2.7-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: gixpy-2.7-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 32.3 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.13.0

File hashes

Hashes for gixpy-2.7-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 8c31743df668d0471618705254c95868693982ba52b332eb6dc6582f3673a423
MD5 901ac099c79093192b5146f66676fa75
BLAKE2b-256 356b84b9b25a651ff00cc53692eb78a54319cf685ec939e6c814600433d726ed

See more details on using hashes here.

File details

Details for the file gixpy-2.7-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: gixpy-2.7-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 32.3 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.13.0

File hashes

Hashes for gixpy-2.7-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 026f2bf208e55e10d0ae52ced2f264d4c22e53b1e25c2401c99ab4260fed97bc
MD5 a27e7126e7cdcb691fbf3a990d5fed8e
BLAKE2b-256 558f5843db4ac257ed5204b94a190d0023ae005d095c14e37ac372d12f3182f5

See more details on using hashes here.

File details

Details for the file gixpy-2.7-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: gixpy-2.7-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 32.3 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.13.0

File hashes

Hashes for gixpy-2.7-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 efa7e49e69d73a5fa30174609bd73da90f4812d561aeebc42e985a41cd9eb544
MD5 2f1eb59101c3280dc8d910fec3b8a831
BLAKE2b-256 59a129ec0e8ae103ea5de38bb9030a7a937b555f648c811aa1f47e9b0047c734

See more details on using hashes here.

File details

Details for the file gixpy-2.7-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: gixpy-2.7-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 32.3 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.13.0

File hashes

Hashes for gixpy-2.7-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 bbecf53c164d20ee0d3f6fd26bcf18873936528e2c444e5098c851a7d5d06e03
MD5 d390a1a28c638b5e83bd669df7566b0b
BLAKE2b-256 347bde798b463e99c987607d5aea9f5e6ddba2dcff8b857792d795ae8e3556b3

See more details on using hashes here.

File details

Details for the file gixpy-2.7-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: gixpy-2.7-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 32.3 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.13.0

File hashes

Hashes for gixpy-2.7-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 65888881f5655df30c6b268597cc48f0ffffabe9aed36d3b241e2889eeeb4784
MD5 8a15e32147248c97104fe9103975622c
BLAKE2b-256 19894295c724f07a5245970d4f47b75a744ddaf570e2192ecc55634dad8be5b4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page