Skip to main content

nuclyr - an utility package for nuclear physics

  1. Motivation
  2. Build
  3. Config
  4. Submodules
    1. exfor
    2. mass
    3. nndc

Motivation

Often data analysis in nuclear physics depends on up-to-date values for specific parameters, e.g. cross sections, masses, half-lives. nuclyr is a python package which should provide such functionality. It will grow over time depending on what I personally need for my analysis. At the moment nuclyr includes the following features:

  • Obtain up-to-date cross section data from the EXFOR database as pandas dataframes via the exfor submodule
  • Get up-to-date atomic masses, massExcess, and calculate QValues via the mass submodule
  • Get up-to-date level scheme information from NNDC via the nndc submodule
  • Rather useful constants in nuclear physics via nuclyr.constants

Build

The package nuclyr is available via pip. See https://pypi.org/project/nuclyr/.

Just run:

pip install nuclyr

Or just clone the repository and build it from there using setup.py.

For the webscraping part of the package a driver for your favorite browser is needed, e.g. chromedriver or msedgedriver. You can find them via the following links:

Please make sure, you're downloading the right version for your browser.

Config

At start nuclyr will create a configuration file in your home directory called .nuclyr which is in JSON format. You can easily edit all the package configurations with your prefered text editor, e.g. the location of the webdriver.

The configurations can also be added within a python script via:

import nuclyr.config as cf

#Setting driver_loc to "path/to/driver"
cf.Set("driver_loc", "path/to/driver") 

#Getting the current options for the driver location
cf.Get("driver_loc") 

#print the whole configuration file
cf.Show() 

Submodules

exfor

This submodule is for mineing up-to-date reaction data from the EXFOR data base.

A simple example to mine the cross section data for 63Cu(p,n) would look like:

#import nuclyr modules
import nuclyr.config as cf
from nuclyr import exfor

#import pyplot for plotting the data
import matplotlib.pyplot as plt

#definition of target and reaction of interest
target="63Cu"
reaction="p,n"

#setting the driver location
cf.Set("driver_loc","path/to/driver")

#obtaining the data via exfor.getSig()
data, legend = exfor.getSIG(target,reaction)

#plotting the dataframes
plt.figure(1, figsize=(8,5))

plt.xlim(xmin=0, xmax=40)
plt.ylim(ymin=0, ymax=1000)
plt.xlabel("proton energy [MeV]", size=25)
plt.ylabel("cross section [mb]", size=25)
plt.text(20, 400, r"$^{63}$Cu(p,n)", size=25)
plt.gca().tick_params(labelsize=20)

for df in data:
    plt.scatter(df[('EN','MEV')], df[('DATA','MB')])

plt.tight_layout()
plt.show()

The result would look like:

.

mass

You want to use recommended values for nuclear masses in your python code? You can get them via this submodule. Here is a small example of getting the mass excesses of thin isotopes.

from nuclyr import mass
import matplotlib.pyplot as plt
import numpy as np

masses = np.arange(99,138)
excess = np.zeros(len(masses))
errors = np.zeros(len(masses))

for i in range(len(masses)):
    number[i], errors[i] =mass.massExcess(50,masses[i])


plt.figure(1, figsize=(8,5))
plt.ylabel(r"mass excess [MeV]", size=25)
plt.xlabel(r"mass number", size=25)
plt.gca().tick_params(labelsize=15)
plt.text(115, -60, r"Z=50", size=30)
plt.errorbar(masses, number, yerr=errors, color="black", marker="o", linestyle="--")
plt.tight_layout()
plt.show()

The script above will produce the following plot:

nndc

Sometimes a nuclear physicist is interested in up-to-date level information of an isotope. It would be really handy to obtain these data in an automatic way. For this, the nndc submodule is implemented which helps you to read level information for a specific isotope from the NNDC-database which get their values from the Nuclear Data Sheets.

The following example shows, how one can obtain the levelscheme as a pandas dataframe an plot the energies of the levels as a histogram for several germanium isotopes.

import nuclyr.nndc as nndc
import pandas as pd
import matplotlib.pyplot as plt

scheme1 = nndc.levelscheme("70Ge")
scheme2 = nndc.levelscheme("72Ge")
scheme3 = nndc.levelscheme("74Ge")
scheme4 = nndc.levelscheme("76Ge")

df1 = scheme1.energies()
df2 = scheme2.energies()
df3 = scheme3.energies()
df4 = scheme4.energies()


plt.figure(1, figsize=(10,6))
plt.xlabel(r"Energy [keV]", size=30)
plt.ylabel(r"$\rho$(E) [1/100 kev]", size=30)
plt.gca().tick_params(labelsize=20)

df1[0].hist(bins=int(df1[0].max()/100), alpha=0.5, label=r"70Ge")
df2[0].hist(bins=int(df2[0].max()/100), alpha=0.5, label=r"72Ge")
df3[0].hist(bins=int(df3[0].max()/100), alpha=0.5, label=r"74Ge")
df4[0].hist(bins=int(df4[0].max()/100), alpha=0.5, label=r"76Ge")

plt.legend(prop={"size":30})
plt.tight_layout()
plt.show()

The resulting histogram is basically the experimentally observed level density and looks like the following figure:

Release files for nuclyr 0.17

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

Source distribution (sdist)

Source distribution for nuclyr 0.17
File Size Uploaded
nuclyr-0.17.tar.gz 367.9 kB Details

Built distribution (wheel)

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

Total release size: 614.7 kB

Release files / nuclyr-0.17.tar.gz

Download URL nuclyr-0.17.tar.gz
Size 367.9 kB
Tags Source
SHA-256 checksum
How to use checksums
36952baa4ac5801362b2d9b44bdf47fe1ef5f363cae44b7336b8733bf46edf7b
BLAKE2b-256 checksum
How to use checksums
84080468a675df3c33857876dc3b25c0197a1b5a98f48ce137a6fb1a4cd19fb5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.5

Release files / nuclyr-0.17-py3-none-any.whl

Download URL nuclyr-0.17-py3-none-any.whl
Size 246.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
360827d2fd9fc34d15b0b110bc88113d4c8a4c5662cb3f5dc2fe2de06b99e4c4
BLAKE2b-256 checksum
How to use checksums
d865e2621747c9686d62236c0166cd83e9184222330f05b5f9b049d078a93e65
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.5

Release history Release notifications | RSS feed

This release

0.17 This release

2 release files

0.16

2 release files

0.15

2 release files

0.12

2 release files

0.11

2 release files

0.1

1 release file

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