silx.io.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 silx.io.specfilewrapper.Specfile(filename)[source]

Bases: specfile.SpecFile

This class is a subclass of silx.io.specfile.SpecFile.

It redefines following methods:

Following methods are added:

__getitem__(key)[source]

Get scan by 0-based index

Parameters:key (int) – 0-based scan index
Returns:Scan
Return type:scandata
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:scandata
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.

epoch()[source]
Returns:Epoch, from last word on file header line #E
Return type:int
Raise:ValueError if #E line not found in header or last word on #E cannot be converted to type int
title()[source]
Returns:Title, from second field on #C header line (field are strings separated by two spaces)
Return type:str
Raise:ValueError if #C line not found in header or line is empty
class silx.io.specfilewrapper.scandata(specfile, scan_index)[source]

Bases: 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 array
  • mca(): becomes a method returning an array, instead of a silx.io.specfile.Scan object
  • header(): 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:

allmotors()[source]

Return a list of all motor names (identical to motor_names).

allmotorpos()[source]

Return a list of all motor positions (identical to motor_positions).

alllabels()[source]

Return a list of all labels (labels).

cols()[source]

Return the number of data columns (number of detectors)

command()[source]

Return the command called for this scan (#S header line)

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)
date()[source]

Return the date from the scan header line #D

fileheader(key='')[source]

Return a list of file header lines

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…) If key is an empty string, return complete list of scan header lines. If key does not match any header line, return empty list.
Returns:List of scan header lines
Return type:list[str]
lines()[source]

Return the number of data lines (number of data points per detector)

mca(number)[source]

Return one MCA spectrum

Parameters:number – MCA number (1-based index)
nbmca()[source]

Return number of MCAs in this scan

Previous topic

silx.io.specfile: Reading SpecFile

Next topic

silx.io.spech5: h5py-like API to SpecFile

This Page