sda.io.load#

Import lab data files and return arrays.

This module provides a unified interface to open and read common lab file formats (text, CSV, Winspec .spe, oscilloscope traces, etc.) and return NumPy arrays.

Supported formats include: - Plain text and CSV (dot or comma decimal, column or row based, with headers) - Winspec (.spe) camera files - LeCroy and Tektronix oscilloscope formats (.csv, .trc, .wfm) - Ocean Optics (.scope, .txt from SpectraSuite) - NumPy binary (.npy)

See also

sda.io.loadspe.loadspe

Winspec .spe loading with metadata.

sda.plot.fplot

Quick plotting of lab data (uses this module).

Classes#

FileOpener

Open and read lab data files with automatic format detection.

Functions#

loadany(fname[, transpose])

Open and read any supported lab file; format is auto-detected.

Module Contents#

class sda.io.load.FileOpener(fname, transpose=-1, verbose=False, warnings=True, **kwargs)#

Open and read lab data files with automatic format detection.

Detects format from extension or file content, then loads data as NumPy array(s). Call get_format() before get_data().

Parameters:
  • fname (str or path-like) – Path to the file to open.

  • transpose (int, optional) – Transpose applied to loaded array; -1 means auto. Passed to numpy loadtxt/autoturn where applicable.

  • verbose (bool, optional) – If True, print progress (default False).

  • warnings (bool, optional) – If True, emit format/header warnings (default True).

  • **kwargs – Passed to underlying loaders (e.g. delimiter for text).

fname#

Path passed at construction.

Type:

str or path-like

format#

Detected format after get_format() (e.g. “txt”, “lecroy”).

Type:

str

data#

Loaded data after get_data().

Type:

np.ndarray or tuple

header#

Column headers if present (e.g. for CSV).

Type:

list or None

Examples

>>> F = FileOpener("data/spectrum.txt", verbose=True)
>>> fmt = F.get_format()
>>> data = F.get_data()
>>> F.get_header()  # optional, if headers were detected
fname#
type#
transpose = -1#
verbose = False#
warnings = True#
kwargs#
delimiters = [';', ',', '\t']#
header = None#
known_formats#
get_format()#

Detect file format from extension or content.

Must be called before get_data(). Sets self.format.

Returns:

Detected format: one of “txt”, “csv”, “npy”, “lecroy”, “lecroytrc”, “tektro”, “tektrowfm”, “winspec”, “ocean”, or “?”.

Return type:

str

get_data()#

Load file content according to detected format.

Returns:

Loaded data (typically 2D array or tuple of 1D arrays). Winspec may return a tuple; see load_winspec().

Return type:

np.ndarray or tuple

Raises:

ValueError – If get_format() was not called first, or format is unknown.

get_header()#

Return column headers if the file had a header line.

Returns:

Header names (e.g. from CSV), or None if no header was detected.

Return type:

list or None

Raises:

ValueError – If get_data() has not been called yet.

is_tektronix()#

Return True if file content matches Tektronix oscilloscope CSV format.

Return type:

bool

is_lecroy()#

Return True if file is LeCroy oscilloscope text/CSV format.

Return type:

bool

is_lecroytrc()#

Return True if file is LeCroy raw binary (.trc) format.

Return type:

bool

is_tektronixwfm()#

Return True if file is Tektronix raw binary (.wfm) format.

Return type:

bool

is_winspec()#

Return True if file is Winspec (Princeton Instrument) .spe format.

Return type:

bool

is_ocean()#

Return True if file is Ocean Optics / SpectraSuite format.

Return type:

bool

is_csv()#

Return True if file has .csv extension.

Return type:

bool

is_txt()#

Return True if file has .txt extension.

Return type:

bool

is_npy()#

Return True if file is NumPy binary .npy format.

Return type:

bool

load_tektronix()#

Load Tektronix oscilloscope CSV. Returns time and amplitude (e.g. current).

Returns:

Stacked (2, n) array: [time, amplitude].

Return type:

np.ndarray

load_tektronixwfm()#

Load Tektronix raw binary .wfm oscilloscope file.

Returns:

(time, voltage) or (time, current) arrays.

Return type:

tuple of (np.ndarray, np.ndarray)

load_lecroy()#

Load LeCroy oscilloscope text/CSV (skiprows=5, auto delimiter).

Returns:

Transposed data array (e.g. (2, n) for time and amplitude).

Return type:

np.ndarray

Notes

Delimiter is guessed. Known variants: WP7100A uses spaces, WS434 uses commas (configurable on the scope).

load_lecroytrc()#

Load LeCroy raw binary .trc oscilloscope file.

Returns:

Stacked (2, n) array: [time, amplitude].

Return type:

np.ndarray

load_winspec()#

Load Winspec (Princeton Instrument) .spe file via loadspe().

Returns:

In spectrum mode: (wavelength, (i, x, y)); in imaging mode: (i, x, y) with i frame index and x, y 2D luminescence. See loadspe() for details.

Return type:

np.ndarray or tuple

load_ocean()#

Load Ocean Optics / SpectraSuite .scope or .txt file.

Header and footer sizes are guessed (typically 14 or 17 header lines). Comma decimals are converted to dots when needed.

Returns:

Transposed data array.

Return type:

np.ndarray

load_csv()#

Load CSV with numpy or pandas (if headers present). Sets self.header.

Returns:

Transposed data array.

Return type:

np.ndarray

load_txt()#

Load plain text: guess delimiter and handle comma decimals.

Returns:

Data array (transpose applied per self.transpose).

Return type:

np.ndarray

guess_delimiter(delimiters=None)#

Return the most frequent delimiter in self.d.

Parameters:

delimiters (list of str, optional) – Candidates (default: [";", ",", "\t"]).

Returns:

Delimiter with highest count, or None if none found.

Return type:

str or None

is_using_commas_instead_of_dots()#

Return True if file appears to use comma as decimal separator.

Return type:

bool

replace_commas_with_dots(d)#

Replace comma decimal separators with dots inside numbers.

Parameters:

d (str) – Raw file content.

Returns:

Content with digit,digit -> digit.digit (e.g. “2,5” -> “2.5”). Does not change commas that are not between two digits.

Return type:

str

sda.io.load.loadany(fname, transpose=-1, **kwargs)#

Open and read any supported lab file; format is auto-detected.

Convenience wrapper around FileOpener: creates an opener, detects format, and returns the loaded data in one call.

Parameters:
  • fname (str or path-like) – Path to the file to open.

  • transpose (int, optional) – Transpose applied to loaded array; -1 means auto (default).

  • **kwargs – Passed to FileOpener (e.g. verbose, warnings, delimiter).

Returns:

Loaded data (shape/type depend on format; see FileOpener).

Return type:

np.ndarray or tuple

See also

FileOpener

Class-based API when you need format or header.

sda.plot.fplot

Quick plotting of lab data (uses this module).