nucml.ace package

Submodules

nucml.ace.data_utilities module

nucml.ace.data_utilities.convert_dos_to_unix(file_path)[source]

Converts a given file from DOS to UNIX.

Parameters

file_path (str) – Path to file to convert.

Returns

None

nucml.ace.data_utilities.copy_ace_w_name(ZAAA, saving_dir)[source]

Copies an ACE file from the configured ace directory.

Parameters
  • ZAAA (str) – Isotope ace file to copy (i.e. 92233).

  • saving_dir (str) – Path indicating the directory where the ACE file will be copy to.

Returns

None

nucml.ace.data_utilities.copy_benchmark_files(benchmark_name, saving_dir)[source]

Copies all files for a given benchmark from the benchmark repository to a given directory.

Parameters
  • benchmark_name (str) – Benchmark name. Check repository for valid names.

  • saving_dir (str) – Path-like string where the new benchmark files will be saved to.

Returns

None

nucml.ace.data_utilities.create_mt2_mt3_mt101(rx_grid, mt_array)[source]

Helps with the creation of MT3 and MT101 which requires them to be the summation of other MT reactions.

TODO: CHOOSE WHICH ONE TO ADJUST BASED ON EXPERIMENTAL DATAPOINTS (MT3 OR MT102)

Parameters
  • rx_grid (DataFrame) – DataFrame containing the grid by which to adjust the MT. This is usually the energy grid.

  • mt_array (np.array) – Array containing the MT values avaliable.

Returns

Resulting dataframe containing the adjusted MT values.

Return type

DataFrame

nucml.ace.data_utilities.create_new_ace(xss, ZZAAA, saving_dir='')[source]

Generates a new .ACE file ready to be used in transport codes. Everything is encoded in the XSS array. The header is to be kept the same since different energy arrays are not supported.

Parameters
  • xss (np.array) – Modified XSS array.

  • ZZAAA (int) – ZZAAA formatted isotope for which to create modified .ACE file.

  • saving_dir (str) – Path-like string on where to save the created .ACE file.

Returns

None

nucml.ace.data_utilities.create_new_ace_w_df(ZZAAA, path_to_ml_csv, saving_dir=None, ignore_basename=False)[source]

Creates new ACE file from a given processed ML generated CSV file.

Parameters
  • ZZAAA (str) – [description]

  • path_to_ml_csv (str) – Path-like string pointing towards the ML and ACE processed CSV.

  • saving_dir (str, optional) – Path where the newly generated ACE file will be saved. Defaults to None.

  • ignore_basename (bool, optional) – TODO. Defaults to False.

Returns

None

nucml.ace.data_utilities.enforce_unitarity(ml_ace_df)[source]

Creates MT2 XS and adjusts MT1 accordingly.

Calculates MT2 by substracting MT3 from MT1. If MT2 is negative: - Replace negatives with NaN - Interpolates from closests values - Adds back amount to MT1 to conserve XS.

TODO: INTRODUCE THIS FUNCTION TO THE get_final_ml_ace_df()

Parameters

ml_ace_df (DataFram) – DataFrame containing the original MT1, MT2, and MT3.

Returns

returns an adjusted dataframe.

Return type

DataFrame

nucml.ace.data_utilities.fill_ml_xs(MT, ml_xs, ace_xs, use_peaks=True)[source]

Utility function used by the get_hybrid_ml_xs() function to fill in the head and tail of a set of cross section values using the hybrid approach.

Parameters
  • MT (int) – ENDF MT reaction code for the reaction channel to adjust.

  • ml_xs (DataFrame) – The DataFrame containing the cross section values for the MT reaction to adjust.

  • ace_xs (np.array) – Array containing the ENDF cross sections that will be used to fill in the ml_xs DataFrame.

Returns

Adjusted ml_xs DataFrame.

Return type

DataFrame

nucml.ace.data_utilities.gather_benchmark_results(searching_directory)[source]

Gathers all benchmark results from the resulting .mat files in the searching_directory and all subdirectories.

Parameters

searching_directory (str) – Path to directory to search for .mat files.

Returns

Contains results for all found .mat files.

Return type

DataFrame

nucml.ace.data_utilities.generate_bench_ml_xs(df, models_df, bench_name, to_scale, raw_saving_dir, reset=False, template_dir='C:/Users/Pedro/Desktop/ML_Nuclear_Data/Benchmarks/inputs/templates', comp_threshold=0.1, reduce_ace_size=True)[source]
nucml.ace.data_utilities.generate_serpent_bash(searching_directory, script_name, benchmark='all', omp=10)[source]

Gathers the path to all “input” benchmark files and returns a single bash script to run all Serpent simulations and convert the resulting matlab file into .mat files for later reading.

Parameters

searching_directory (str) – Top level directory that will be searched for “input” files.

Returns

None

nucml.ace.data_utilities.generate_sss_xsdata(saving_dir)[source]

Copies the .xsdata file to a given directory and configures it to match the paths.

Parameters

saving_dir (str) – Path-like directory where the .xsdata file will be copied to.

Returns

None

nucml.ace.data_utilities.get_basic_mts(xss, pointer_dict)[source]

Returns a dcitionary containing the cross section values for MT1, MT 101, MT2, and MT3. These are not part of the MT array. The Cross Section values start inmediatly after the energy points. The corresponding energy grid is the entire energy grid.

Parameters
  • xss (np.array) – The XSS array obtained through the get_nxs_jxs_xss() function.

  • pointers_dict (dict) – Pointers dictionary obtained through the get_pointers() function.

Returns

Dicitonary containing the cross section values for the basic reaction types.

Return type

dict

nucml.ace.data_utilities.get_energies(isotope, temp='03c', ev=False, log=False)[source]

Retrieves the energy array from a given isotope ENDF .ACE file.

Parameters
  • isotope (str) – ZZAAA formatted isotope.

  • temp (str, optional) – Extension of ACE file to retrieve energies from. Defaults to “03c”.

  • ev (bool, optional) – If True, energies are converted to eV from MeV. Defaults to False.

  • log (bool, optional) – If True, the log is taken before returning the array. Defaults to False.

Returns

Energy grid numpy array.

Return type

np.array

nucml.ace.data_utilities.get_energy_array(xss, pointers_dict)[source]

Returns the energy grid given the XSS array and the pointers dictionary.

Parameters
  • xss (np.array) – The XSS array obtained through the get_nxs_jxs_xss() function.

  • pointers_dict (dict) – Pointers dictionary obtained through the get_pointers() function.

Returns

Numpy array containing the energy grid values.

Return type

np.array

nucml.ace.data_utilities.get_final_ml_ace_df(energies, mt_array, mt_xs_pointers_array, pointers, jxs_df, xss, ml_df, ml_list=['MT_1', 'MT_2', 'MT_3', 'MT_18', 'MT_101', 'MT_102'])[source]

Given a set of ML generated XS (adjusted), this function allows to fill in other reaction channels not included by the ML predictions. This is useful since for some calculations some MT reactions are not required but are still present in the ACE files. This allows to preserve the ACE file values and structure.

For MT3 the ML generated cross sections are adjusted so that conservation rules are not broken. Same for MT101. All values will be at the energy grid specified by the energies array.

Note: MT2 is not calculated here.

TODO: DEAL WITH MT3 BETTER IN CASE IT IS GENERATED BY ML, WHAT ELSE TO ADJUST

Parameters
  • energies (np.array) – Array containing the energy values at which the ML generated values are created.

  • mt_array (np.array) – Array containing all mt reactions avaliable in ACE.

  • mt_xs_pointers_array (np.array) – Pointers for every reaction in the MT array in the XSS array.

  • xs_table_pointer (int) – Index of xxs at which the XS values start.

  • jxs_df (DataFrame) – The DataFrame containing the JXS table.

  • xss (np.array) – Array containing all info for a specific ace file.

  • ml_df (DataFrame) – DataFrame containing the ML generated cross sections.

  • ml_list (list) – List containing the ML generated column names that should not be modified at any point.

Returns

DataFrame containing the resulting cross sections from both ML and ACE.

Return type

DataFrame

nucml.ace.data_utilities.get_hybrid_ml_xs(ml_df, basic_mt_dict, mt_array, mt_xs_pointers_array, pointers, jxs_df, xss, use_peaks=True)[source]

Substitutes the ACE MT values in a machine learning generate dataframe containing a set of reaction channels. For MT1, MT2, and MT3 we fix the 1/v and tail region of each cross section. ML models like KNN and DT are coarse and sometimes unable to accuratly keep predicting a given trend. For this we:

Parameters
  • ml_df (DataFrame) – Contains the ML generated predictions under each columned named “MT_MT”.

  • basic_mt_dict (DICT) – A dicitonary containing MT1, MT2, MT3, and MT101 ({“mt1”:values, “mt2”:…}).

  • mt_array (np.array) – Contains the mt reactions avaliable in the .ace file.

  • mt_xs_pointers_array (np.array) – Contains the mt XS pointers in the xss array.

  • xs_table_pointer (int) – Index at which XS’s start in the xss array.

  • jxs_df (DataFrame) – The DataFrame obtained using the get_nxs_jxs_xss() function.

  • xss (np.array) – Array containing all information in the .ace file.

Returns

Merged DataFrame containing all ML and ACE reaction values.

Return type

DataFrame

nucml.ace.data_utilities.get_jxs_dictionary(jxs_df)[source]

Given the extracted JXS DataFrame, this function will return a key:value dictionary of the values in the JXS in accordance to the ACE formatting documentation. JXS values are mostly indexes in the XSS array to indicate the beggining of a data type.

Parameters

jxs_df (DataFrame) – The JXS DataFrame extracted using the get_nxs_jxs_xss() function.

Returns

Dictionary containing the JXS results.

Return type

dict

nucml.ace.data_utilities.get_mt_array(xss, pointer_dict)[source]

Returns the avaliable MT reactions as a numpy array given the XSS and pointers dictionary.

Parameters
  • xss (np.array) – The XSS array obtained through the get_nxs_jxs_xss() function.

  • pointers_dict (dict) – Pointers dictionary obtained through the get_pointers() function.

Returns

Numpy array containing the avaliable MT values.

Return type

np.array

nucml.ace.data_utilities.get_mt_array_w_pointers(mt_array, mt_xs_pointers_array)[source]

Returns a dictionary with the avaliable MT reactions as keys and the cross section pointers as values.

Parameters
  • mt_array (np.array) – Array containing the MT reactions. Usually obtained by the get_mt_array() function.

  • mt_xs_pointers_array (np.array) – Array containing the XS pointers obtained through the get_mt_xs_pointers_array() function.

Returns

Dictionary containing the mt_array:xs_pointer key:value pairs.

Return type

dict

nucml.ace.data_utilities.get_mt_xs_pointers_array(xss, pointer_dict)[source]

Returns the XS pointers for each MT reaction in the MT array in the form of an equal length array.

Parameters
  • xss (np.array) – The XSS array obtained through the get_nxs_jxs_xss() function.

  • pointers_dict (dict) – Pointers dictionary obtained through the get_pointers() function.

Returns

Numpy array containing the XS pointers grid values.

Return type

np.array

nucml.ace.data_utilities.get_nxs_dictionary(nxs_df)[source]

Given the extracted NSX DataFrame, this function will transform it into a dictionary. The keys are XSS_length, ZZAAA, Num_Energies, “NTR”, “NR”, “NTRP”, “NPCR”, “S”, “Z”, and “A”. For a definition, check out the ACE formatting documentation.

Parameters

nxs_df (DataFrame) – The NSX DataFrame extracted using the get_nxs_jxs_xss() function.

Returns

dictionary containing the NSX results.

Return type

dict

nucml.ace.data_utilities.get_nxs_jxs_xss(isotope, temp='03c', custom_path=None, reduced=False)[source]

Retrieves the NSX, JXS, and XSS tables for a given isotope at a given temperature The JSX DataFrame indicates the indices to the XSS where different pieces of data begin. The XSS table contains the actual data needed by many functions of the ACE utilities.

Parameters
  • isotope (str) – Isotope in ZZAAA format.

  • temp (str, optional) – Temperature in ace format (i.e. 03c means 300C). Defaults to “03c”.

  • custom_path (str, optional) – File-path to a new ACE file not stored in the configured ACE directory. Defaults to None.

Returns

tuple containing:

nxs (DataFrame) jxs (DataFrame) xss (np.array)

Return type

(tuple)

nucml.ace.data_utilities.get_pointers(nxs, jxs)[source]

Gets general information from NXS and JXS needed to start manipulating cross sections. This includes several pointers for Energy, MT Array, LSIG, SIG, and Fission.

Parameters
  • nxs (dict) – Dictionary obtained using the get_nxs_dictionary().

  • jxs (dict) – Dictionary obtained using the get_jxs_dictionary().

Returns

Contains several pointers to different data types in the xss array.

Return type

dict

nucml.ace.data_utilities.get_to_skip_lines(isotope, temp='03c')[source]

This utility returns the path to the corresponding ACE file for a given isotope, returns the number of lines to skip to get to the data block belonging to the given energy, and the number of lines corresponding to that block.

Parameters
  • isotope (str) – Element in ZZAAA format (i.e. 92233, 6012).

  • temp (str, optional) – Temperature in ACE format (i.e. 03c means 300C). Defaults to “03c”.

Returns

tuple containing:

path (str): Path to the queried isotope in the ACE directory. to_skip (int): Number of lines to skip in the original file until the wanted temperature begins. lines (int): Number of total lines covering the queried isotope at a given temperature.

Return type

(tuple)

Raises

FileNotFoundError – If a given isotope file does not exists, an error will be raised.

nucml.ace.data_utilities.get_xs_for_mt(MT, mt_array, mt_xs_pointers_array, jxs_df, xss, pointers)[source]

Returns cross section values, the corresponding energy points, and the indexes corresponding the starting and end point in the xss array for a given reaction channel as a dictionary.

Parameters
  • MT (int) – MT number for the reaction to extract.

  • mt_array (np.array) – Array containing the MT reactions. Usually obtained by the get_mt_array() function.

  • mt_xs_pointers_array (np.array) – Array containing the XS pointers obtained through the get_mt_xs_pointers_array() function.

  • jxs_df (DataFrame) – DataFrame containing the JXS values.

  • xss (np.array) – The XSS array obtained through the get_nxs_jxs_xss() function.

  • verbose (bool, optional) – To or not to print statements througout the process. Defaults to True.

Returns

Contains cross section values and metadata for a given reaction channel.

Return type

dict

nucml.ace.data_utilities.modify_xss_w_df(xss, ml_ace_df, mt_array, mt_xs_pointers_array, jxs_df, pointers)[source]

Returns a modified XSS array. It substitutes the MT reactions in ml_list in the original ACE xss array. The resulting xss can then be used to create a new .ace file for use in monte carlo or deterministic codes.

Parameters
  • ml_list (list) – List of mt reactions to substitute in the original ACE xss.

  • xss (np.array) – Original xss .ace array.

  • ml_ace_df (DataFrame) – DataFrame containing all modified and unmodified MT values.

  • nes (int) – Number of energy points in the original .ace file.

  • mt_array (np.array) – Array containing the avaliable mt values in the .ace file.

  • mt_xs_pointers_array (np.array) – Indexes where the XS starts in the xss array for each MT value.

  • xs_table_pointer (int) – Index at which the XS values begin.

  • jxs_df (DataFrame) – JXS DataFrame from the .ACE file.

Returns

Modified xss array.

Return type

np.array

nucml.ace.data_utilities.parsing_datatypes(x)[source]

Utility function to correctly format numbers before writing them to new .ACE files.

Parameters

x (float) – Number to format.

Returns

Formatted value.

Return type

float

nucml.ace.data_utilities.reduce_ace_filesize(directory, keep='03c')[source]

Utility function to reduce the size of ACE files. Useful to remove all other information other than the section of interest (i.e. .03c).

Parameters
  • directory (str) – Path to directory where all ACE files will be searched and processed.

  • keep (str, optional) – Temperature to keep. Must not include the dot. Defaults to “03c”.

Returns

None

nucml.ace.plot module

nucml.ace.plot.dt_dual_keff_plot(dt_df, train_mae, val_mae, hyperparameter, keff_metric, save=False, saving_dir='')[source]

Creates a two figure plot containing both the performance metric (i.e. MAE) and the criticality calculation (i.e K-eff) vs two model hyperparameters. These decision tree hyperparameteres are usually the Max Depth and the Minimum Numbers for Split.

Parameters
  • dt_df (DataFrame) – DataFrame containing all trained models performance in criticality benchmarks.

  • train_mae (str) – Feature name for the performance metric to plot.

  • val_mae (str) – Feature name for the validation performance metric..

  • hyperparameter (str) – Feature name for the hyperparameter to plot.

  • keff_metric (str) – Feature name for the multiplication factor to plot.

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

  • saving_dir (str, optional) – Directory where the figure will be saved. Defaults to “”.

Returns

None

nucml.ace.plot.dt_keff_plot(dt_df, mae, hyperparameter, keff_metric, save=False, saving_dir='')[source]

Creates a figure containing both the performance metric (i.e. MAE) and the criticality calculation (i.e K-eff) vs a single model hyperparameters. The decision tree hyperparameteres are usually the Max Depth and the Minimum Numbers for Split.

Parameters
  • dt_df (DataFrame) – DataFrame containing all trained models performance in criticality benchmarks.

  • mae (str) – Feature name for the performance metric to plot (i.e. Train MAE, Val MAE).

  • hyperparameter (str) – Feature name for the main hyperparameter to plot.

  • keff_metric (str) – Feature name for the multiplication factor metric.

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

  • saving_dir (str, optional) – Directory where the figure will be saved. Defaults to “”.

Returns

None

nucml.ace.plot.knn_dual_plot(knn_df, hyperparameter, train_mae, val_mae, keff_metric, save=False, saving_dir='')[source]

Creates a two figure plot containing both performance metrics (i.e. Train MAE and Val MAE), the criticality calculation (i.e K-eff) and a model hyperparameter.

Parameters
  • knn_df (DataFrame) – DataFrame containing all trained models performance in criticality benchmarks.

  • hyperparameter (str) – Feature name for the hyperparameter to plot.

  • train_mae (str) – Feature name for the performance metric to plot.

  • val_mae (str) – Feature name for the validation performance metric.

  • keff_metric (str) – Feature name for the multiplication factor to plot.

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

  • saving_dir (str, optional) – Directory where the figure will be saved. Defaults to “”.

Returns

None

nucml.ace.plot.knn_keff_plot(knn_df, hyperparameter, mae, keff_metric, save=False, saving_dir='')[source]

Creates a figure containing a single performance metric of choice (i.e. MAE) and the criticality calculation results (i.e K-eff) vs a single model hyperparameters.

Parameters
  • knn_df (DataFrame) – DataFrame containing all trained models performance in criticality benchmarks.

  • hyperparameter (str) – Feature name for the main hyperparameter to plot.

  • mae (str) – Feature name for the performance metric to plot (i.e. Train MAE, Val MAE).

  • keff_metric (str) – Feature name for the multiplication factor metric.

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

  • saving_dir (str, optional) – Directory where the figure will be saved. Defaults to “”.

Returns

None

nucml.ace.plotting_utilities module

nucml.ace.plotting_utilities.dt_dual_keff_plot(dt_df, train_mae, main_metric2, metric1, metric2, save=False, saving_dir='')[source]
nucml.ace.plotting_utilities.dt_keff_plot(dt_df, val_mae, hyperparameter, keff_metric, save=False, saving_dir='')[source]
nucml.ace.plotting_utilities.knn_dual_plot(dt_df, main_metric, metric0, metric1, keff_metric, save=False, saving_dir='')[source]
nucml.ace.plotting_utilities.knn_keff_plot(knn_df, k, val_mae, keff_metric, save=False, saving_dir='')[source]

Module contents