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.loadspeWinspec .spe loading with metadata.
sda.plot.fplotQuick plotting of lab data (uses this module).
Classes#
Open and read lab data files with automatic format detection. |
Functions#
|
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()beforeget_data().- Parameters:
fname (
strorpath-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).
- format#
Detected format after
get_format()(e.g. “txt”, “lecroy”).- Type:
- data#
Loaded data after
get_data().- Type:
np.ndarrayortuple
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(). Setsself.format.- Returns:
Detected format: one of “txt”, “csv”, “npy”, “lecroy”, “lecroytrc”, “tektro”, “tektrowfm”, “winspec”, “ocean”, or “?”.
- Return type:
- 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.ndarrayortuple- 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:
- Raises:
ValueError – If
get_data()has not been called yet.
- is_tektronix()#
Return True if file content matches Tektronix oscilloscope CSV format.
- Return type:
- 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:
tupleof(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().
- 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.
- is_using_commas_instead_of_dots()#
Return True if file appears to use comma as decimal separator.
- Return type:
- 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 (
strorpath-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.ndarrayortuple
See also
FileOpenerClass-based API when you need format or header.
sda.plot.fplotQuick plotting of lab data (uses this module).