metbit.nmr_preprocess
NMR and preprocessing module in metbit 7.0.6.
import metbit.nmr_preprocessClasses
nmr_preprocessing
nmr_preprocessing is a class for processing NMR data.
Parameters: data_path (str): Path to the directory containing the Bruker formatted data. bin_size (float): Bin size for the PPM scale. auto_phasing (bool): Perform automatic phase correction. phase_fn (str): Phase correction function ("acme", "peak_minima"). baseline_correction (bool): Perform baseline correction ('linear', 'constant', 'median', 'solvent filter'). calib_type (str): Calibration type ('tsp', 'glucose', 'alanine').
Returns:
nmr_preprocessingAn instance of the nmr_preprocessing class.Example: # Create an instance of the nmr_preprocessing class nmr_data = nmr_preprocessing(data_path='path/to/data', bin_size=0.0003, auto_phasing=True, phase_fn='peak_minima', baseline_correction=True, calibration=True, calib_type='tsp')
# Get the processed NMR data nmr_data.get_data()
# Get the PPM scale nmr_data.get_ppm()
# Get the metadata nmr_data.get_metadata()
# Get the phase correction nmr_data.get_phase()
Methods
__init__(self, data_path: str, bin_size: float=0.0003, auto_phasing: bool=True, phase_fn: str='peak_minima', baseline_correction: bool=True, baseline_type: str='linear', calibration: bool=True, calib_type: str='tsp')
get_data(self)
get_ppm(self)
get_metadata(self)
get_phase(self)
Functions
read_fid(data_path: str)
Read in NMR data from a Bruker FID file.
Parameters: data_path (str): Path to the Bruker FID file.
Returns:
tupleTuple containing the data dictionary and the data array.remove_digital_filter(dic, data)
Remove the digital filter from NMR data.
Parameters: dic (dict): Data dictionary. data (np.ndarray): NMR data array.
Returns: np.ndarray: NMR data array with digital filter removed.
generate_ppm_scale(dic, data)
Generate a PPM scale for NMR data.
Parameters: dic (dict): Data dictionary. bin_size (float): Bin size for the PPM scale.
Returns: np.ndarray: PPM scale array.
phasing(data, index, auto=True, fn='peak_minima', p0=0.0, p1=0.0)
Apply phase correction to NMR data.
Parameters: data (np.ndarray): NMR data array. fn (str): Phase correction function ('peak_minima', 'peak_maxima', 'min_imag', 'max_imag'). auto (bool): Perform automatic phase correction.
Returns: np.ndarray: Phased NMR data array.
calibrate(X, ppm, calib_type='tsp', custom_range=None)
Calibrate chemical shifts in NMR spectra.
Parameters: X (np.ndarray): 2D array, NMR data (rows: spectra, columns: PPM positions). ppm (np.ndarray): 1D array, chemical shift values aligned with columns of X. calib_type (str): Calibration type ('tsp', 'glucose', 'alanine'). custom_range (tuple): PPM range (start, end) for custom calibration.
Returns: np.ndarray: Calibrated NMR data matrix.
Example: # Ensure X is a 2D numpy array X = data.to_numpy()
# Ensure ppm is a 1D numpy array ppm = data.columns[:-1].astype(float).to_numpy()
# Call the calibrate function calibrated_X = calibrate(X=X, ppm=ppm, calib_type='tsp', custom_range=None)