File Operations Module¶
Functions for importing, exporting, and saving data in various formats.
Load and Save¶
load_data ¶
Loads a dataset from filename, or displays a file dialog if no
filename is given (the dialog needs the GUI extras installed).
Container detection is by content (zip magic bytes); .mat and
legacy .npy fall back to extension:
.dvmacontainer files (zip magic bytes) — the default format since 1.5.0; safe, pickle-free (seecontainer).- legacy
.npypickle saves from pydvma <= 1.4.0 — supported forever. Trust model: the legacy path usesnp.load(allow_pickle=True), and unpickling can execute arbitrary code, so only open legacy .npy files you or your lab created..dvmafiles do not have this caveat. .mat(by extension) — JW-logger imports.
save_data ¶
Saves a DataSet to 'filename.dvma' (container format v2 — a zip
of manifest.json + pickle-free .npy arrays; see container), or
provides a dialog if no filename is given.
Legacy escape hatch: an explicit filename ending in .npy
writes the pre-1.5.0 pickle format instead, for workflows that
still need it. New saves should prefer .dvma — it is safe to
share (loading executes no code) and readable outside Python.
Parameters:
-
dataset(DataSet) –An object of the class DataSet
-
parent(optional, default:None) –Parent widget for file dialog
-
filename(str, default:None) –Output filename, dialog shown if not provided
-
overwrite_without_prompt(bool, default:False) –If True, overwrite without asking
-
sets(int or Iterable[int], default:None) –If given, writes
dataset.subset(sets)instead of the whole dataset — the notebook counterpart of the web app's Save "Choose sets…" picker (seedatastructure.DataSet.subsetfor the exact inclusion rule).None(the default) writesdatasetunchanged.
save_fig ¶
Saves figure to file 'filename.png' and 'filename.pdf', or provides dialog if no filename provided.
Parameters:
-
plot(PlotData or Figure) –A PlotData object or matplotlib Figure object
-
parent(optional, default:None) –Parent widget for file dialog
-
figsize(tuple, default:None) –Tuple for figure size
-
filename(str, default:None) –Output filename, dialog shown if not provided
-
overwrite_without_prompt(bool, default:False) –If True, overwrite without asking
Export Functions¶
export_to_matlab ¶
Exports dataset class to file 'filename.mat', or provides dialog if no filename provided.
Saved file can be loaded directly in Matlab as set of arrays.
Parameters:
-
dataset(DataSet) –An object of the class DataSet
-
parent(optional, default:None) –Parent widget for file dialog
-
filename(str, default:None) –Output filename, dialog shown if not provided
-
overwrite_without_prompt(bool, default:False) –If True, overwrite without asking
export_to_matlab_jwlogger ¶
Exports dataset class to file 'filename.mat', or provides dialog if no filename provided.
Saved file is compatible with Jim Woodhouse logger file format.
Parameters:
-
dataset(DataSet) –An object of the class DataSet
-
parent(optional, default:None) –Parent widget for file dialog
-
filename(str, default:None) –Output filename, dialog shown if not provided
-
overwrite_without_prompt(bool, default:False) –If True, overwrite without asking
export_to_csv ¶
Exports data to file 'filename.csv', or provides dialog if no filename provided.
Saved file is *.csv
Parameters:
-
data_list(TimeDataList, FreqDataList, or TfDataList) –Data list to export
-
parent(optional, default:None) –Parent widget for file dialog
-
filename(str, default:None) –Output filename, dialog shown if not provided
-
overwrite_without_prompt(bool, default:False) –If True, overwrite without asking
Import Functions¶
import_from_matlab_jwlogger ¶
Imports dataset class from file 'filename.mat', or provides dialog if no filename provided.
Saved file is compatible with Jim Woodhouse logger file format. The
conventions below were confirmed against the recovered MATLAB source
("Data logger V2.9a": specmenu.m save path, avtflogpars.m
averaged-TF computation, dospec.m):
- SPECTRAL files save
yspec, dt2, npts, freq, tfun.freqis the SAMPLE RATE,nptsthe FFT length, soyspechasnpts/2 + 1rows on the one-sided axisrfftfreq(npts, 1/freq)(df = freq/npts). - TIME files save
indata, buflen, freq, dt2, tsmax— there is NOnptsand notfun(JW's guitar_string captures confirmed this; the old import assumednptsand raised KeyError). The time axis comes fromindata's own length at fs =freq;buflenduplicates that length andtsmaxrecords the capture's scale (the data is already in physical units — do NOT rescale by it). tfunselects spectrum (0) / transfer function (1).dt2is the saveddtypevector[n_time_channels, n_yspec_columns, n_sonogram]— column COUNTS, not column types.- The averaged-TF logger writes
yspecas INTERLEAVED pairs[H1, coh1, H2, coh2, ...]— each output channel's H1-estimator TF followed by its coherence (avtflogpars.m:thing(:,2k-1) = cross/autoin;thing(:,2k) = |cross|^2/(autoin*autoout)). - The save menu also allows ARBITRARY column subsets ("Channels to save": one / all / displayed / custom) and files can be composited by the Add-on-load path — so real archives also contain bare-H files (coherence stripped) and multi-instrument H collections.
- The writer duplicates the first positive bin into the DC row
(
yspec(1,:) = yspec(2,:)), so the DC bin is cosmetic.
Import behaviour for TF files: coherence columns are detected
unambiguously (real-valued AND within [0, 1] — no measured complex FRF
is both). The documented interleaved [H, coh, ...] layout is
recognised and split with positional pairing; an equal split in any
other order pairs by order of appearance; files with no coherence
columns, or an ambiguous mix, import as before (every column a TF
channel — nothing is dropped).
Parameters:
-
filename(str, default:None) –Input filename, dialog shown if not provided