spike.plugins.specials package — spike 0.99.23 documentation

# spike.plugins.specials package

## Submodules

## spike.plugins.specials.bokeh_display module

displays interactive plots through bokeh, allows to save them in html format.

This plugin uses bokeh (https://bokeh.pydata.org/en/latest/) to build and display interactive plots. It adds npkd.bokeh_fig, a python dictionary containing the styles (colors, lines…) and npkd.bokeh_plot containing the plot itself (bokeh figure format).

To make it work in the notebook add:

  from bokeh.io import show,output_notebook output_notebook()

And do:

  npkd.bokeh(show=True)

To save the plot in html format after doing npkd.bokeh(show=True):

  from bokeh.resources import CDN from bokeh.embed import file_html html_text = file_html(npkd.bokeh_plot, CDN, “Title”) with open(“bokehplot.html”, “w”) as file:

  > file.write(html_text)

`spike.plugins.specials.bokeh_display.` `bokeh_display`(npkd, scale=1.0, autoscalethresh=3.0, absmax=None, show=False, title=None, label=None, xlabel='_def_', ylabel='_def_', axis=None, image=False, mode3D=False, zoom=None, mpldic={}, dbkdic={}, dfigdic={}, linewidth=1, color=None, plot_width=600, plot_height=400, sizing_mode=None, redraw=False, tools='pan, box_zoom, box_select, reset, save')

  Display using bokeh instead of matplotlib

  scale allows to increase the vertical scale of display absmax overwrite the value for the largest point, which will not be computed

  > display is scaled so that the largest point is first computed (and stored in absmax), and then the value at absmax/scale is set full screen

  show will call bk.show() at the end, allowing every declared display to be shown on-screen

    useless in ipython/jupyter notebook

  title add a title to the bokeh plot label add a label text to plot xlabel, ylabel axes label (default is self.currentunit - use None to remove) axis used as axis if present, axis length should match experiment length

  > in 2D, should be a pair (xaxis,yaxis)

  image if True, the function will generate the 2D NMR FID of data,

    if False (Default), the function present contour plots.

  mode3D not implemented zoom is a tuple defining the zoom window (left,right) or ((F1_limits),(F2_limits))

  > defined in the current axis unit (points, ppm, m/z etc ….)

  mpldic a dictionnary passed as is to the matplotlib plot command dbkdic a dictionnary passed as is to populated the parameters of the bokeh graph dfigdic a dictionnary passed as is to populated the content of the bokeh figure linewidth linewidth for the plots (useful for example when using seaborn) color if 1D is the color of the curve,

  > if 2D FID is the palette name to be used, if 2D contour is the color set to be used by matplotlib.

  plot_width, plot_height width and height of the plot sizing_mode if provided, resize plot according to the window chosen sizes.

  > e.g. “scale_width”, “scale_height”, “scale_both”

  tools a string containing the tools to be available for bokeh interactivity.

    e.g. “pan, box_zoom, box_select, reset, save” (see bokeh doc for more info)

`spike.plugins.specials.bokeh_display.` `get_contour_data`(ax)

  Get informations about contours created by matplotlib. ax is the input matplotlob contour ax (cf. fig,ax produced by matplotlib) xs and ys are the different contour lines got out of the matplotlib. col is the color corresponding to the lines.

## spike.plugins.specials.pg_sane module

plugin for PG_Sane algorithm, used for NUS processing

It takes a NUS acquired transient, and fill it by estimating the missing values.

associated publications

- Lionel Chiron, Afef Cherni, Christian Rolando, Emilie Chouzenoux, Marc-André Delsuc Fast Analysis of Non Uniform Sampled DataSets in 2D-FT-ICR-MS. - in progress

- Bray, F., Bouclon, J., Chiron, L., Witt, M., Delsuc, M.-A., & Rolando, C. (2017). Nonuniform Sampling Acquisition of Two-Dimensional Fourier Transform Ion Cyclotron Resonance Mass Spectrometry for Increased Mass Resolution of Tandem Mass Spectrometry Precursor Ions. Anal. Chem., acs.analchem.7b01850. http://doi.org/10.1021/acs.analchem.7b01850

- Chiron, L., van Agthoven, M. A., Kieffer, B., Rolando, C., & Delsuc, M.-A. (2014). Efficient denoising algorithms for large experimental datasets and their applications in Fourier transform ion cyclotron resonance mass spectrometry. PNAS , 111(4), 1385–1390. http://doi.org/10.1073/pnas.1306700111

`spike.plugins.specials.pg_sane.` `HT`(x, thresh)

  returns the Hard Thresholding of x, i.e. all points such as x_i <= thresh are set to 0.0

`spike.plugins.specials.pg_sane.` `HTproj`(x, k)

  returns the Hard Thresholding of x, on the ball of radius ell_o = k i.e. the k largest values are kept, all other are set to 0

`spike.plugins.specials.pg_sane.` `noise`(data, iterations=10, tresh=3.0)

  Simple noise evaluation

`spike.plugins.specials.pg_sane.` `pg_sane`(npkd, HTmode='projection', axis=1, iterations=10, HTratio=None, rank=20, Lthresh=2.0, sampling=None, size=None, final='SANE')

  Papoulis Gershberg algorithm - stabilized with SANE

  This function takes FID with a partial sampling, and fills the holes with estimated values. The FID can then be processed normally, as it was completely acquired.

  mode (threshold or projection) determine PG algorithm iterations : the number of iterations used for the program

  > pg_sane converges quite rapidely, and usually 5 to 20 iterations are suffisant. when the SNR is high, or for large data-sets (>8k) more iterations might be needed

  HTratio: number of lines left by HT/projection - usually a few % of the whole spectrum

    default is 0.01 ( 1% )

  ranka rough estimate of the number of lines present in the FT spectrum of the FID - not stringent -

    if in doubt, use a slightly larger value.

  Lthreshthe multiplier for HT/threshold, usually 2.0

    lower recovers more weak signals but requires more iterations higher requires less iteration but look only to larger peaks.

  samplingif provided, the sampling index list and npkd is supposed to be zerofilled (missing values set to zero)

    if None, npkd.axis1.sampled should be True, and sampling it will be fetched via npkd.axis1.get_sampling()

  final: the final step after iterations,

    default is ‘SANE’: better (noise-less) data-sets, the best reconstruction quality in simulations ‘PG’ to reapply PG step - produces the cleanest/more compressible data-sets ‘Reinject’: the closest to acquired data - to use if there is very little noise.

  size: if different from None, pg_sane will also extrapolate to size

class `spike.plugins.specials.pg_sane.` `sane_pgTests`(methodName='runTest')

  Bases: `unittest.case.TestCase`

  `test_NUS_sampling`()

    NUS example removing the sampling noise

  `test_NUS_sampling2`()

    NUS larger example removing the sampling noise

## spike.plugins.specials.wavelet module

A plugin which install wavelet denoising

This plugin is based on the PyWavelet library, which should be installed independently before trying to use this plugin It can be found at: http://www.pybytes.com/pywavelets/

M-A Delsuc april 2016 from an idea by L Chiron

class `spike.plugins.specials.wavelet.` `WaveLetTest`(methodName='runTest')

  Bases: `unittest.case.TestCase`

  - Testing Wavelet plugin-

  `announce`()
  `setUp`()

    Hook method for setting up the test fixture before exercising it.

  `test_wave`()

    - testing wavelet -

`spike.plugins.specials.wavelet.` `denoise1D`(data, noiseSigma, wavelet='db3')

  performed the 1D denoising data : a 1D numpy array wavelet : the wavelet basis used,

`spike.plugins.specials.wavelet.` `denoise2D`(data, noiseSigma, wavelet='db3')

  performed the 2D denoising data : a 2D numpy array wavelet : the wavelet basis used

`spike.plugins.specials.wavelet.` `ilog2`(x)

  integer log2 definition

`spike.plugins.specials.wavelet.` `wavelet`(npkd, nsigma=1.0, wavelet='db3')

  Performs the wavelet denoising of a 1D or 2D spectrum.

  nsigma the threshold is nsigma times the estimate noise level,

    default 1.0 - corresponds to a relatively strong denoising

  wavelet the wavelet basis used, default ‘db3’ (Daubechies 3)

    check pywt.wavelist() for the list of possible wavelet

  eg: d.wavelet(nsigma=0.5) # d is cleaned after execution

  ref: Donoho DL (1995) De-noising by soft-thresholding. IEEE Trans Inf Theory 41:613–621.

  Based on the PyWavelet library

## Module contents