metbit.calibrate
NMR and preprocessing module in metbit 8.7.7.
import metbit.calibrateFunctions
calibrate(X, ppm, calib_type='tsp', custom_range=None, custom_target=None)
Calibrate chemical shifts in NMR spectra using known reference peaks.
Parameters: X (np.ndarray or pd.DataFrame): NMR data matrix (rows: spectra, columns: PPM positions). ppm (np.ndarray): 1D array of chemical shift values (same order as X columns). calib_type (str): One of 'tsp', 'acetate', 'glucose', 'alanine', 'formate', or 'custom'. custom_range (tuple[float, float] | None): For 'custom', the (start_ppm, end_ppm) region to search for the peak. custom_target (float | None): For 'custom', the target ppm to calibrate the detected peak to (e.g., 0.91).
Returns: pd.DataFrame: Calibrated NMR data matrix with same shape and columns as input.
Notes: - For 'glucose' and 'alanine', the function attempts to use the top-2 peaks' mean ppm in the range, otherwise falls back to the highest peak. - For 'custom', both `custom_range` and `custom_target` should be provided, e.g.: calibrate(X, ppm, calib_type='custom', custom_range=(0.89, 1.20), custom_target=0.91)