Table Of Contents

Previous topic

nmrglue.linesh

Next topic

nmrglue.segmentation

This Page

nmrglue.peakpick

Peak picking routines, lineshape parameter guessing, and related functions.

This modules is imported as nmrglue.peakpick and can be called as such.

High-Level Functions

These are the functions most users will use from the peakpick module.

nmrglue.analysis.peakpick.pick(data, thres, msep=None, direction='both', algorithm='thres', est_params=True, lineshapes=None)

Pick (find) peaks in a spectrum using a given algorithm.

Parameters:

  • data N-dimensional array.

  • thres Threshold value for minimum peak height.

  • msep N-tuple of minimum peak seperations along each axis.

    Must be defined if algorithm is ‘thresh’ or ‘thresh-fast’

  • direction Direction of peaks, ‘positive’,’negative’, or ‘both’

    or short cut values ‘p’,’n’,’b’.

  • algorithm Peak picking algorithm to use. Options are ‘thres’,

    ‘thres-fast’, ‘downward’, or ‘connected’

  • est_params Set to True to perform a rough estimate of linewidths and

    amplitude for all peaks picked. False returns only the peak locations (centers)

  • lineshapes A list of lineshape classes or string shortcuts for each

    dimension. If not specified Gaussian type lineshapes with a FWHM linewidth parameter is assumed in each dimension. This parameter if only used if est_params is True.

Returns: centers,[linewidths,amplitudes]

  • centers Array of estimated peak locations, shape (n_peaks,ndim).
  • linewidths Array of estimated peak linewidths, shape (n_peaks,ndim).
  • amplitudes Array of estimated peak amplitude, shape (n_peaks).

Low-Level Functions

These functions are typically not used directly by users. They are called by high level functions. Developers and user who want fine control over peak picking will be interested in these functions.

nmrglue.analysis.peakpick.find_regions(data, centers, thres, linewidths=None, amplitudes=None, pad=None, resolve=True)

Find regions in spectra containing peaks.

Parameters:

  • data N-dimensional array.
  • centers Array of peak centers.
  • thres Threshold value for segmenting.
  • linewidths Array of peak linewidths, optional.
  • amplitudes Array of peak amplitudes, optional.
  • pad Tuple of additional points to surround each region with.
  • resolve True/False to resolve overlapping regions.

Returns: regions

  • regions List of dictionaries defining peak containing regions in the

    spectra. Each region dictionary has the following keys:

    • ‘min’ Tuple of the minimum corner of the region.
    • ‘max’ Tuple of the maximum corner of the region.
    • ‘centers’ List of peak centers in the region.
    • ‘linewidths’ List of peak linewidths in the region.
    • ‘amplitudes’ List of peak amplitudes in the region.

    The ‘linewidths’ and ‘amplitude’ keys are only created if linewidths and amplitudes are passed to the function.

nmrglue.analysis.peakpick.regions2recarray(regions)
Convert a regions list to a records array
nmrglue.analysis.peakpick.pad_regions(regions, pad, shape=None)

Add a pad to each region in regions list

Parameters:

  • regions Region dictionary (is changed by this functions)
  • pad Tuple of value to pad on each side on region
  • shape Shape of spectrum dictionary points to

Returns: regions

nmrglue.analysis.peakpick.resolve_region_overlap(regions)

Resolve overlapping regions

Parameters:

  • regions Region dictionary (is changed by this functions)

Returns: regions

nmrglue.analysis.peakpick.combine_regions(regions, list_to_combine)
Combine regions in a list of regions to combine
nmrglue.analysis.peakpick.combine_2regions(r1, r2)
Combine two regions, r1 and r2, returns a new region dictionary
nmrglue.analysis.peakpick.limits_in_limits(lms_list, lms)

Find all limit tuples in lms_list which are overlapping with limits, lms.

Returns a list of indicies of lms_list which overlap.

nmrglue.analysis.peakpick.is_overlappedND(lms1, lms2)
Determind if regions defined by limit1 and limit2 overlap
nmrglue.analysis.peakpick.is_overlapped1D((min1, max1), (min2, max2))
Determine if two line segments are overlapped given limits of both
nmrglue.analysis.peakpick.region2linesh(region)

Convert a region dictionary to linesh input

Parameters:

  • region Region dictionary which has linewidth and amplitude keys

Returns: (rslice,min,guesses,amp_guesses)

  • rslice Slice objects which will slice the array to give a region
  • min List of mimimum to add to the output
  • guesses linesh.fit_NDregion guesses input
  • amp_guesses linesh.fit_NDregion amp_guesses input
nmrglue.analysis.peakpick.linesh2region(params_best, amp_best, rslice)

Convert linesh.fit_NDregion output to a region dictionary

Parameters:

  • params_best fit_NDregion output
  • amp_best fit_NDregion output
  • min List of minimums to add to the output

Returns: region dictionary

nmrglue.analysis.peakpick.filter_by_distance(data, centers, msep, lineshapes=None, amplitudes=None)

Filter peaks which are nearby, keeping those with the largest intesity.

Parameters:

  • data N-dimensional array.
  • centers Array of estimated peak locations.
  • msep N-tuple of minimum peak seperations along each axis.
  • linewidths Array of estimated peak linewidths, optional.
  • amplitudes Array of estimated peak amplitude, optional.

Returns: centers,[linewidths,amplitudes]

nmrglue.analysis.peakpick.pts_in_limits(pts, lms)

Find all points in pts that are within a box defined by limits lms

Returns a list of indicies of pts which are within the box limits.

nmrglue.analysis.peakpick.in_limits(pt, lms)
Return True/False depending on if point (pt) is in limits (lms).
nmrglue.analysis.peakpick.guess_params_center(data, center, thres, lineshapes)

Guess the parameter of a peak centered at center.

Parameters:

  • data Spectral data
  • center Location of peak center
  • thres Noise threshold
  • lineshapes List of lineshape classes

Return: centers,linewidths,amplitudes

  • centers Array of estimated peak centers in each dimension.
  • linewidth Array of estimated linewidths in each dimension
  • amplitude Estimate of peak amplitude
nmrglue.analysis.peakpick.guess_params_segment(data, segment, lineshapes)

Guess the parameter of a peak in a provided segment.

Parameters:

  • data Spectral data
  • segment List of points in segment.
  • lineshapes List of lineshape classes

Return: centers,linewidths,amplitudes

  • centers Array of estimated peak centers in each dimension.
  • linewidth Array of estimated linewidths in each dimension
  • amplitude Estimate of peak amplitude
nmrglue.analysis.peakpick.pick_connected(data, thres, direction='both', seg_flag=False)

Peak pick a spectrum using the connected path algorithm.

Find peaks (local maxima/minima) in an arbitrary dimensional NMR spectra above/below a given threshold and not part of an already defined connected segment.

Parameters:

  • data N-dimensional array.

  • thres Threshold value for minimum peak height.

  • direction Direction of peaks, ‘positive’,’negative’, or ‘both’

    or short cut values ‘p’,’n’,’b’.

  • seg_flag Set True to return list of points in each segment, False to

    return only peak centers.

Return: centers,[segments]

  • centers array of peak locations with shape (n_peaks,ndim).

  • segments List of all points in a given segment, optional with the

    seg_flag.

nmrglue.analysis.peakpick.pick_downward(data, thres, direction='both', seg_flag=False)

Peak pick a spectrum using a downward/upward path algorithm.

Find peaks (local maxima/minima) in an arbitrary dimensional NMR spectra above/below a given threshold and not part of an already defined downward/upward segment.

Parameters:

  • data N-dimensional array.

  • thres Threshold value for minimum peak height.

  • direction Direction of peaks, ‘positive’,’negative’, or ‘both’

    or short cut values ‘p’,’n’,’b’.

  • seg_flag Set True to return list of points in each segment, False to

    return only peak centers.

Return: centers,[segments]

  • centers array of peak locations with shape (n_peaks,ndim).

  • segments List of all points in a given segment, optional with the

    seg_flag.

nmrglue.analysis.peakpick.pick_thres(data, thres, msep, direction='both')

Peak pick a spectrum using a threshhold-minimum distance algorithm.

Find peaks (local maxima/minima) in a arbitrary dimensional NMR spectra above/below a set threshold with a minimal distance between peaks. When the spectrum is small and multiple copies can fit into RAM use the _fast version of this function.

Parameters:

  • data N-dimensional array.

  • thres Threshold value for minimum peak height

  • msep N-tuple of minimum peak seperations along each axis

  • direction Direction of peaks, ‘positive’,’negative’, or ‘both’

    or short cut values ‘p’,’n’,’b’.

Returns: array of peak locations with shape (n_peaks,ndim)

nmrglue.analysis.peakpick.pick_thres_fast(data, thres, msep, direction='both')

Fast version of pick_thres functions

See peak_thres for call details