Skip to content

Pip package #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,24 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.10', '3.11', '3.12']
python-version: ['3.10', '3.11', '3.12', '3.13']

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install pytest coverage
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pip install -e '.[dev]'
- name: Test with pytest
run: |
coverage run -m pytest -v && coverage xml
- name: Upload coverage to Codecov
if: ${{ matrix.python-version == '3.12' }}
uses: codecov/codecov-action@v3
if: ${{ matrix.python-version == '3.13' }}
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ venv*/
# Test coverage related files and directories
.coverage
coverage_html_report

# Package build files and folders
*.egg-info/
File renamed without changes.
45 changes: 18 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,14 @@

## Introduction

The nuclear mass tables produced by [NUBASE](http://amdc.in2p3.fr/web/nubase_en.html) and [AME](https://www-nds.iaea.org/amdc/) are parsed into pandas dataframes.
These dataframes are then read with the [dash](https://plotly.com/dash/) module to create an interactive webpage to allow the user to interogate the data they are interested in.
The nuclear mass tables produced by [NUBASE](http://amdc.in2p3.fr/web/nubase_en.html) and [AME](https://www-nds.iaea.org/amdc/) have unique formats.
This package does the hard work for you and parses the files into a single pandas dataframe for simpler access.

No guarantee is supplied with regards to the accuracy of the data presented.
Estimated values are included, please always refer to the original sources.
All data should, however, be accurate.

Additional functionality and polish will be added as I learn more about [dash](https://plotly.com/dash/).
In the meantime, suggestions are welcome via [issues](https://github.com/php1ic/pynch/issues) or a pull request.

## Setup

As is the standard, you can confirm you have the necessary modules using the [requirements.txt](./requirements.txt) file
```bash
pip install --user -r requirements.txt
```

## Running

With all of the necessary requirements installed, the below will start the app
```bash
python3 app.py
```
The console will tell you where to point your browser - likely http://127.0.0.1:8050/.
Suggestions are welcome via [issues](https://github.com/php1ic/pynch/issues) or a pull request.

## Mass tables

Expand All @@ -41,16 +25,23 @@ The data files released by the papers linked below are used to create the mass t
The NUBASE files are read for all of the data values, with the AME files being used to populate an additional mass excess data field.
No comparison or validation is done on common values.

## Additional uses
## Setup

Until the package is added to Python Package Index, the local clone of the repo must be installed from within the top level directory.
```bash
pip install -e .
```

## Usage

If you want to do your own thing with the data, you could import this module, access `MassTable().full_data`, then sort, slice and filter the resultant dataframe to your heart's content.
Import the module to access `MassTable().full_data`, then sort, slice and filter the resultant dataframe to your heart's content.

For example, track how the accuracy of the mass excess of 18B changes once it is experimentally measured
```python
>>> import pynch.mass_table as mt
>>> df = mt.MassTable().full_data
>>> df[(df['A'] == 18) & (df['Z'] == 5)][['Experimental', 'NubaseMassExcess', 'NubaseMassExcessError', 'NubaseRelativeError', 'DiscoveryYear']]
Experimental NubaseMassExcess NubaseMassExcessError NubaseRelativeError DiscoveryYear
>>> df[(df['A'] == 18) & (df['Z'] == 5)][['Experimental', 'NUBASEMassExcess', 'NUBASEMassExcessError', 'NUBASERelativeError', 'DiscoveryYear']]
Experimental NUBASEMassExcess NUBASEMassExcessError NUBASERelativeError DiscoveryYear
TableYear
2003 False 52320.0 800.0 0.015291 1900
2012 True 51850.0 170.0 0.003279 2010
Expand All @@ -61,7 +52,7 @@ Or for all of the A=100 isotopes from the 2012 table that have a mass-excess err
```python
>>> import pynch.mass_table as mt
>>> df = mt.MassTable().full_data
>>> df.query('TableYear == 2012 and A == 100 and NubaseMassExcessError < 10.0')[['A', 'Z', 'Symbol', 'DiscoveryYear']]
>>> df.query('TableYear == 2012 and A == 100 and NUBASEMassExcessError < 10.0')[['A', 'Z', 'Symbol', 'DiscoveryYear']]
A Z Symbol DiscoveryYear
TableYear
2012 100 40 Zr 1970
Expand All @@ -77,12 +68,12 @@ Or how does the NUBASE mass-excess compare with the AME value for experimentally
>>> import pynch.mass_table as mt
>>> df = mt.MassTable().full_data
>>> # Create a new column comparing the measured values
>>> df['NUBASE-AME'] = df['NubaseMassExcess'] - df['AMEMassExcess']
>>> df['NUBASE-AME'] = df['NUBASEMassExcess'] - df['AMEMassExcess']
>>> # Extract the data for measured isotopes and from the latest table
>>> df_comparison = df.query('TableYear == 2020 and Experimental == True')
>>> # Sort the difference in measured data by absolute value and print the columns we are interested in
>>> df_comparison.sort_values(by=['NUBASE-AME'], key=abs, ascending=False)[['A', 'Z', 'Symbol', 'NubaseMassExcess', 'AMEMassExcess', 'NUBASE-AME']].head(n=10)
A Z Symbol NubaseMassExcess AMEMassExcess NUBASE-AME
>>> df_comparison.sort_values(by=['NUBASE-AME'], key=abs, ascending=False)[['A', 'Z', 'Symbol', 'NUBASEMassExcess', 'AMEMassExcess', 'NUBASE-AME']].head(n=10)
A Z Symbol NUBASEMassExcess AMEMassExcess NUBASE-AME
TableYear
2020 221 91 Pa 20370.0 20374.937 -4.937
2020 57 23 V -44440.0 -44435.063 -4.937
Expand Down
189 changes: 0 additions & 189 deletions app.py

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 8 additions & 7 deletions pynch/mass_table.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Functionality to parse all data file into a single object."""
import importlib.resources
import logging
import pathlib
import typing
Expand All @@ -8,7 +9,7 @@
from pynch.ame_mass_parse import AMEMassParser
from pynch.ame_reaction_1_parse import AMEReactionParserOne
from pynch.ame_reaction_2_parse import AMEReactionParserTwo
from pynch.nubase_parse import NubaseParser
from pynch.nubase_parse import NUBASEParser


class MassTable:
Expand All @@ -19,8 +20,8 @@ class MassTable:

def __init__(self):
"""Do all of the work at construction."""
# Assume this file is some/path/pynch/pynch/mass_table.py
self.data_path = pathlib.Path(__file__) / ".." / ".." / "data"
self.data_path = importlib.resources.files("pynch.data")
print(self.data_path)
self.existing_years = [2003, 2012, 2016, 2020]
self.nubase = pd.concat([self._parse_nubase_data(y) for y in self.existing_years], ignore_index=True)
self.ame = pd.concat([self._parse_ame_data(y) for y in self.existing_years], ignore_index=True)
Expand Down Expand Up @@ -78,7 +79,7 @@ def _validate_year(self, year: int) -> int:
def _parse_nubase_data(self, year: int) -> pd.DataFrame:
"""Get the nubase for the given year as a pandas.DataFrame."""
year = self._validate_year(year)
return NubaseParser(self._get_nubase_datafile(year), year).read_file()
return NUBASEParser(self._get_nubase_datafile(year), year).read_file()

def _parse_ame_data(self, year: int) -> pd.DataFrame:
"""Combine all the AME files from the given year into a pandas.DataFrame."""
Expand All @@ -97,14 +98,14 @@ def _combine_all_data(self) -> pd.DataFrame:
common_columns = ['A', 'Z', 'N', 'TableYear', 'Symbol']
df = self.nubase.merge(self.ame, on=common_columns)

df["NubaseRelativeError"] = abs(
df["NubaseMassExcessError"] / df["NubaseMassExcess"]
df["NUBASERelativeError"] = abs(
df["NUBASEMassExcessError"] / df["NUBASEMassExcess"]
)
df["AMERelativeError"] = abs(df["AMEMassExcessError"] / df["AMEMassExcess"])

# 12C has a 0.0 +/ 0.0 mass excess by definition so calculating relative error -> NaN
# Set the value to 0.0 as that's what it is
df.loc[(df.Symbol == "C") & (df.A == 12), "NubaseRelativeError"] = 0.0
df.loc[(df.Symbol == "C") & (df.A == 12), "NUBASERelativeError"] = 0.0
df.loc[(df.Symbol == "C") & (df.A == 12), "AMERelativeError"] = 0.0

# 198Au has a typo in it's decay mode in the 2012 table. It is recorded as '-'
Expand Down
2 changes: 1 addition & 1 deletion pynch/nubase_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from pynch.parse import Parse


class NubaseFile(Parse):
class NUBASEFile(Parse):
"""Easy access to where variables are in the NUBASE file.

The NUBASE data file is formatted by location in the line, values exist
Expand Down
Loading