openspi.core

Functions

process_csv(file_path, range_min, range_max)

Processes .csv files to match the required format for OpenSpecy processing.

process_csv_folder(folder_path, range_min, range_max)

Processes a batch of .csv files in the given folder by calling

r_script(file_path, range_min, range_max[, ...])

Processes spectra through the OpenSpecy R package and returns a dataframe

sort_export(df, excel_path, top_n[, nrel])

Sorts the dataframe exported from the R script and rearranges it into a

openspi_main(source_path, range_min, range_max[, ...])

A complete function for spectral pre-processing, processing through the

Module Contents

openspi.core.process_csv(file_path, range_min, range_max)

Processes .csv files to match the required format for OpenSpecy processing. (The required format is two columns named 'wavenumber' and 'intensity')

Parameters:
  • file_path (str) – The complete path to the .csv file to be processed. This function only accepts .csv files, and any other file types will cause the function to stop.

  • range_min (int) – The minimum wavenumber of the desired spectral range. Note that this value can be greater than the actual minimum if cropping is desired.

  • range_max (int) – The maximum wavenumber of the desired spectral range. Note that this value can be less than the actual maximum if cropping is desired.

Returns:

file_path – The complete path to the processed .csv file.

Return type:

str

openspi.core.process_csv_folder(folder_path, range_min, range_max)

Processes a batch of .csv files in the given folder by calling process_csv, then zips the processed files to send to OpenSpecy.

Parameters:
  • folder_path (str) – The complete path to the folder containing .csv files to be processed. This function only accepts .csv files, and any other file types will cause the function to stop.

  • range_min (int) – The minimum wavenumber of the desired spectral range. Note that this value can be greater than the actual minimum if cropping is desired.

  • range_max (int) – The maximum wavenumber of the desired spectral range. Note that this value can be less than the actual maximum if cropping is desired.

Returns:

zipped_file_path – The complete path to a zipped folder containing the processed .csv files. This will be located in the same directory as the original folder path.

Return type:

str

openspi.core.r_script(file_path, range_min, range_max, adj_intens: bool = False, adj_intens_type: str = 'none', subtract_baseline: bool = False, top_n: int = 5)

Processes spectra through the OpenSpecy R package and returns a dataframe with the library matches and other data https://github.com/wincowgerDEV/OpenSpecy-package

Parameters:
  • file_path (str) – Path to the zipped folder containing the processed .csv files OR the path to a single .csv file.

  • range_min (int) – The minimum wavenumber of the desired spectral range. Note that this value can be greater than the actual minimum if cropping is desired.

  • range_max (int) – The maximum wavenumber of the desired spectral range. Note that this value can be less than the actual maximum if cropping is desired.

  • top_n (int) – The top n highest matches desired. Recommended values: 1 <= n >= 10 (Not yet supported)

  • adj_intens (bool) – If True, the function will adjust the intensity of the spectra using the OpenSpecy package.

  • adj_intens_type (str) – The type of intensity adjustment to be made. Options are ‘none’, ‘transmittance’, or ‘absorbance’

  • subtract_baseline (bool) – If True, the function will subtract the baseline from the spectra using IModPolyFit from the OpenSpecy package.

Returns:

df_top_matches – A Pandas dataframe containing the library match data for the files.

Return type:

dataframe

openspi.core.sort_export(df, excel_path, top_n, nrel=False)

Sorts the dataframe exported from the R script and rearranges it into a more presentable format. Exports an Excel file.

Parameters:
  • df (df) – The dataframe exported from the R script.

  • excel_path (str) – The full path to an .xlsx file.

  • top_n (int) – The number of top matches for each file. Equal to top_n in openspi_main. Default is 5.

  • nrel (Bool) – Adds an extra row regarding first well information to the “Matches Checked sheet.”

Return type:

None.

openspi.core.openspi_main(source_path, range_min, range_max, export_xlsx=None, export_dir=None, nrel_version=False, adj_intens=False, adj_intens_type='none', subtr_baseline=False)

A complete function for spectral pre-processing, processing through the OpenSpecy library in R, and configuring/processing the outputted data into an Excel spreadsheet.

Parameters:
  • source_path (str) – The complete path to the folder containing .csv files to be processed OR the path to a single .csv file. This function only accepts .csv files, and any other file types will cause the function to stop.

  • range_min (int) – The minimum wavenumber of the desired spectral range. Note that this value can be greater than the actual minimum if cropping is desired.

  • range_max (int) – The maximum wavenumber of the desired spectral range. Note that this value can be less than the actual maximum if cropping is desired.

  • export_xlsx (str) – The desired name of the outputted .xlsx file. If the file name does not contain the file extention .xlsx, it will be added. Optional; if not specified, the outputted file will be named according to the source file/folder.

  • export_dir (str) – The desired location of the outputted .xlsx file. Optional; if not specified, the file will be saved in the parent directory of the source file/folder.

  • nrel_version (bool) – If True, the function will use the NREL version of OpenSpecy, which has two differences: 1) all .sp files present in the folder will be deleted, and 2) the outputted file will be named in a specific way according to the files contained within.

  • top_n (int) – The top n highest matches desired. Recommended values: 1 <= n >= 10. Not yet supported.

  • adj_intens (bool) – If True, the function will adjust the intensity of the spectra using the OpenSpecy package.

  • adj_intens_type (str) – The type of intensity adjustment to be made. Options are ‘none’, ‘transmittance’, or ‘absorbance’

  • subtr_baseline (bool) – If True, the function will subtract the baseline from the spectra using IModPolyFit from the OpenSpecy package.

Return type:

None.