Skip to content

Commit

Permalink
More docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
sbradnam committed Nov 6, 2024
1 parent 587a135 commit 27d7a1d
Showing 1 changed file with 57 additions and 28 deletions.
85 changes: 57 additions & 28 deletions jade/expoutput.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import pandas as pd
from docx.shared import Inches
from f4enix.input.MCNPinput import D1S_Input
from f4enix.output.mctal import Tally
from scipy.interpolate import interp1d
from tqdm import tqdm

Expand Down Expand Up @@ -395,7 +396,7 @@ def _print_raw(self) -> None:
data.to_csv(file, header=True, index=False)

@abstractmethod
def _processMCNPdata(self, output : MCNPSimOutput) -> dict:
def _processMCNPdata(self, output : MCNPSimOutput):
"""
Given an mctal file object return the meaningful data extracted. Some
post-processing on the data may be foreseen at this stage.
Expand Down Expand Up @@ -469,7 +470,7 @@ class FNGOutput(ExperimentalOutput):
],
}

def _processMCNPdata(self, output: MCNPSimOutput):
def _processMCNPdata(self, output: MCNPSimOutput) -> pd.DataFrame:
"""
Read All tallies and return them as a dictionary of DataFrames. This
aslo needs to ovveride the raw data since unfortunately it appears
Expand Down Expand Up @@ -537,6 +538,10 @@ def _processMCNPdata(self, output: MCNPSimOutput):
def _pp_excel_comparison(self) -> None:
"""
Responsible for producing excel outputs
Returns
-------
None.
"""
# Dump the global C/E table
ex_outpath = os.path.join(self.excel_path, self.testname + "_CE_tables.xlsx")
Expand Down Expand Up @@ -570,7 +575,7 @@ def _pp_excel_comparison(self) -> None:
ws = writer.sheets[folder]
ws.write_string(0, 0, '"C/E (mean +/- σ)"')

def _get_collected_data(self, folder):
def _get_collected_data(self, folder : str) -> pd.DataFrame:
"""
Given a campaign it builds a single table containing all experimental
and computational data available for the total SDDR tally.
Expand All @@ -597,13 +602,13 @@ def _get_collected_data(self, folder):

return df

def _build_atlas(self, tmp_path, atlas):
def _build_atlas(self, tmp_path : str | os.PathLike, atlas : at.Atlas) -> at.Atlas:
"""
Fill the atlas with the customized plots. Creation and saving of the
atlas are handled elsewhere.
Parameters
----------
tmp_path : path
tmp_path : str or os.PathLike
path to the temporary folder where to dump images.
atlas : Atlas
Object representing the plot Atlas.
Expand Down Expand Up @@ -718,33 +723,42 @@ def _build_atlas(self, tmp_path, atlas):

return atlas

def _read_exp_file(self, filepath):
def _read_exp_file(self, filepath : str | os.PathLike) -> pd.DataFrame:
"""
Override parent method since the separator for these experimental
files is ";"
Parameters
----------
filepath : str
string containing the path to the experimental file to be read
filepath : str | os.PathLike
string or os.PathLike containing the path to the experimental file to be read
for comparison
Returns
-------
pd.DataFrame
Pandas data frame containing experimental data
"""
return pd.read_csv(filepath, sep=";")


class SpectrumOutput(ExperimentalOutput):
def _build_atlas(self, tmp_path, atlas):
def _build_atlas(self, tmp_path : str | os.PathLike, atlas : at.Atlas) -> at.Atlas:
"""
Fill the atlas with the customized plots. Creation and saving of the
atlas are handled elsewhere.
Parameters
----------
tmp_path : str
tmp_path : str | os.PathLike
path to the temporary folder containing the plots for the atlas
atlas : Atlas
atlas : at.Atlas
Object representing the plot Atlas.
Returns
-------
atlas : at.Atlas
Object representing the plot Atlas.
"""
self.tables = []
self.bench_conf = pd.read_excel(self.cnf_path)
Expand Down Expand Up @@ -794,27 +808,32 @@ def _build_atlas(self, tmp_path, atlas):

return atlas

def _get_tally_info(self, tally):
def _get_tally_info(self, tally : Tally) -> tuple[int, str, str]:
"""
Extracts and assigns information from the tally object, as well as
information from the benchmark config variable
Args:
tally (Tally): JADE tally object
Returns:
tallynum (int): Tally number of the tally being plotted
particle (str): Type of quantity being plotted on the X axis
quant + unit (str): Unit of quantity being plotted on the X axis
Parameters
----------
tally : Tally
F4Enix tally object
Returns
-------
tallynum : int
Tally number of the tally being plotted
particle : str
Type of quantity being plotted on the X axis
quant + unit : str
Unit of quantity being plotted on the X axis
"""
tallynum = tally.tallyNumber
particle = tally.particleList[np.where(tally.tallyParticles == 1)[0][0]]
quant = self.bench_conf.loc[tallynum, "X Quantity"]
unit = self.bench_conf.loc[tallynum, "X Unit"]
return tallynum, particle, quant + " [" + unit + "]"

def _define_title(self, input, quantity_CE):
def _define_title(self, input : str, quantity_CE : str) -> str:
"""Assigns the title for atlas plot
Parameters
Expand All @@ -837,9 +856,13 @@ def _define_title(self, input, quantity_CE):
title = self.testname + " " + input + ", " + quantity_CE
return title

def _dump_ce_table(self):
def _dump_ce_table(self) -> None:
"""
Generates the C/E table and dumps them as an .xlsx file
Returns
-------
None
"""
final_table = pd.concat(self.tables)
skipcol_global = 0
Expand Down Expand Up @@ -930,7 +953,7 @@ def _dump_ce_table(self):

return

def _data_collect(self, input, tallynum, quantity_CE, e_intervals):
def _data_collect(self, input : str, tallynum : str, quantity_CE : str, e_intervals : list) -> tuple[list, str]:
"""Collect data for C/E tables
Parameters
Expand Down Expand Up @@ -999,26 +1022,32 @@ def _data_collect(self, input, tallynum, quantity_CE, e_intervals):
pass
return data, x_lab

def _pp_excel_comparison(self):
def _pp_excel_comparison(self) -> None:
"""
Excel is actually printed by the build atlas in this case
Returns
-------
None
"""
# Excel is actually printed by the build atlas in this case
pass

def _processMCNPdata(self, output):
def _processMCNPdata(self, output : MCNPSimOutput) -> dict:
"""
given the mctal file the lethargy flux and energies are returned
both for the neutron and photon tally
Parameters
----------
output : MCNPoutput
output : MCNPSimOutput
object representing the MCNP output.
Returns
-------
res : dic
res : dict
contains the extracted lethargy flux and energies.
"""

res = {}
# Read tally energy binned fluxes
for tallynum, data in output.tallydata.items():
Expand Down

0 comments on commit 27d7a1d

Please sign in to comment.