specfilewrapper
: Reading SpecFile (old API)¶
This module provides a backward compatibility layer with the legacy specfile wrapper.
If you are starting a new project, please consider using silx.io.specfile
instead of this module.
If you want to use this module for an existing project that used the old wrapper through PyMca, you can try replacing:
from PyMca5.PyMcaIO import specfilewrapper
with:
from silx.io import specfilewrapper
There might still be differences between this module and the old wrapper, due to differences in the underlying implementation. Any of these differences that break your code should be reported on https://github.com/silx-kit/silx/issues
The documentation mentions only the methods and attributes that are different
from the ones in silx.io.specfile.SpecFile
and
silx.io.specfile.Scan
. You should refer to the documentation of these
base classes for more information.
-
class
Specfile
(filename)[source]¶ Bases:
silx.io.specfile.SpecFile
This class is a subclass of
silx.io.specfile.SpecFile
.It redefines following methods:
__getitem__()
: returns ascandata
object instead of asilx.io.specfile.Scan
objectlist()
: returns a string representation of a list instead of a list of integers
Following methods are added:
-
__getitem__
(key)[source]¶ Get scan by 0-based index
- Parameters
key (int) – 0-based scan index
- Returns
Scan
- Return type
-
list
()[source]¶ Return a string representation of a list of scan numbers.
The scans numbers are listed in the order in which they appear in the file. Continuous ranges of scan numbers are represented as
first:last
.For instance, let’s assume our specfile contains following scans: 1, 2, 3, 4, 5, 684, 685, 687, 688, 689, 700, 688, 688. This method will then return:
"1:5,684:685,687:689,700,688,688"
-
select
(key)[source]¶ Get scan by
n.m
key- Parameters
key (str) –
"s.o"
(scan number, scan order)- Returns
Scan
- Return type
-
scanno
()[source]¶ Return the number of scans in the SpecFile
This is an alias for
__len__()
, for compatibility with the old specfile wrapper API.
-
allmotors
(scan_index=0)[source]¶ This is an alias for
motor_names()
, for compatibility with the old specfile wrapper API.
-
class
scandata
(specfile, scan_index)[source]¶ Bases:
silx.io.specfile.Scan
This class is a subclass of
silx.io.specfile.Scan
.It redefines following methods/attributes:
data()
becomes a method returning an array, instead of just an arraymca()
: becomes a method returning an array, instead of asilx.io.specfile.MCA
objectheader()
: becomes a method returning a list of scan header lines (or a list of a single header line, if a key is specified), instead of just a list of all header lines
Following methods are added:
-
data
()[source]¶ Return the data in this scan as a 2D numpy array.
The first index corresponds to the columns/detectors in the original file, and the second index is the row index from the original file. Indices are 0-based.
For instance, this is how you access the 18th data sample for the 3rd detector (assuming
sc
is your scan object):>>> scdata = sc.data() >>> data_sample = scdata[2, 17]
-
datacol
(col)[source]¶ Return a data column (all data for one detector)
- Parameters
col – column number (1-based index)
-
dataline
(line)[source]¶ Return a data line (one sample for all detectors)
- Parameters
line – line number (1-based index)
-
header
(key='')[source]¶ Return a list of scan header lines if no key is specified. If a valid key is specified, return a list of a single header line.
- Parameters
key – Header key (e.g.
S, N, L, @CALIB
…) Ifkey
is an empty string, return complete list of scan header lines. Ifkey
does not match any header line, return empty list.- Returns
List of scan header lines
- Return type
List[str]