Skip to main content

Simple yet powerful package for neutron resonance fitting

Project description

nbragg

nbragg logo

Documentation Status PyPI version

nbragg is a package designed for fitting neutron Bragg edge data using NCrystal cross-sections. This tool provides a straightforward way to analyze neutron transmission through polycrystalline materials, leveraging Bragg edges to extract information on material structure and composition.

Features

  • Flexible Cross-Section Calculations: Interfaces with NCrystal to fetch cross-sections for crystalline materials.
  • Grouped/Gridded Data Fitting: Analyze spatially-resolved or multi-sample data with support for 1D arrays, 2D grids, and named groups. Includes parallel fitting with automatic result visualization via parameter maps.
  • SANS Modeling: Built-in support for Small Angle Neutron Scattering (SANS) using hard-sphere models for samples with nanoscale features.
  • Extinction Effects: Support for primary and secondary extinction modeling for large crystallites and thick samples.
  • Built-In Tools for Response and Background Functions: Includes predefined models for instrument response (e.g., Jorgensen, square) and background components (polynomial functions).
  • LMFit Integration: Allows flexible, nonlinear fitting of experimental data using the powerful lmfit library.
  • Rietveld-type analysis: Enables iterative, parametric refinement of Bragg edge data using the Rietveld method, accumulating parameters across stages for robust fitting.
  • Pythonic API: Simple-to-use, yet flexible enough for custom modeling.
  • Plotting Utilities: Provides ready-to-use plotting functions for easy visualization of results.
  • Bragg Edge Analysis: Perform Bragg edge fitting to extract information such as d-spacing, strain, and texture.

Installation

Basic Installation

To install the base package:

pip install nbragg

Installation with Extinction Effects

To include extinction effects in your analysis, you'll need to install the extinction plugin separately:

pip install nbragg
pip install git+https://github.com/XuShuqi7/ncplugin-CrysExtn

The ncrystal-plugin-crysextn plugin provides extinction corrections for crystallographic calculations.

Note: The extinction plugin is only required if you plan to use extinction effects. For standard Bragg edge fitting without extinction corrections, the base installation is sufficient.

Usage

Here's a quick example to get started:

import nbragg

data = nbragg.Data.from_transmission("iron_powder.csv") # read data
xs = nbragg.CrossSection(iron="Fe_sg229_Iron-alpha.ncmat") # define sample
model = nbragg.TransmissionModel(xs, vary_background=True, vary_response=True) # define model
result = model.fit(data) # perform fit
result.plot() # plot results

Fit Results

Tutorials and Documentation

For more detailed examples and advanced usage, including custom stage definitions and Rietveld fitting, please refer to our documentation page and check out the updated Jupyter notebook tutorial.

License

nbragg is licensed under the MIT License.

Third-Party Dependencies

This project depends on several open-source packages with permissive licenses compatible with MIT:

  • scipy, pandas, numpy, lmfit: BSD/BSD 3-Clause
  • setuptools, tqdm: MIT License
  • matplotlib: PSF License
  • ncrystal: Apache 2.0 (license)

All dependencies allow free use, modification, and distribution.

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

nbragg-0.7.1.tar.gz (129.1 kB view details)

Uploaded Source

Built Distribution

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

nbragg-0.7.1-py3-none-any.whl (101.5 kB view details)

Uploaded Python 3

File details

Details for the file nbragg-0.7.1.tar.gz.

File metadata

  • Download URL: nbragg-0.7.1.tar.gz
  • Upload date:
  • Size: 129.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nbragg-0.7.1.tar.gz
Algorithm Hash digest
SHA256 ba13b09c482a8b97946fff7775edbe39b9970f1de35fd261ccd4ca41908099e1
MD5 355f611717a88301a957552c310bd4d3
BLAKE2b-256 b9eafc3e4bbdf65da54ec9875bc249f1c1148e5fde199c4171a9ef508f092b5c

See more details on using hashes here.

Provenance

The following attestation bundles were made for nbragg-0.7.1.tar.gz:

Publisher: python-publish.yml on TsvikiHirsh/nbragg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nbragg-0.7.1-py3-none-any.whl.

File metadata

  • Download URL: nbragg-0.7.1-py3-none-any.whl
  • Upload date:
  • Size: 101.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nbragg-0.7.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0c37af204f34439b42b6b417c62168540c4356f452118db48cb9e28882868e86
MD5 277603029247780152a4ee46b2b0c0e2
BLAKE2b-256 20a087e94750a5c54cedd68e8c75812d4572a3689614ec0d51d9ace03853f270

See more details on using hashes here.

Provenance

The following attestation bundles were made for nbragg-0.7.1-py3-none-any.whl:

Publisher: python-publish.yml on TsvikiHirsh/nbragg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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