Public API
Spectrum
Section titled “Spectrum”class Spectrum:NMR spectrum.
The recommended way of creating Spectrum instances from spectrum files
is by using the Spectrum.load() function. This automatically determines
the format of the spectrum and selects the correct SpectrumReader.
Example:
spectrum = Spectrum.load('./spectrum_file.ucsf')ndim: intNumber of dimensions of the spectrum.
nuclei
Section titled “nuclei”nuclei: tuple[str, ...]The type of nucleus (13C, 1H, etc.) associated with each axis.
data_source
Section titled “data_source”data_source: bioshift.spectra.spectrumdatasource.SpectrumDataSourceObject responsible for lazy-loading and parsing spectrum data.
transform
Section titled “transform”transform: bioshift.spectra.spectrumtransform.SpectrumTransformObject storing the transformation from array coordinate space to chemical shift space.
experiment
Section titled “experiment”experiment: bioshift.spectra.spectrum.NMRExperimentEnum value for the type of NMR experiment the spectrum is from (e.g., HSQC, HNCACB)
shape: numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[~_ScalarT]]Returns: Shape of the underlying data array.
array: numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[~_ScalarT]]Get the raw data of the spectrum as a numpy array.
@classmethoddef load(cls, path: str | os.PathLike) -> bioshift.spectra.spectrum.Spectrum:Create a spectrum from a path to a spectrum file. Automatically determines the file format and dispatches the correct spectrum reader. Currently spectra stored in .ucsf and .spc(.par) files are supported.
Arguments:
Section titled “Arguments:”- path: Path to the spectrum file.
Returns:
Section titled “Returns:”Spectrum object
intensity
Section titled “intensity”def intensity( self, shift: numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[~_ScalarT]] | tuple[numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[~_ScalarT]], ...]) -> numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[~_ScalarT]]:Evaluate the interpolated intensity at given chemical shift coords.
This method wraps scipy.interpolate.RegularGridInterpolator to interpolate
values from a regularly spaced ND grid (self.array) defined over axes
stored in self.transform.axes.
Arguments:
Section titled “Arguments:”- shift: Coordinates at which to evaluate
- the intensity.
- Accepts: - A NumPy array of shape (n_points, ndim), where each row is a point.
- A tuple of arrays (e.g., from
np.meshgrid) of equal shape, which will be stacked into coordinate points.
- A tuple of arrays (e.g., from
Returns:
Section titled “Returns:”Interpolated intensity values at the specified coordinates. If
shiftis a tuple of meshgrid arrays, the output shape matches the grid shape.
def slice(self, axis: int, z: float) -> bioshift.spectra.spectrum.Spectrum:Take a slice from the spectrum along the specified axis.
Arguments:
Section titled “Arguments:”- axis: The index of the axis perpendicular to the slice plane.
- z: The chemical shift of the plane along the specified axis.
Returns:
Section titled “Returns:”A new spectrum, with one fewer dimension, corresponding to the slice plane.
project
Section titled “project”def project(self, axis: int) -> bioshift.spectra.spectrum.Spectrum:Project the spectrum along one of its coordinate axes by taking the integral.
Arguments:
Section titled “Arguments:”- axis: The axis along which to project the spectrum.
Returns:
Section titled “Returns:”A new spectrum with one fewer dimension.
def blur(self, sigma: tuple[float]) -> bioshift.spectra.spectrum.Spectrum:Apply a gaussian blur to the spectrum.
Arguments:
Section titled “Arguments:”- sigma: The standard deviation of the gaussian kernel used for the blur.
Returns:
Section titled “Returns:”A new spectrum which has been blurred.
threshold
Section titled “threshold”def threshold( self, level: float, soft: bool = True) -> bioshift.spectra.spectrum.Spectrum:Apply a threshold to the spectrum.
Arguments:
Section titled “Arguments:”- level: The threshold level. All points with intensities below this value are set to zero.
- soft: If set to True, values above the threshold are shifted down by the threshold level,
- in order to keep the spectrum continuous.
Returns:
Section titled “Returns:”A new spectrum with all points below the threshold value set to zero.
normalize
Section titled “normalize”def normalize(self) -> bioshift.spectra.spectrum.Spectrum:Normalize the spectrum to have maximum 1.0.
Returns:
Section titled “Returns:”A new spectrum with all values divided by the maximum of the original.
transpose
Section titled “transpose”def transpose( self, axes: tuple[int, ...] | None = None) -> bioshift.spectra.spectrum.Spectrum:Transpose the spectrum, swapping the ordering of the axes.
Arguments:
Section titled “Arguments:”- Axes: Tuple of integers defining the new ordering of the axes.
- If None are provided, then the default behaviour is to invert
- the ordering of the axes (the same as np.transpose)
Returns:
Section titled “Returns:”A new spectrum with axes reordered.
SpectrumTransform
Section titled “SpectrumTransform”class SpectrumTransform:Represents a diagonal affine transformation used to map between coordinates in the raw spectrum array and chemical shift values.
ndim: intNumber of dimensions in the spectrum.
shape: numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[~_ScalarT]]Shape of the underlying data array.
scaling
Section titled “scaling”scaling: numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[~_ScalarT]]Vector of diagonal components of the affine transformation matrix. Components are scaling values along each axis.
offset
Section titled “offset”offset: numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[~_ScalarT]]Constant offset vector for the affine transformation.
bounds
Section titled “bounds”bounds: numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[~_ScalarT]]Bounds of the spectrum (in array grid coordinates).
inverse_scaling
Section titled “inverse_scaling”inverse_scaling: numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[~_ScalarT]]Vector containing the diagonal entries of the affine transformation matrix for the inverse transform. Used to convert from chemical shifts to grid coords.
inverse_offset
Section titled “inverse_offset”inverse_offset: numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[~_ScalarT]]Vector offset for the inverse transform. Used to convert from chemical shifts to grid coords.
grid_to_shift
Section titled “grid_to_shift”def grid_to_shift( self, x: numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[~_ScalarT]]) -> numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[~_ScalarT]]:Convert a grid coord to a chemical shift.
Arguments:
Section titled “Arguments:”- x: Array containing grid coordinates of points in the spectrum. Must be broadcastable to (ndim,).
Returns:
Section titled “Returns:”Array of corresponding chemical shift values
shift_to_grid
Section titled “shift_to_grid”def shift_to_grid(self, x) -> numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[~_ScalarT]]:Convert a grid coord to a chemical shift.
Arguments:
Section titled “Arguments:”- x: Array containing chemical shift coordinates. Must be broadcastable to (ndim,).
Returns:
Section titled “Returns:”Array of corresponding grid coordinates.
from_reference
Section titled “from_reference”@classmethoddef from_reference( cls, shape: numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[~_ScalarT]], spectral_width: numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[~_ScalarT]], spectrometer_frequency: numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[~_ScalarT]], ref_coord: numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[~_ScalarT]], ref_shift: numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[~_ScalarT]]) -> bioshift.spectra.spectrumtransform.SpectrumTransform:Create a SpectrumTransform from spectrum referencing information.
All arguments must be NDArrays with shape (ndim,)
Arguments:
Section titled “Arguments:”- shape : Number of data points along each axis of the spectrum.
- spectral_width: Difference in chemical shift across the width of the spectrum along each axis, measured in Hz.
- spectrometer_frequency: Frequency of spectrometer along each axis, measured in MHz. Required to convert spectral width into ppm.
- ref_coord: Grid coordinates of a reference point in the spectrum.
- ref_shift: Chemical shift vector of the point located at the reference coordinate.
Returns:
Section titled “Returns:”
SpectrumTransformobject with scaling and offset vectors calculated from the reference data.
axes: tuple[numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[~_ScalarT]], ...]grid: tuple[numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[~_ScalarT]], ...]def slice(self, axis: int) -> bioshift.spectra.spectrumtransform.SpectrumTransform:transpose
Section titled “transpose”def transpose(self, axes=None):NMRExperiment
Section titled “NMRExperiment”class NMRExperiment(enum.Enum):NHSQC = <NMRExperiment.NHSQC: 'NHSQC'>HNCO = <NMRExperiment.HNCO: 'HNCO'>HNCACB
Section titled “HNCACB”HNCACB = <NMRExperiment.HNCACB: 'HNCACB'>HNCA = <NMRExperiment.HNCA: 'HNCA'>HNCOCACB
Section titled “HNCOCACB”HNCOCACB = <NMRExperiment.HNCOCACB: 'HN(CO)CACB'>load_spectrum
Section titled “load_spectrum”def load_spectrum(path: str | os.PathLike) -> bioshift.spectra.spectrum.Spectrum: