nucml.ensdf package

Submodules

nucml.ensdf.data_utilities module

nucml.ensdf.data_utilities.append_ensdf_levels(tot_num_levels, df, Z, A, log=False, scale=False, scaler=None, to_scale=[])[source]

Expands the energy levels up to “tot_num_levels” for the given ENSDF isotopic sample.

Parameters
  • tot_num_levels (int) – Total number of levels to include (i.e 50 will include levels 1-50).

  • df (DataFrame) – DataFrame containing an already extracted isotopic sample.

  • Z (int) – Number of protons.

  • A (int) – Mass Number.

  • log (bool, optional) – If True, the logarithm will be applied to the Level Number.

  • scale (bool, optional) – If True, the data will be tranform using the provided scaler. Defaults to False.

  • scaler (object, optional) – Scikit-Learn trained transformer. Defaults to None.

  • to_scale (list, optional) – List of features to be scaled. Defaults to [].

Returns

Extracted element sample.

Return type

DataFrame

nucml.ensdf.data_utilities.append_ensdf_levels_nodata(tot_num_levels, df, log=False, scale=False, scaler=None, to_scale=[])[source]

Expands the energy levels up to “tot_num_levels” for the given ENSDF isotopic sample if no Level Energy data is avaliable.

Parameters
  • tot_num_levels (int) – Total number of levels to include (i.e 50 will include levels 1-50).

  • df (DataFrame) – DataFrame containing an already extracted isotopic sample.

  • log (bool, optional) – If True, the logarithm will be applied to the Level Number.

  • scale (bool, optional) – If True, the data will be tranform using the provided scaler. Defaults to False.

  • scaler (object, optional) – Scikit-Learn trained transformer. Defaults to None.

  • to_scale (list, optional) – List of features to be scaled. Defaults to [].

Returns

Extracted element sample.

Return type

DataFrame

nucml.ensdf.data_utilities.append_ensdf_levels_range(tot_num_levels, df, Z, A, steps=1, log=False, scale=False, scaler=None, to_scale=[])[source]

Expands the energy levels up to “tot_num_levels” for the given ENSDF isotopic sample using a range with n steps rather than linear.

Parameters
  • tot_num_levels (int) – Total number of levels to include (i.e 50 will include levels 1-50).

  • df (DataFrame) – DataFrame containing an already extracted isotopic sample.

  • Z (int) – Number of protons.

  • A (int) – Mass Number.

  • steps (int) – Number of intermediate steps between 1 and tot_num_levels to create.

  • log (bool, optional) – If True, the logarithm will be applied to the Level Number.

  • scale (bool, optional) – If True, the data will be tranform using the provided scaler. Defaults to False.

  • scaler (object, optional) – Scikit-Learn trained transformer. Defaults to None.

  • to_scale (list, optional) – List of features to be scaled. Defaults to [].

Returns

Extracted element sample.

Return type

DataFrame

nucml.ensdf.data_utilities.generate_level_density_csv(df, Z, A, nodata=False, upper_energy_mev=20, get_upper=False, tot_num_levels=0, it_limit=500, plot=False, save=False, saving_dir='')[source]

Fits a linear model to the isotopic sample provided, and saves a CSV file with the linear model values for each energy level avaliable. If get_upper is True, then a new level number will be appended until the linear model predicts a value above the upper_energy_mev value.

Parameters
  • df (DataFrame) – DataFrame containing the needed data for isotope Z, A.

  • Z (int) – Number of protons.

  • A (int) – Mass number.

  • nodata (bool, optional) – If True, it assumes there is no avaliable data for the queried isotope. Defaults to False.

  • upper_energy_mev (int, optional) – If get_upper is True, the algorithm will iterate until this energy is reached. Defaults to 20 MeV.

  • get_upper (bool, optional) – If True, more levels will be added until the level energy in the level density reaches the 20 MeV mark. Defaults to False.

  • tot_num_levels (int, optional) – If any value other than 0 is given, it will append the remaining energy levels until reaching tot_num_levels. Defaults to 0.

  • it_limit (int, optional) – Sets the iteration limits for the linear model to reach the upper_energy_mev value. Defaults to 500.

  • plot (bool, optional) – If True, a plot of the linear model along the experimental levels will be rendered. Defaults to False.

  • save (bool, optional) – If True, the resulting DataFrame using the linear model will be saved. Defaults to False.

  • saving_dir (str, optional) – Path-like string pointing towars the directory where the DataFrame will be saved. Defaults to “”.

Returns

New DataFrame with Level Number and Level Energy as predicted by the linear model.

Return type

DataFrame

nucml.ensdf.data_utilities.get_level_density(energy_mev, df)[source]

Given an energy density DataFrame, the level density at a wanted energy is returned.

Parameters
  • energy_mev (float) – Energy point at which the level density is to be returned.

  • df (DataFrame) – Level Density DataFrame to interpolate at energy_mev.

Returns

Level density at “energy_mev”.

Return type

float

nucml.ensdf.data_utilities.load_ensdf_element(df, Z, scale=False, scaler=None, to_scale=[])[source]

Loads ENSDF data for a given element (Z).

Parameters
  • df (DataFrame) – DataFrame containing all necessary information for Z, A.

  • Z (int) – Number of protons.

  • scale (bool, optional) – If True, the data will be tranform using the provided scaler. Defaults to False.

  • scaler (object, optional) – Scikit-Learn trained transformer. Defaults to None.

  • to_scale (list, optional) – List of features to be scaled. Defaults to [].

Returns

Extracted element sample.

Return type

DataFrame

nucml.ensdf.data_utilities.load_ensdf_samples(df, Z, A, scale=False, scaler=None, to_scale=[])[source]

Loads ENSDF data for a particular isotope (Z, A).

Parameters
  • df (DataFrame) – DataFrame containing all necessary information for Z, A.

  • Z (int) – Number of protons.

  • A (int) – Mass Number.

  • scale (bool, optional) – If True, the data will be tranform using the provided scaler. Defaults to False.

  • scaler (object, optional) – Scikit-Learn trained transformer. Defaults to None.

  • to_scale (list, optional) – List of features to be scaled. Defaults to [].

Returns

Extracted isotope sample.

Return type

DataFrame

nucml.ensdf.data_utilities.make_predictions_from_df(df, Z, A, model, model_type, scaler, to_scale, log_sqrt=False, log=False, plot=False, save=False, save_dir='')[source]

Returns a set of ML predictions at all known levels within the passed DataFrame.

Parameters
  • df (DataFrame) – DataFrame containing all needed information for Z, A.

  • Z (INT) – Number of protons.

  • A (int) – Mass Number.

  • model (object) – Trained machine learning model.

  • model_type (str) – Type of ML model. Options include “tf”, “xgb”, or “scikit”.

  • scaler (object) – Trained scikit-learn normalizer/transformer.

  • to_scale (list) – List of features that are to be subject to transformation by the scaler.

  • log_sqrt (bool, optional) – If True, it assumes the models where trained on Level Energy data with SQRT applied. Defaults to False.

  • log (bool, optional) – If True, it assumes the models where trained on Level Energy data with LOG applied. Defaults to False.

  • plot (bool, optional) – If True, the ML predictions will be plotted along the true known values. Defaults to False.

  • save (bool, optional) – If True, the rendered figure will be saved. Defaults to False.

  • save_dir (str, optional) – Path-like string indicating directory where the figure will be saved. Defaults to “”.

Returns

New DataFrame with ML predictions.

Return type

DataFrame

nucml.ensdf.data_utilities.make_predictions_w_levels(df, Z, A, num_levels, model, model_type, scaler, to_scale, inv_transform=False, log_sqrt=False, log=False, plot=False, save=False, save_dir='')[source]

Returns a set of ML predictions up to num_levels.

Parameters
  • df (DataFrame) – DataFrame containing all needed information for Z, A.

  • Z (INT) – Number of protons.

  • A (int) – Mass Number.

  • num_levels (int) – Upper level number for which to predict the level energy.

  • model (object) – Trained machine learning model.

  • model_type (str) – Type of ML model. Options include “tf”, “xgb”, or “scikit”.

  • scaler (object) – Trained scikit-learn normalizer/transformer.

  • to_scale (list) – List of features that are to be subject to transformation by the scaler.

  • inv_transform (bool, optional) – If True, the returned DataFrame will be in its original ranges. Defaults to False.

  • log_sqrt (bool, optional) – If True, it assumes the models where trained on Level Energy data with SQRT applied. Defaults to False.

  • log (bool, optional) – If True, it assumes the models where trained on Level Energy data with LOG applied. Defaults to False.

  • plot (bool, optional) – If True, the ML predictions will be plotted along the true known values. Defaults to False.

  • save (bool, optional) – If True, the rendered figure will be saved. Defaults to False.

  • save_dir (str, optional) – Path-like string indicating directory where the figure will be saved. Defaults to “”.

Returns

New DataFrame with ML predictions.

Return type

DataFrame

nucml.ensdf.data_utilities.make_predictions_w_levels_nodata(df, num_levels, model, model_type, scaler, to_scale, inv_transform=False, log_sqrt=False, log=False, plot=False, save=False, save_dir='')[source]

Returns a set of ML predictions up to num_levels for isotopes with no known nuclear structure data.

Parameters
  • df (DataFrame) – DataFrame containing all needed information for a given Z, A. Just one row is sufficient.

  • num_levels (int) – Upper level number for which to predict the level energy.

  • model (object) – Trained machine learning model.

  • model_type (str) – Type of ML model. Options include “tf”, “xgb”, or “scikit”.

  • scaler (object) – Trained scikit-learn normalizer/transformer.

  • to_scale (list) – List of features that are to be subject to transformation by the scaler.

  • inv_transform (bool, optional) – If True, the returned DataFrame will be in its original ranges. Defaults to False.

  • log_sqrt (bool, optional) – If True, it assumes the models where trained on Level Energy data with SQRT applied. Defaults to False.

  • log (bool, optional) – If True, it assumes the models where trained on Level Energy data with LOG applied. Defaults to False.

  • plot (bool, optional) – If True, the ML predictions will be plotted along the true known values. Defaults to False.

  • save (bool, optional) – If True, the rendered figure will be saved. Defaults to False.

  • save_dir (str, optional) – Path-like string indicating directory where the figure will be saved. Defaults to “”.

Returns

New DataFrame with ML predictions.

Return type

DataFrame

nucml.ensdf.data_utilities.predicting_nuclear_xs_v2(df, Z, A, model, scaler, to_scale, num_levels=100, log_sqrt=False, model_type=None, save=False, plot=False, save_dir='', inv_trans=False)[source]

Plots and returns a set of ML predictions at all known levels and up to num_levels in cases where the known levels are fewer.

Parameters
  • df (DataFrame) – DataFrame containing all needed information for Z, A.

  • Z (INT) – Number of protons.

  • A (int) – Mass Number.

  • model (object) – Trained machine learning model.

  • scaler (object) – Trained scikit-learn normalizer/transformer.

  • to_scale (list) – List of features that are to be subject to transformation by the scaler.

  • num_levels (int) – Upper level number for which to predict the level energy. Defaults to 100.

  • log_sqrt (bool, optional) – If True, it assumes the models where trained on Level Energy data with SQRT applied. Defaults to False.

  • model_type (str) – Type of ML model. Options include “tf”, “xgb”, or “scikit”/None. Defaults to None.

  • save (bool, optional) – If True, the rendered figure will be saved. Defaults to False.

  • plot (bool, optional) – If True, the ML predictions will be plotted along the true known values. Defaults to False.

  • save_dir (str, optional) – Path-like string indicating directory where the figure will be saved. Defaults to “”.

  • inv_transform (bool, optional) – If True, the returned DataFrame will be in its original ranges. Defaults to False.

Returns

New DataFrame with ML predictions.

Return type

DataFrame

nucml.ensdf.parsing module

nucml.ensdf.parsing.generate_cutoff_ensdf(ensdf_directory, elemental_directory, ripl_directory=None, saving_directory=None)[source]

Uses the RIPL level parameters cut-off information to generate a new ENSDF CSV file. It removes all nuclear level information above the given parameters for each isotope by using the CSV file created using the get_level_parameters() function.

Parameters
  • ensdf_directory (str) – Path-like string indicating the directory where the ensdf.csv file is stored.

  • elemental_directory (str) – Path-like string indicating the the Elemental_ENSDF_no_Header_F directory.

  • ripl_directory (str, optional) – Path-like string indicating the directory where the ripl_cut_off_energies.csv file is stored. If None, it is assumed that the file is located in the ensdf_directory. Defaults to None.

  • saving_directory (str, optional) – The resulting file will be saved in this directory. If None, the saving_directory will be set to the ensdf_directory. Defaults to None.

Returns

None

nucml.ensdf.parsing.generate_elemental_ensdf(dat_list, header_directory, saving_directory)[source]

Generates a new RIPL/ENSDF file for each element. The original files are organized by proton number. This function is useful to organize by element instead. Three directories are created: one for raw elemental files with headers, another one without headers, and a third one which is a formatted version of the second one.

Note: This script will delete all existing header files and create them again if run by a second time using the same directories.

Parameters
  • dat_list (list) – List containing the paths to all .dat files to be processed. Usually generated using the get_ripl_dat_paths() function.

  • header_directory (str) – Path-like string where the all_ensdf_headers_formatted.csv file is located. This file is generated using the get_headers() function.

  • saving_directory (str) – Path-like string where the new directories and ENSDF files will be stored.

Returns

None

nucml.ensdf.parsing.generate_ensdf_csv(header_directory, elemental_directory, saving_directory=None)[source]

Generates a single CSV file containing information from all isotopes.

Parameters
  • header_directory (str) – Path-like string where the all_ensdf_headers_formatted.csv file is located. This file is generated using the get_headers() function.

  • elemental_directory (str) – Path-like string to directory where the Elemental_ENSDF_no_Header_F directory is located. This directory is first created using the generate_elemental_ensdf() function.

  • saving_directory (str) – Path-like string where the new ENSDF CSV file will be stored. If None, it will be saved in the header_directory.

Returns

None

nucml.ensdf.parsing.get_headers(dat_list, saving_directory)[source]

Retrieves the avaliable raw headers for all .dat files.

Parameters
  • dat_list (list) – List containing the paths to all .dat files to be processed. Usually generated using the get_ripl_dat_paths() function.

  • saving_directory (str) – Path-like string to directory for saving the header file.

Returns

None

nucml.ensdf.parsing.get_level_parameters(level_params_directory, saving_directory=None)[source]

Converts the levels-param.data file from RIPL into a usable CSV file.

Parameters
  • level_params_directory (str) – Path-like string pointing towards the directory where the levels-param.data file is located.

  • saving_directory (str) – Path-like string pointing towards the directory where the resulting CSV will be stored. If None, it will be stored in the level_params_directory.

Returns

None

nucml.ensdf.parsing.get_ripl_dat_paths(dat_directory)[source]

Searches directory for RIPL .dat files and returns a list of relative paths for each one.

Parameters

dat_directory (str) – Path to the RIPL directory containing all dat files.

Returns

Contains relative path to each .dat file found.

Return type

list

nucml.ensdf.parsing.get_stable_states(dat_list, header_directory, saving_directory=None)[source]

Generates a CSV file containing only stable state information for each isotope.

Parameters
  • dat_list (list) – List containing the paths to all .dat files to be processed. Usually generated using the get_ripl_dat_paths() function.

  • header_directory (str) – Path-like string where the all_ensdf_headers_formatted.csv file is located. This file is generated using the get_headers() function.

  • saving_directory (str) – Path-like string where the resulting CSV file will be saved. If None, files will be stored in the same directory as the header_directory.

Returns

None

nucml.ensdf.plot module

nucml.ensdf.plot.level_density(df, Z, A, df2=Empty DataFrame Columns: [] Index: [], save=False, save_dir=None, label1='Adopted', label2='Cut-Off')[source]

Plots level density for a given isotope.

Parameters
  • df (DataFrame) – DataFrame containing the discrete levels for a given isotope.

  • Z (int) – Number of protons.

  • A (int) – Mass number.

  • df2 (DataFrame, optional) – If passed, this will be plotted alongside the main dataframe. Useful for plotting all known levels along the RIPL-cutoff DataFrame. Defaults to an empty DataFrame.

  • save (bool, optional) – If True, the image will be saved. Defaults to False.

  • save_dir (str, optional) – Path-like string where the figure will be stored. Defaults to None.

  • label1 (str, optional) – Label for the first dataframe line in the plot legend. Defaults to “Adopted”.

  • label2 (str, optional) – Label for the second dataframe line in the plot legend. Defaults to “Cut-Off”.

Returns

None

nucml.ensdf.plot.level_density_ml(ensdf_df, predictions_df, log_sqrt=False, log=False, save=False, save_dir=None)[source]

Plots the level density based on all known levels and the predicted LD based on model predictions.

Parameters
  • ensdf_df (DataFrame) – The original DataFrame containing all known levels. It can also be the ENSDF data filtered using the RIPLE cut-off parameters.

  • predictions_df (DataFrame) – A DataFrame containing the predictions by any ML model. It must contain both a “Level_Number”, and “Energy” feature.

  • log_sqrt (bool, optional) – If True, it assumes both DataFrames “Energy” feature are in sqrt(Energy). Defaults to False.

  • log (bool, optional) – If True, it assumes that both DataFrame’s “Energy” and “Data” features are already in log form. Defaults to False.

  • save (bool, optional) – If True, the resulting plot will be saved. Defaults to False.

  • save_dir (str, optional) – Path-like string pointing towards a directory where the image will be saved. Defaults to None.

Returns

None

nucml.ensdf.plot.levels_axh(protons, mass_number, ensdf_df, save=False, save_dir=None)[source]

Experimental. Plots all levels as horizontal lines in a vertical plot.

Parameters
  • protons (int) – Number of Protons.

  • mass_number (int) – Mass Number.

  • ensdf_df (DataFrame) – DataFrame containing the original levles for all isotopes.

  • save (bool, optional) – If True, the image will be saved. Defaults to False.

  • save_dir (str, optional) – Path-like string where the generated image will be saved. Defaults to None.

Returns

None

Module contents