Skip to main content

A python [D]ark field x-ray microscopy [A]nalysis & [R]econstruction [L]ibrary for rapid data [IN]spection & [G]raphing

Project description

DARLING

the python [D]ark field x-ray microscopy [A]nalysis & [R]econstruction [L]ibrary for rapid data [IN]spection & [G]raphing

cross-platform pure python tests ubuntu-linux code style black Sphinx documentation

Authors

darling is written and maintained by:

Axel Henningsson, Felix Tristan Frankus and Adam André William Cretton

affiliated with DTU. The core ideas of this library was originally written during a beamtime at ESRF id03D.

Until an associated journal publication is available, if you use this code in your research, we ask that you cite this repository.

If you are interested in collaborating with us on DFXM data analysis, please reach out to us at: naxhe@dtu.dk and we can discuss the possibilities.

Usecase

Loading & plotting Data

Darling collects many useful tools in the properties module.

For example, it is possible to model the angular intensity distribution of a scan using a Gaussian Mixture Model (GMM) and then color code the scan based on the first maxima of the GMM using a RGB color map known as a mosaicity map.

import numpy as np

# read some toy data in
path_to_data, _, _ = darling.assets.domains()  # replace with your own data
scan_id = "1.1"  # tope level key in the hdf5 file
dset = darling.DataSet(path_to_data, scan_id)

# model the intensity distribution using a GMM
features = darling.properties.gaussian_mixture(dset.data, k=4, coordinates=dset.motors)

# color code the scan based on the first maxima of the GMM
first_maxima_mean = np.concatenate(
   (features["mean_motor1"][..., 0, None], features["mean_motor2"][..., 0, None]),
   axis=-1,
)
rgbmap, colorkey, colorgrid = darling.properties.rgb(
   first_maxima_mean, norm="dynamic", coordinates=dset.motors
)

To visualize the resulting mosaicity map, you can use the following code:

import matplotlib.pyplot as plt

# plot the resulting mosaicity map
plt.style.use('dark_background')
fig, ax = plt.subplots(1, 1, figsize=(7,7))
im = ax.imshow(rgbmap)
plt.tight_layout()
plt.show()
https://github.com/AxelHenningsson/darling/blob/dev/docs/source/images/domains_mosa.png?raw=true

for more examples see the externally hosted documentation at https://axelhenningsson.github.io/darling/

Installation

From source the key is simply to clone and pip install

git clone https://github.com/AxelHenningsson/darling.git
cd darling
pip install -e .

In general, you probably want to install in a fresh virtual environment as

python3 -m venv .venv_darling
source .venv_darling/bin/activate
git clone https://github.com/AxelHenningsson/darling.git
cd darling
pip install -e .

use

source .venv_darling/bin/activate

whenever you want to activate the environment. To add your env into a jupyter kernel such that you can use it in an interactive notebook you may add the following two commands:

pip install ipykernel
python -m ipykernel install --user --name=darling

Note on jupyter & the ESRF slurm cluster

In the main ESRF slurm Python jupyter kernel it is possible to do the following hack to get the latest darling running.

git clone https://github.com/AxelHenningsson/darling.git
sys.path.insert(0, os.path.abspath('./darling'))
import darling

This trick is possible since that all dependencies of darling are already installed in the big Python jupyter kernel at ESRF.

The following snippet has also been verified to work on the ESRF slurm cluster 19 Dec 2024 in a browser terminal:

python3 -m venv .venv_darling
source .venv_darling/bin/activate
git clone https://github.com/AxelHenningsson/darling.git
cd darling
pip install -e .
pip install ipykernel
python -m ipykernel install --user --name=darling

This appraoch should work on other clusters as well, as long as some user permission to install exists.

Documentation

Darling hosts documentation at https://axelhenningsson.github.io/darling/

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

darling_pypi-1.0.0.tar.gz (52.8 MB view details)

Uploaded Source

Built Distribution

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

darling_pypi-1.0.0-py3-none-any.whl (53.1 MB view details)

Uploaded Python 3

File details

Details for the file darling_pypi-1.0.0.tar.gz.

File metadata

  • Download URL: darling_pypi-1.0.0.tar.gz
  • Upload date:
  • Size: 52.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.13

File hashes

Hashes for darling_pypi-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d61a967d4beb062c4a6e46899f18bbec3407e12baef11de25746ab436a38defd
MD5 dee0d4d9657577cdf88994812c651fd3
BLAKE2b-256 4cf61f8772826c1bf48718aeefe60a1cae119ffd2404b289abea89a7056667a1

See more details on using hashes here.

File details

Details for the file darling_pypi-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: darling_pypi-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 53.1 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.13

File hashes

Hashes for darling_pypi-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a018f72bce1404c25a05db91d1a07e6a09e8627104684d1cef8ab8cd6528474a
MD5 13bb1fa28fddd7d794d36ca847e2e97e
BLAKE2b-256 211e521efcfc3bb863d8aad2677e6cfe55a1a3ab7d952e2b0ceb1f4fd69819ea

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