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.60751437 0.79681984 0.47506375 0.25979711 0.6172825 ]
 [0.41509848 0.43698721 0.46495209 0.45531921 0.26668963]
 [0.69257897 0.22500874 0.00429019 0.10909167 0.2772603 ]
 [0.83781487 0.95848095 0.78629453 0.9133048  0.7872383 ]
 [0.00218731 0.3840234  0.87369183 0.15712825 0.06712352]
 [0.47775678 0.85187841 0.22228819 0.87204655 0.527083  ]
 [0.99995592 0.97275267 0.9522271  0.04383711 0.93195715]
 [0.37073234 0.31477348 0.26914554 0.32858744 0.47315331]
 [0.91974875 0.34804994 0.92043275 0.60395538 0.47047676]
 [0.35477116 0.241056   0.14764391 0.33115611 0.71399262]]
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/stable/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.042 seconds)

Gallery generated by Sphinx-Gallery