1
- import pandas as pd
1
+ """Functionality to parse all data file into a single object."""
2
2
import pathlib
3
3
import typing
4
4
5
- from pynch .nubase_parse import NubaseParser
5
+ import pandas as pd
6
+
6
7
from pynch .ame_mass_parse import AMEMassParser
7
- from pynch .ame_reaction_1_parse import AMEReactionParser_1
8
- from pynch .ame_reaction_2_parse import AMEReactionParser_2
8
+ from pynch .ame_reaction_1_parse import AMEReactionParserOne
9
+ from pynch .ame_reaction_2_parse import AMEReactionParserTwo
10
+ from pynch .nubase_parse import NubaseParser
9
11
10
12
11
13
class MassTable :
12
- """Storage class for all of the mass data
14
+ """Storage class for all of the mass data.
13
15
14
- Internally there are separate dataframes for the NUBASE and AME data
16
+ Internally there are separate dataframes for the NUBASE and AME data as well as a combined one for all data
15
17
"""
16
18
17
19
def __init__ (self ):
20
+ """Do all of the work at construction."""
18
21
# Assume this file is some/path/pynch/pynch/mass_table.py
19
22
self .data_path = pathlib .Path (__file__ ) / ".." / ".." / "data"
20
23
self .existing_years = [2003 , 2012 , 2016 ]
@@ -24,9 +27,7 @@ def __init__(self):
24
27
self ._do_indexing ()
25
28
26
29
def _get_nubase_datafile (self , year : int ) -> str :
27
- """
28
- Use the given year to locate the nubase mass table file and return the absolute path.
29
- """
30
+ """Use the given year to locate the nubase mass table file and return the absolute path."""
30
31
nubase_mass = self .data_path / pathlib .Path (str (year ))
31
32
nubase_mass = nubase_mass .resolve ()
32
33
@@ -40,9 +41,7 @@ def _get_nubase_datafile(self, year: int) -> str:
40
41
return nubase_mass
41
42
42
43
def _get_ame_datafiles (self , year : int ) -> typing .Tuple [str , str , str ]:
43
- """
44
- Use the given year to locate the 3 AME data file and return the absolute path.
45
- """
44
+ """Use the given year to locate the 3 AME data file and return the absolute path."""
46
45
data_dir = self .data_path / pathlib .Path (str (year ))
47
46
data_dir = data_dir .resolve ()
48
47
@@ -62,40 +61,32 @@ def _get_ame_datafiles(self, year: int) -> typing.Tuple[str, str, str]:
62
61
return ame_mass , ame_reaction_1 , ame_reaction_2
63
62
64
63
def _validate_year (self , year : int ) -> None :
65
- """
66
- Point the appropriate variables at the required data files for the table year
67
- """
64
+ """Point the appropriate variables at the required data files for the table year."""
68
65
if year not in self .existing_years :
69
66
print (f"WARNING: { year } not a valid table year, using { self .existing_years [- 1 ]} " )
70
67
year = self .existing_years [- 1 ]
71
68
72
69
return year
73
70
74
71
def _parse_nubase_data (self , year : int ) -> pd .DataFrame :
75
- """
76
- Get the nubase for the given year as a pandas.DataFrame.
77
- """
72
+ """Get the nubase for the given year as a pandas.DataFrame."""
78
73
year = self ._validate_year (year )
79
74
return NubaseParser (self ._get_nubase_datafile (year ), year ).read_file ()
80
75
81
76
def _parse_ame_data (self , year : int ) -> pd .DataFrame :
82
- """
83
- Combine all the AME files from the given year into a pandas.DataFrame.
84
- """
77
+ """Combine all the AME files from the given year into a pandas.DataFrame."""
85
78
year = self ._validate_year (year )
86
79
ame_mass , ame_reaction_1 , ame_reaction_2 = self ._get_ame_datafiles (year )
87
80
88
81
ame_mass_df = AMEMassParser (ame_mass , year ).read_file ()
89
82
90
83
# Merge all 3 of the AME files/data frames into one
91
84
common_columns = ['A' , 'Z' , 'N' , 'TableYear' , 'Symbol' ]
92
- temp_df = ame_mass_df .merge (AMEReactionParser_1 (ame_reaction_1 , year ).read_file (), on = common_columns )
93
- return temp_df .merge (AMEReactionParser_2 (ame_reaction_2 , year ).read_file (), on = common_columns )
85
+ temp_df = ame_mass_df .merge (AMEReactionParserOne (ame_reaction_1 , year ).read_file (), on = common_columns )
86
+ return temp_df .merge (AMEReactionParserTwo (ame_reaction_2 , year ).read_file (), on = common_columns )
94
87
95
88
def _combine_all_data (self ) -> pd .DataFrame :
96
- """
97
- Combine all NUBASE and AME data into a single pandas DataFrame
98
- """
89
+ """Combine all NUBASE and AME data into a single pandas DataFrame."""
99
90
common_columns = ['A' , 'Z' , 'N' , 'TableYear' , 'Symbol' ]
100
91
return self .nubase .merge (self .ame , on = common_columns )
101
92
0 commit comments