General presentation of the Spectrum data structureΒΆ

This example illustrates how to create and use the specio.core.Spectrum data structure.

# Authors: Guillaume Lemaitre <guillaume.lemaitre@inria.fr>
# License: BSD3

from __future__ import print_function

import numpy as np

from specio import specread
from specio.core import Spectrum
from specio.datasets import load_spc_path

print(__doc__)

The Spectrum class provide a data structure which embeds the following information:

  • a 1D ndarray of shape (n_wavelength,) or 2D ndarray of shape (n_spectra, n_wavelength) amplitudes;
  • a 1D ndarray of shape (n_wavelength,) wavelength;
  • a dict meta.

Therefore, an instance can be built using those three variable. We give a simple example below to create an instance containing 10 spectra with 5 wavelengths.

n_spectra, n_wavelength = 10, 5
amplitude = np.random.random((n_spectra, n_wavelength))
wavelength = np.arange(n_wavelength)
metadata = {'nature': 'toy example'}

spectra = Spectrum(amplitude, wavelength, metadata)
print('The spectrum created has the representation: \n{}'.format(spectra))

Out:

The spectrum created has the representation:
Spectrum:
wavelength:
 [0 1 2 3 4]
amplitudes:
 [[0.41155881 0.4410429  0.74851219 0.91246808 0.17335279]
 [0.03342243 0.72810047 0.74043749 0.04202056 0.78000646]
 [0.85951004 0.68387822 0.12000613 0.0226045  0.32373463]
 [0.36167387 0.21916125 0.51391335 0.89549974 0.73305959]
 [0.19896516 0.9117214  0.74223989 0.44378499 0.70809748]
 [0.16594486 0.43981374 0.86848413 0.43283146 0.91462357]
 [0.53432633 0.07034977 0.73516734 0.45864686 0.69151735]
 [0.09986733 0.13807725 0.33753242 0.61236941 0.23041451]
 [0.0654372  0.47233339 0.24795823 0.77457653 0.07745354]
 [0.62503565 0.02894108 0.90872696 0.02870197 0.77222143]]
metadata:
 {'nature': 'toy example'}

The Spectrum instances are returned when using specio.specread. We give a quick example to illustrate this case.

spc_filename = load_spc_path()
print('Reading the file from: {}'.format(spc_filename))
spectra = specread(spc_filename)
print('The spectrum read has the representation: \n{}'.format(spectra))

Out:

Reading the file from: /home/docs/checkouts/readthedocs.org/user_builds/specio/envs/latest/local/lib/python2.7/site-packages/specio/datasets/data/spectra.spc
x-y(1)
The spectrum read has the representation:
Spectrum:
wavelength:
 [ 400.62109375  402.94384766  405.26721191 ... 3797.08911133 3798.45288086
 3799.81542969]
amplitudes:
 [1487.         1385.         1441.         ...  147.24124146  139.16082764
  134.08041382]
metadata:
 {'dat_fmt': u'x-y', 'fexp': 128, 'fytype': 4, 'fcatxt': '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 'fspare': '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 'trandm': False, 'fzinc': 0.0, 'freserv': '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 'year': 115, 'fwtype': '\x00', 'fmods': 0, 'fmethod': '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 'fsource': '\x00\x00\x00\x00\x00\x00\x00\x00\x00', 'fprocs': '\x00', 'flevel': '\x00', 'fpost': '\x00', 'txvals': True, 'fcmnt': '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 'hour': 16, 'day': 9, 'fpeakpt': 0, 'ftflg': '\x80', 'tordrd': False, 'logtxto': 64, 'flast': 3799.8154296875, 'flogoff': 15832, 'length': 16484, 'fwplanes': 0, 'ffactor': 0.0, 'tsprec': False, 'fxtype': 13, 'zlabel': u'Arbitrary', 'ylabel': u'Counts', 'spacing': 1.7796828983965969, 'ffirst': 400.62109375, 'fversn': 'K', 'log_other': [''], 'filename': 'spectra.spc', 'tcgram': False, 'log_dict': {'SPIKE FILTER ': ' MULTIPLE ACCUM.', 'ND FILTER ': ' D0', 'AUTOEXPOSURE ': ' OFF', 'ACQ. TIME (S) ': ' ', 'BINNING ': ' ', 'LASER (NM) ': ' 660 ', 'INSTRUMENT ': ' LABRAM HR EVOL', 'DELAY TIME (S) ': ' ', 'TITLE ': ' ', 'SAMPLE ': ' ', 'SLIT ': ' ', 'X (\xb5M) ': ' ', 'ACCUMULATIONS ': ' ', 'Y (\xb5M) ': ' ', 'READOUT MODE ': ' SIGNAL', 'Z (\xb5M) ': ' ', 'OBJECTIV ': ' X100LWD', 'SITE ': ' ', 'HOLE ': ' ', 'WINDOWS ': ' ', 'REMARK ': ' ', 'DENOISE ': ' OFF', 'AUTOFOCUS ': ' OFF', 'ICS CORRECTION ': ' OFF', 'GRATING ': ' 300 GR/MM', 'STAGEXY ': ' MARZHAUSER', 'DARK CORRECTION ': ' OFF', 'COLLECTION ': ' FIBER', 'RANGE (CM-\xb9) ': ' 399...3800', 'PROJECT ': ' ', 'DATE ': ' 27.03.2015 13:25', 'STAGEZ ': ' PI', 'INST. PROCESS ': ' OFF', 'DETECTOR ': ' SYNAPSE'}, 'cmnt': u'', 'fres': '\x00\x00\x00\x00\x00\x00\x00\x00\x00', 'month': 5, 'logdsks': 0, 'logspar': '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 'minute': 33, 'logbins': 0, 'talabs': False, 'fexper': 0, 'tmulti': False, 'logsizm': 4096, 'fnsub': 1, 'fsampin': 0, 'logsizd': 652, 'exp_type': u'General SPC', 'txyxys': False, 'fwinc': 0.0, 'xlabel': u'Raman Shift (cm-1)', 'fztype': 0, 'fdate': 120933409, 'log_content': ['ACQ. TIME (S) = ', 'ACCUMULATIONS = ', 'RANGE (CM-\xb9) = 399...3800', 'WINDOWS = ', 'AUTOFOCUS = OFF', 'AUTOEXPOSURE = OFF', 'SPIKE FILTER = MULTIPLE ACCUM.', 'DELAY TIME (S) = ', 'BINNING = ', 'READOUT MODE = SIGNAL', 'DENOISE = OFF', 'ICS CORRECTION = OFF', 'DARK CORRECTION = OFF', 'INST. PROCESS = OFF', 'INSTRUMENT = LABRAM HR EVOL', 'DETECTOR = SYNAPSE', 'OBJECTIV = X100LWD', 'GRATING = 300 GR/MM', 'ND FILTER = D0', 'LASER (NM) = 660 ', 'SLIT = ', 'HOLE = ', 'COLLECTION = FIBER', 'STAGEXY = MARZHAUSER', 'STAGEZ = PI', 'X (\xb5M) = ', 'Y (\xb5M) = ', 'Z (\xb5M) = ', 'PROJECT = ', 'SAMPLE = ', 'SITE = ', 'TITLE = ', 'REMARK = ', 'DATE = 27.03.2015 13:25', ''], 'fnpts': 1911}

Total running time of the script: ( 0 minutes 0.015 seconds)

Gallery generated by Sphinx-Gallery