Skip to content

Commit 8bac52c

Browse files
committed
Fix flake8 warnings
Two files each have one line that's too long but they are for a string and variable name so will leave for the moment.
1 parent df051dd commit 8bac52c

13 files changed

+90
-110
lines changed

.flake8

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
[flake8]
2+
ignore =
3+
# I'm not always in an imperative mood
4+
D401
25
exclude = tests,.git,__pycache__
36
max-line-length = 120
47
count = True

app.py

+14-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
"""dsfds."""
12
import dash
3+
from dash.dependencies import Input, Output
4+
5+
import dash_bootstrap_components as dbc
6+
27
import dash_core_components as dcc
8+
39
import dash_html_components as html
4-
import dash_bootstrap_components as dbc
5-
from dash.dependencies import Input, Output
610

711
import plotly.express as px
812

@@ -34,7 +38,7 @@
3438
],
3539
)
3640
def update_graph(y_var, x_value, year):
37-
41+
"""The actions to do when the selected data is changed."""
3842
df_f = df.loc[table_years[year]][["Symbol", "Decay", "A", "Z", "N", y_var]]
3943
df_ff = df_f.loc[(df_f["A"] == x_value)]
4044

@@ -75,19 +79,19 @@ def update_graph(y_var, x_value, year):
7579

7680
title = html.H2(f"A = {x_value}")
7781

78-
minA = df_f["A"].min()
79-
maxA = df_f["A"].max()
82+
min_a = df_f["A"].min()
83+
max_a = df_f["A"].max()
8084

81-
marksA = {i: f"{i}" for i in range(20, maxA, 20)}
85+
marks_a = {i: f"{i}" for i in range(20, max_a, 20)}
8286

8387
return (
8488
title,
8589
a_fig,
8690
z_fig.update_traces(mode="lines+markers"),
8791
n_fig.update_traces(mode="lines+markers"),
88-
minA,
89-
maxA,
90-
marksA,
92+
min_a,
93+
max_a,
94+
marks_a,
9195
)
9296

9397

@@ -144,8 +148,7 @@ def update_graph(y_var, x_value, year):
144148

145149

146150
def main():
147-
"""
148-
"""
151+
"""For testing."""
149152

150153
# df = MassData().full_data
151154
# print(df)

pynch/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""May not actually be needed."""

pynch/ame_mass_file.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1+
"""Storage for variable line positions."""
12
from pynch.parse import Parse
23

34

45
class AMEMassFile(Parse):
5-
"""Easy access to where the variables are in the AME mass file
6-
7-
The AME mass file
8-
"""
6+
"""Easy access to where the variables are in the AME mass file."""
97

108
def __init__(self):
9+
"""Setup up the values."""
1110
super(AMEMassFile, self).__init__()
1211
self.START_A = 16
1312
self.END_A = 19

pynch/ame_mass_parse.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1+
"""Extract the data from the AME mass file."""
12
import pandas as pd
23

34
from pynch.ame_mass_file import AMEMassFile
45

56

67
class AMEMassParser(AMEMassFile):
7-
"""Parse the AME mass file
8+
"""Parse the AME mass file.
89
910
The format is known but I don't think python can easily parse it.
1011
"""
1112

1213
def __init__(self, filename: str, year: int):
14+
"""Set the file to read and table year."""
1315
super().__init__()
1416
self.filename = filename
1517
self.year = year
1618
print(f"Reading {self.filename} from {self.year}")
1719

1820
def _read_line(self, line: str) -> dict:
19-
"""
20-
Read a line from the file
21-
"""
21+
"""Read a line from the file."""
2222
if line.find("#") != -1:
2323
line = line.replace("#", " ")
2424

@@ -43,9 +43,7 @@ def _read_line(self, line: str) -> dict:
4343
return data
4444

4545
def read_file(self) -> pd.DataFrame:
46-
"""
47-
Read the file
48-
"""
46+
"""Read the file."""
4947
with open(self.filename, "r") as f:
5048
lines = [line.rstrip() for line in f]
5149

pynch/ame_reaction_1_file.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1+
"""Storage for the variable line positions."""
12
from pynch.parse import Parse
23

34

4-
class AMEReactionFile_1(Parse):
5-
"""Easy access to where the variables are in the first AME reaction file
6-
7-
The AME first reaction file
8-
"""
5+
class AMEReactionFileOne(Parse):
6+
"""Easy access to where the variables are in the first AME reaction file."""
97

108
def __init__(self):
11-
super(AMEReactionFile_1, self).__init__()
9+
"""Setup the values that locate the variable."""
10+
super(AMEReactionFileOne, self).__init__()
1211
self.START_R1_A = 1
1312
self.END_R1_A = 4
1413
self.START_R1_Z = 8

pynch/ame_reaction_1_parse.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1+
"""Extract the data from the first reaction file."""
12
import pandas as pd
23

3-
from pynch.ame_reaction_1_file import AMEReactionFile_1
4+
from pynch.ame_reaction_1_file import AMEReactionFileOne
45

56

6-
class AMEReactionParser_1(AMEReactionFile_1):
7-
""" Parse the first AME reaction file
7+
class AMEReactionParserOne(AMEReactionFileOne):
8+
"""Parse the first AME reaction file.
89
910
The format is known but I don't think python can easily parse it.
1011
"""
1112

1213
def __init__(self, filename: str, year: int):
14+
"""Set the file to read and table year."""
1315
super().__init__()
1416
self.filename = filename
1517
self.year = year
1618
print(f"Reading {self.filename} from {self.year}")
1719

1820
def _read_line(self, line: str) -> dict:
19-
"""
20-
Read a line from the file
21-
"""
21+
"""Read a line from the file."""
2222
# Don't use a '#' as an experimental marker in this file
2323
# but still need to remove it
2424
if line.find("#") != -1:
@@ -51,9 +51,7 @@ def _read_line(self, line: str) -> dict:
5151
return data
5252

5353
def read_file(self) -> pd.DataFrame:
54-
"""
55-
Read the file
56-
"""
54+
"""Read the file."""
5755
with open(self.filename, "r") as f:
5856
lines = [line.rstrip() for line in f]
5957

pynch/ame_reaction_2_file.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1+
"""Storage for the variable line positions."""
12
from pynch.parse import Parse
23

34

4-
class AMEReactionFile_2(Parse):
5-
"""Easy access to where the variables are in the second AME reaction file
6-
7-
The second AME reaction file
8-
"""
5+
class AMEReactionFileTwo(Parse):
6+
"""Easy access to where the variables are in the second AME reaction file."""
97

108
def __init__(self):
11-
super(AMEReactionFile_2, self).__init__()
9+
"""Setup the values that locate the variables."""
10+
super(AMEReactionFileTwo, self).__init__()
1211
self.START_R2_A = 1
1312
self.END_R2_A = 4
1413
self.START_R2_Z = 8

pynch/ame_reaction_2_parse.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1+
"""Extract the date from the second reaction file."""
12
import pandas as pd
23

3-
from pynch.ame_reaction_2_file import AMEReactionFile_2
4+
from pynch.ame_reaction_2_file import AMEReactionFileTwo
45

56

6-
class AMEReactionParser_2(AMEReactionFile_2):
7-
"""Parse the second AME reaction file
7+
class AMEReactionParserTwo(AMEReactionFileTwo):
8+
"""Parse the second AME reaction file.
89
910
The format is known but I don't think python can easily parse it.
1011
"""
1112

1213
def __init__(self, filename: str, year: int):
14+
"""Set the file to read and table year."""
1315
super().__init__()
1416
self.filename = filename
1517
self.year = year
1618
print(f"Reading {self.filename} from {self.year}")
1719

1820
def _read_line(self, line: str) -> dict:
19-
"""
20-
Read a line from the file
21-
"""
21+
"""Read a line from the file."""
2222
# Don't use a '#' as an experimental marker in this file
2323
# but still need to remove it
2424
if line.find("#") != -1:
@@ -51,9 +51,7 @@ def _read_line(self, line: str) -> dict:
5151
return data
5252

5353
def read_file(self) -> pd.DataFrame:
54-
"""
55-
Read the file
56-
"""
54+
"""Read the file."""
5755
with open(self.filename, "r") as f:
5856
lines = [line.rstrip() for line in f]
5957

pynch/mass_table.py

+17-26
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1-
import pandas as pd
1+
"""Functionality to parse all data file into a single object."""
22
import pathlib
33
import typing
44

5-
from pynch.nubase_parse import NubaseParser
5+
import pandas as pd
6+
67
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
911

1012

1113
class MassTable:
12-
"""Storage class for all of the mass data
14+
"""Storage class for all of the mass data.
1315
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
1517
"""
1618

1719
def __init__(self):
20+
"""Do all of the work at construction."""
1821
# Assume this file is some/path/pynch/pynch/mass_table.py
1922
self.data_path = pathlib.Path(__file__) / ".." / ".." / "data"
2023
self.existing_years = [2003, 2012, 2016]
@@ -24,9 +27,7 @@ def __init__(self):
2427
self._do_indexing()
2528

2629
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."""
3031
nubase_mass = self.data_path / pathlib.Path(str(year))
3132
nubase_mass = nubase_mass.resolve()
3233

@@ -40,9 +41,7 @@ def _get_nubase_datafile(self, year: int) -> str:
4041
return nubase_mass
4142

4243
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."""
4645
data_dir = self.data_path / pathlib.Path(str(year))
4746
data_dir = data_dir.resolve()
4847

@@ -62,40 +61,32 @@ def _get_ame_datafiles(self, year: int) -> typing.Tuple[str, str, str]:
6261
return ame_mass, ame_reaction_1, ame_reaction_2
6362

6463
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."""
6865
if year not in self.existing_years:
6966
print(f"WARNING: {year} not a valid table year, using {self.existing_years[-1]}")
7067
year = self.existing_years[-1]
7168

7269
return year
7370

7471
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."""
7873
year = self._validate_year(year)
7974
return NubaseParser(self._get_nubase_datafile(year), year).read_file()
8075

8176
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."""
8578
year = self._validate_year(year)
8679
ame_mass, ame_reaction_1, ame_reaction_2 = self._get_ame_datafiles(year)
8780

8881
ame_mass_df = AMEMassParser(ame_mass, year).read_file()
8982

9083
# Merge all 3 of the AME files/data frames into one
9184
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)
9487

9588
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."""
9990
common_columns = ['A', 'Z', 'N', 'TableYear', 'Symbol']
10091
return self.nubase.merge(self.ame, on=common_columns)
10192

pynch/nubase_file.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
"""Storage for the variable line positions."""
12
from pynch.parse import Parse
23

34

45
class NubaseFile(Parse):
5-
"""Easy access to where variables are in the NUBASE file
6+
"""Easy access to where variables are in the NUBASE file.
67
78
The NUBASE data file is formatted by location in the line, values exist
89
between 2 specific columns in the line. Store the start and end locations
@@ -11,6 +12,7 @@ class NubaseFile(Parse):
1112
"""
1213

1314
def __init__(self):
15+
"""Setup the values that locate the variable."""
1416
super(NubaseFile, self).__init__()
1517
self.START_A = 0
1618
self.END_A = 3

0 commit comments

Comments
 (0)