Skip to content

Added pyproject.toml #5

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 4 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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pip install --user -r requirements.txt

With all of the necessary requirements installed, the below will start the app
```bash
python3 app.py
python3 src/app.py
```
The console will tell you where to point your browser - likely http://127.0.0.1:8050/.

Expand All @@ -43,7 +43,7 @@ No comparison or validation is done on common values.

## Additional uses

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.
If you want to do your own thing with the data, you could install this package, import this module, access `MassTable().full_data`, then sort, slice and filter the resultant dataframe to your heart's content. You can install this package with `pip install git+<package-repo>` where `<package-repo>` is the git repository of this package.

For example, track how the accuracy of the mass excess of 18B changes once it is experimentally measured
```python
Expand Down
16 changes: 16 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[build-system]
requires = ["setuptools>=64", "setuptools_scm>=8"]
build-backend = "setuptools.build_meta"

[project]
name = "pynch"
dynamic = ["dependencies", "version"]

[tool.setuptools]
include-package-data = true

[tool.setuptools.packages.find]
where = ["src"]

[tool.setuptools.dynamic]
dependencies = {file = ["requirements.txt"]}
2 changes: 1 addition & 1 deletion app.py → src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def update_graph(y_var, x_value, year):

logit = (
True
if y_var in ["HalfLife", "NubaseRelativeError", "AMERelativeError"]
if y_var in ["HalfLife", "NUBASERelativeError", "AMERelativeError"]
else False
)

Expand Down
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.
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.
23 changes: 13 additions & 10 deletions pynch/mass_table.py → src/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 @@ -20,7 +21,7 @@ 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 = "data"
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 All @@ -29,8 +30,9 @@ def __init__(self):

def _get_nubase_datafile(self, year: int) -> pathlib.Path:
"""Use the given year to locate the nubase mass table file and return the absolute path."""
nubase_mass = self.data_path / pathlib.Path(str(year))
nubase_mass = nubase_mass.resolve()
with importlib.resources.path("pynch", self.data_path) as p:
nubase_mass = p / pathlib.Path(str(year))
nubase_mass = nubase_mass.resolve()

if year == 2003:
nubase_mass = nubase_mass / "nubtab03.asc"
Expand All @@ -45,8 +47,9 @@ def _get_nubase_datafile(self, year: int) -> pathlib.Path:

def _get_ame_datafiles(self, year: int) -> typing.Tuple[pathlib.Path, pathlib.Path, pathlib.Path]:
"""Use the given year to locate the 3 AME data file and return the absolute path."""
data_dir = self.data_path / pathlib.Path(str(year))
data_dir = data_dir.resolve()
with importlib.resources.path("pynch", self.data_path) as p:
data_dir = p / pathlib.Path(str(year))
data_dir = data_dir.resolve()

if year == 2003:
ame_mass = data_dir / "mass.mas03"
Expand Down Expand Up @@ -78,7 +81,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 +100,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 → src/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
8 changes: 4 additions & 4 deletions pynch/nubase_parse.py → src/pynch/nubase_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

import pandas as pd

from pynch.nubase_file import NubaseFile
from pynch.nubase_file import NUBASEFile


class NubaseParser(NubaseFile):
class NUBASEParser(NUBASEFile):
"""Parse the NUBASE data file.

A collection of functions to parse the weird format of the NUBASE file.
Expand Down Expand Up @@ -96,8 +96,8 @@ def _read_line(self, line: str) -> dict:
"TableYear": self.year,
"A": self._read_as_int(line, self.START_A, self.END_A),
"Z": self._read_as_int(line, self.START_Z, self.END_Z),
"NubaseMassExcess": self._read_as_float(line, self.START_ME, self.END_ME),
"NubaseMassExcessError": self._read_as_float(line, self.START_DME, self.END_DME),
"NUBASEMassExcess": self._read_as_float(line, self.START_ME, self.END_ME),
"NUBASEMassExcessError": self._read_as_float(line, self.START_DME, self.END_DME),
# "LevelEnergy" : self._read_as_float(,
# line, self.START_ISOMER, self.END_ISOMER
# )
Expand Down
File renamed without changes.
Loading