Read multiple files using regular expressionΒΆ

This example shows how to read several SPC files which are located inside a folder.

../../_images/sphx_glr_plot_read_multiple_files_001.png

Out:

The SPC files will be search in: /home/docs/checkouts/readthedocs.org/user_builds/specio/checkouts/latest/examples/reader/data/*.spc
x-y(1)
x-y(1)

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

from __future__ import print_function

import os
import sys

import matplotlib.pyplot as plt

from specio import specread

print(__doc__)

# Get the path to the data relatively to this example
DATA_PATH = os.path.dirname(sys.argv[0])

spc_filenames = os.path.join(DATA_PATH, 'data', '*.spc')
print('The SPC files will be search in: {}'.format(spc_filenames))

# Read the data
spectra = specread(spc_filenames)

# Plot the first spectra
plt.plot(spectra.wavelength,
         spectra.amplitudes.T)

# We get the axis information by using the meta data of the first file read.
plt.xlabel(spectra.meta[0]['xlabel'])
plt.ylabel(spectra.meta[0]['ylabel'])
plt.show()

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

Gallery generated by Sphinx-Gallery