Skip to main content

BabelScan

BabelScan is a format independent data structure for holding different types of data from a scan file.

Various file formats are supported, including Nexus and HDF formats, as well as older ASCII file formats. BabelScan is implicitly Lazy Loading and only loads data when requested, making it fast and lightweight.

Data fields are stored in a format independent way, with the abiliity to find close matches to a requested field.

3D datasets such as images from detectors are specially handelled and contain several special functions.

If packages lmfit and matplotlib are available, fitting and plotting options are included in the BabelScan object.

A FolderMonitor class allows loading of specific files in numeric order

An Instrument class holds specific configuration for generation of bespoke BabelScan objects.

You can read the documentation here!

Documentation Status

By Dan Porter, Diamond Light Source Ltd. 2021

Usage

# Python script
import babelscan
scan1 = babelscan.file_loader('12345.nxs')
scan2 = babelscan.file_loader('i16_1234.dat')
exp = babelscan.FolderMonitor('/path/to/files')
scan3 = exp.scan(0)  # returns latest scan in directory
scans = scan1 + scan2 + scan3  # creates MultiScan object that combines the 3 datasets

# Folder monitor:
mon = babelscan.FolderMonitor('/some/folder', **options)
scan = mon.scan(0)  # creates scan from latest file in folder

# intrument configuration file
i16 = babelscan.instrument_from_config('config_files/i16.config')
experiment = i16.experiment('/data/folder')
scan = experiment.scan(12345)
print(scan)  # displays I16 metadata by default

Installation

requirements: numpy, h5py, imageio, [optional: matplotlib, lmfit]

available from: https://github.com/DanPorter/babelscan

Latest version from github:

pip install git+https://github.com/DanPorter/babelscan.git

Stable version from PyPI:

pip install babelscan

Examples

import babelscan
scan = babelscan.file_loader('12345.nxs')

print(scan)  # prints scan information

en = scan('energy')  # finds data field named 'energy', returns data
val = scan('sum/Transmission')  # Finds 'sum' and 'Transmission' fields, evaluates result

x = scan('axes')  # finds default xaxis in Nexus files
y = scan('signal')  # finds default yaxis in Nexus files

title = scan.title()  # generates a plot title

im = scan.image(0)  # returns first detector image if scan contains 3D data

# Automatically generate x, y, error data and labels for plotting
# Here we also show off the automatic "region of interest" specification,
# as well as the automatic normalisation and error generation
x, y, dy, xlab, ylab = scan.get_plot_data('axes', 'nroi_peak[31,31]', '/count_time/Transmission', 'np.sqrt(x+0.1)')

# If matplotlib is installed, plotting behaviour is enabled:
scan.plot()  # creates a figure and plots the default axes
scan.plot.plotline('axes', 'signal', 'b-')  # command similar to plt.plot
scan.plot.plot_image(index)  # creates figure and plots detector image

# If lmfit is installed, fitting behaviour is enabled:
scan.fit()  # fits a gaussian peak to the default axes
scan.fit.fit('axes', 'signal')  # Fits a gaussian peak to choosen axes
# The resulting parameters are stored in the namespace:
scan('area')

See the included example_*.py files for more examples.

Metadata

Release files for babelscan 0.5.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for babelscan 0.5.2
File Size Uploaded
babelscan-0.5.2.tar.gz 46.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for babelscan 0.5.2
File Interpreter ABI Platform
babelscan-0.5.2-py3-none-any.whl Python 3 none any Details

Total release size: 98.4 kB

Release files / babelscan-0.5.2.tar.gz

Download URL babelscan-0.5.2.tar.gz
Size 46.6 kB
Tags Source
SHA-256 checksum
How to use checksums
6d250a7b14f55986bed508ec39fbb825093bb753171c65fb05d5407f13d8cb21
BLAKE2b-256 checksum
How to use checksums
345f7413c9f787694805b0e8d3f689ce9418523bb97758f1ed974e3c6075027a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.5.0.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

Release files / babelscan-0.5.2-py3-none-any.whl

Download URL babelscan-0.5.2-py3-none-any.whl
Size 51.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6c6deb16250f8bf8d1c4b0855cde6b69eec8cb72084496c60d146a0ded77a97a
BLAKE2b-256 checksum
How to use checksums
d85aa251aac169e589e991ed2a942ae0e7e78416cb388bf63a3aca716189b7ae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.5.0.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

Release history Release notifications | RSS feed

This release

0.5.2 This release

2 release files

0.5.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page