Data Structure Module¶
Core data structures for storing and managing measurement data.
Main Container¶
DataSet ¶
The container for a set of measurements and everything derived from them.
log_data, load_data and the create_test_* functions all return
one. A DataSet holds seven lists, one per kind of data item (see
Attributes). Add items with add_to_dataset; items are stored by
reference, never copied.
The calculate_* methods run the matching analysis function over
time_data_list and REPLACE the corresponding list with the
results rather than appending to it, so calling calculate_fft_set
twice leaves one set of spectra, and calculate_tf_set also drops
any modal reconstruction held in tf_data_list. With no time data
they empty that list and print a message. The plot_* methods draw
one list in a new matplotlib figure and return its PlotData.
save_data writes a .dvma file, optionally with only some of
the measurements (see subset).
Parameters:
-
data(object, default:None) –An item, or a homogeneous list of items, to add at construction; see
add_to_dataset.
Attributes:
-
time_data_list(TimeDataList) –The measurements (
TimeData). -
freq_data_list(FreqDataList) –Spectra (
FreqData). -
cross_spec_data_list(CrossSpecDataList) –Cross-spectrum and coherence matrices (
CrossSpecData). -
tf_data_list(TfDataList) –Transfer functions (
TfData), including modal reconstructions. -
modal_data_list(ModalDataList) –Modal fits (
ModalData). -
sono_data_list(SonoDataList) –Sonograms (
SonoData). -
meta_data_list(MetaDataList) –Legacy dataset-level metadata (
MetaData). -
pydvma_version(str) –The pydvma version that created the DataSet or, for one loaded from a file, the version that wrote the file (
'unknown (pre-1.4.0)'for an old file with no version stamp).
Attributes¶
Methods:¶
add_to_dataset ¶
Append one data item, or a homogeneous list of them, to the matching list.
The item's class picks the list (a TimeData goes to
time_data_list, and so on). Items are appended by reference,
not copied. An object of any other class, and an empty list, are
ignored without a message.
Parameters:
-
data(object) –A
TimeData,FreqData,CrossSpecData,TfData,ModalData,SonoDataorMetaData, or a list (a Python list or one of the*DataListclasses) of items that are all of one of those classes.
Raises:
-
ValueError–datais a list of mixed item types.
replace_data_item ¶
Replace the item at one index of the matching list.
The list is chosen by the class of data, as in
add_to_dataset; an object of any other class is ignored.
Parameters:
-
data(object) –The replacement data item.
-
n_set(int) –Index, in that list, of the item to replace.
Raises:
-
IndexError–n_setis out of range for that list.
remove_last_data_item ¶
Remove the last item of one list, if the list is not empty.
Parameters:
-
data_class(str) –Class name of the items whose list to shorten:
'TimeData','FreqData','CrossSpecData','TfData','ModalData','SonoData'or'MetaData'. Any other value does nothing.
remove_data_item_by_index ¶
Remove items from one list by index.
If any index is out of range, nothing is removed and a message is printed.
Parameters:
-
data_class(str) –Class name of the items whose list to shorten, as for
remove_last_data_item. -
list_index(int or list[int] or ndarray) –Index or indices to remove. A list passed here is sorted in place.
calculate_fft_set ¶
Calculate the FFT of every measurement, replacing freq_data_list.
Runs analysis.calculate_fft on each item of time_data_list.
The previous contents of freq_data_list are discarded, not
appended to.
Parameters:
-
time_range(list or ndarray or PlotData, default:None) –[t_start, t_stop]in seconds, applied to every measurement; None (the default) uses each whole record. -
window(str, default:None) –A
scipy.signal.windowsname, or None (the default) for a rectangular window.
calculate_tf_set ¶
Calculate the transfer functions of every measurement, replacing tf_data_list.
Runs analysis.calculate_tf on each item of time_data_list.
The previous contents of tf_data_list, modal reconstructions
included, are discarded.
Parameters:
-
ch_in(int, default:0) –Column index of the input (reference) channel (default 0).
-
time_range(list or ndarray, default:None) –[t_start, t_stop]in seconds; None (the default) uses each whole record. -
window(str, default:None) –A
scipy.signal.windowsname, or None (the default) for a rectangular window. -
N_frames(int, default:1) –Number of averaging frames per measurement (default 1).
-
overlap(float, default:0.5) –Fractional overlap between frames (default 0.5).
calculate_cross_spectrum_matrix_set ¶
Calculate the cross-spectrum matrix of every measurement, replacing cross_spec_data_list.
Runs analysis.calculate_cross_spectrum_matrix on each item of
time_data_list. The previous contents of
cross_spec_data_list are discarded.
Parameters:
-
ch_in(int, default:0) –Accepted for symmetry with
calculate_tf_setand ignored: the matrix covers every channel pair. -
time_range(list or ndarray or PlotData, default:None) –[t_start, t_stop]in seconds; None (the default) uses each whole record. -
window(str, default:None) –A
scipy.signal.windowsname, e.g.'hann'for random excitation. None (the default) applies no window, which suits impacts. -
N_frames(int, default:1) –Number of averaging frames per measurement (default 1).
-
overlap(float, default:0.5) –Fractional overlap between frames (default 0.5).
calculate_tf_averaged ¶
Calculate one ensemble-averaged TF from all measurements, replacing tf_data_list.
Runs analysis.calculate_tf_averaged on the whole of
time_data_list, treating each measurement as one frame of the
average, and sets tf_data_list to a one-item list holding the
result.
Parameters:
-
ch_in(int, default:0) –Column index of the input (reference) channel (default 0).
-
time_range(list or ndarray, default:None) –[t_start, t_stop]in seconds, applied to every measurement; None (the default) uses each whole record. -
window(str, default:None) –A
scipy.signal.windowsname, e.g.'hann'for random excitation. None (the default) applies no window, which suits impacts.
calculate_cross_spectra_averaged ¶
Calculate one ensemble-averaged cross-spectrum matrix, replacing cross_spec_data_list.
Runs analysis.calculate_cross_spectra_averaged on the whole of
time_data_list and sets cross_spec_data_list to a one-item
list holding the result.
Parameters:
-
time_range(list or ndarray, default:None) –[t_start, t_stop]in seconds, applied to every measurement; None (the default) uses each whole record. -
window(str, default:None) –A
scipy.signal.windowsname, or None (the default) for a rectangular window.
calculate_sono_set ¶
Calculate the sonogram of every measurement, replacing sono_data_list.
Runs analysis.calculate_sonogram on each item of
time_data_list. The previous contents of sono_data_list are
discarded.
Parameters:
-
nperseg(int, default:None) –STFT segment length in samples; None (the default) uses about 1/50 of each record.
clean_impulse ¶
Return a copy of the DataSet with the hammer channel of every measurement cleaned.
Runs analysis.clean_impulse on each item of time_data_list
and returns a deep copy of the DataSet whose measurements are
the cleaned versions. This DataSet's data is not changed. The
copy's other lists (spectra, TFs, and so on) are copied as they
are and are not recomputed from the cleaned data. A measurement
that was already cleaned is placed in the copy as the same
object, not a copy.
Parameters:
-
ch_impulse(int, default:0) –Column index of the force (impulse) channel in every measurement (default 0).
Returns:
-
dataset(DataSet or None) –The cleaned copy, or None (with a message) when there is no time data.
subset ¶
Return a new DataSet holding chosen measurements and the results derived from them.
A spectrum, cross-spectrum, transfer function or sonogram is kept
when it was computed from at least one of the chosen
measurements, so an ensemble-averaged result comes along if any
of its source measurements is chosen. A modal fit is kept when
any of the transfer functions it was fitted to came from a chosen
measurement. MetaData, and derived items whose source is not
among the chosen measurements (or is missing from the DataSet
altogether), are left out, even when every index is chosen.
Items are shared, not copied: the new DataSet's lists hold the
same objects as this one's, so changing an item through either
DataSet changes it in both. Take a copy.deepcopy first if
you need independent objects. Items keep their original order.
Parameters:
-
sets(int or Iterable[int]) –Index or indices into
time_data_listto keep (0-based). A repeated index counts once.
Returns:
-
dataset(DataSet) –The new DataSet, with
pydvma_versioncopied from this one.
Raises:
-
IndexError–setscontains an index outsiderange(len(self.time_data_list)).
save_data ¶
Save the DataSet to a file with file.save_data.
Writes the .dvma container format, adding .dvma when the
name ends in neither .dvma nor .npy; a name ending in
.npy writes the legacy pickle format instead. If the file
already exists you are asked at the terminal whether to
overwrite it (y overwrites; anything else cancels), unless
overwrite_without_prompt is True, which a scripted re-save
needs.
Parameters:
-
filename(str, default:None) –Output file name. Required: leaving it out raises TypeError, since pydvma has no file dialog.
-
sets(int or Iterable[int], default:None) –If given, saves
self.subset(sets)instead of the whole DataSet; seesubset. None (the default) saves everything. -
overwrite_without_prompt(bool, default:False) –If True, overwrite an existing file without asking. Default False.
Returns:
-
filename(str or None) –The file written, or None if the save was cancelled.
export_to_matlab ¶
Export the DataSet to a MATLAB .mat file with file.export_to_matlab.
The data arrays are written raw (in volts), with the time,
frequency and TF calibration factors and units alongside; see
file.export_to_matlab for the variable names.
Parameters:
-
filename(str, default:None) –Output file name (
.matis added if missing). Required: leaving it out raises TypeError, since pydvma has no file dialog. -
overwrite_without_prompt(bool, default:False) –If False (the default), an existing file triggers a y/n question at the terminal.
Returns:
-
filename(str or None) –The file written, or None if the export was cancelled.
export_to_matlab_jwlogger ¶
Export the DataSet in Jim Woodhouse's MATLAB logger format.
Uses file.export_to_matlab_jwlogger; the .mat file can be
opened by that MATLAB logger.
Parameters:
-
filename(str, default:None) –Output file name (
.matis added if missing). Required: leaving it out raises TypeError, since pydvma has no file dialog. -
overwrite_without_prompt(bool, default:False) –If False (the default), an existing file triggers a y/n question at the terminal.
Returns:
-
filename(str or None) –The file written, or None if the export was cancelled.
plot_time_data ¶
Plot time_data_list in a new matplotlib figure.
Each channel is multiplied by its channel_cal_factors. Lines
outside sets / channels are drawn faint; clicking a
legend entry toggles a line between faint and full.
Parameters:
-
sets(str or list[int], default:'all') –'all'(the default) or the set indices to highlight. -
channels(str or list[int], default:'all') –'all'(the default) or the channel indices to highlight in every set.
Returns:
-
plot(PlotData) –The plot;
plot.figandplot.axare its matplotlib Figure and Axes. Pass it astime_rangetocalculate_fft_set(oranalysis.calculate_fft) to analyse the time range currently shown.
plot_freq_data ¶
Plot freq_data_list as calibrated magnitude in dB in a new figure.
Lines outside sets / channels are drawn faint; clicking a
legend entry toggles a line. Other views (linear, real,
imaginary, phase, Nyquist) are available through
PlotData.update.
Parameters:
-
sets(str or list[int], default:'all') –'all'(the default) or the set indices to highlight. -
channels(str or list[int], default:'all') –'all'(the default) or the channel indices to highlight in every set.
Returns:
-
plot(PlotData) –The plot;
plot.figandplot.axare its matplotlib Figure and Axes.
plot_tf_data ¶
Plot tf_data_list as calibrated magnitude in dB in a new figure.
Coherence is drawn dotted on a second y-axis (plot.ax2),
unless every set's coherence is missing or identically 1. Modal
reconstructions are labelled fit. NaN values in a set's
tf_coherence are replaced by 1 in place when plotted.
Parameters:
-
sets(str or list[int], default:'all') –'all'(the default) or the set indices to highlight. -
channels(str or list[int], default:'all') –'all'(the default) or the channel indices to highlight in every set.
Returns:
-
plot(PlotData) –The plot;
plot.fig,plot.axandplot.ax2are its matplotlib Figure, main Axes and coherence Axes.
plot_sono_data ¶
Plot one channel of one sonogram as a colour map in a new figure.
The magnitude is shown in dB. Exact zeros in that channel's
sono_data are replaced by 1e-16 in place, to avoid taking the
log of zero.
Parameters:
-
n_set(int, default:0) –Index into
sono_data_list(default 0). -
n_chan(int, default:0) –Channel (plane) index within that sonogram (default 0).
-
db_range(float, default:60) –Colour-scale range in dB below the maximum (default 60).
Returns:
-
plot(PlotData) –The plot;
plot.figandplot.axare its matplotlib Figure and Axes.
update_dataset ¶
Rebuild a DataSet from an older pydvma version in the current layout.
Copies every item list of dataset into a fresh DataSet, so the
result has every list the current version expects, and gives every
TfData a flag_modal_TF attribute (False) if it lacks one. The
items are shared with dataset, not copied, so that attribute is
added to the original items too; if dataset has no
modal_data_list, an empty one is added to it.
Parameters:
-
dataset(DataSet) –The dataset to rebuild. It must have
time_data_list,freq_data_list,tf_data_list,cross_spec_data_list,sono_data_listandmeta_data_list;modal_data_listis optional.
Returns:
-
dataset_new(DataSet) –A new DataSet holding the same items.
Time Domain Data¶
TimeData ¶
TimeData(time_axis, time_data, settings, timestamp=None, timestring=None, units=None, channel_cal_factors=None, id_link=None, test_name=None)
One block of acquired time-series data plus its acquisition metadata.
Held inside a DataSet.time_data_list. Produced by log_data,
by the test-data factories in testdata, and on import from
Matlab. The numeric content is in volts (see "Voltage-Based
I/O" in the user-guide acquisition page); apply
channel_cal_factors to convert to engineering units at display
or fit time. analysis.calculate_* functions copy units and
channel_cal_factors onto their derived FreqData / TfData /
CrossSpecData / SonoData outputs.
Attributes:
-
time_axis(ndarray) –1D sample times in seconds.
-
time_data(ndarray) –Shape
(n_samples, n_channels)voltage samples. -
settings(MySettings) –Snapshot of the acquisition configuration.
-
timestamp(datetime) –Capture start time.
-
timestring(str) –Filesystem-safe rendering of
timestamp. -
units(list[str] or None) –Engineering units per channel (e.g.
['N', 'm/s', 'g']). None if unset. -
channel_cal_factors(ndarray) –Per-channel multipliers from volts to engineering units. Defaults to all-ones.
-
id_link–Reference to a source TimeData (used when this object is derived rather than freshly acquired).
-
test_name(str or None) –Free-form label, displayed in plots.
-
unique_id(UUID) –Generated at construction; used by derived objects to link back to their source via
id_link. -
channel_calibration(list) –Optional, absent unless a calibration was recorded (set after construction; files saved before it existed load without it). A list with one entry per channel; each entry is None (nothing recorded) or a dict saying how that channel's
channel_cal_factors/unitswere obtained:method('sensitivity' for a spec-sheet value, 'reference_tone' for a measured one),date(ISO 8601),sensitivityandunit,reference(None, orlevel,level_unitandfreqof the reference tone), the statedgain_db,input_modeandpad(each None when unknown),device(name, or None), a free-textnote, andcarried(True when copied from an earlier set rather than measured on this one).
TimeDataList ¶
Bases: list
A list of TimeData measurements: a DataSet's time_data_list.
An ordinary Python list with methods that run an analysis over every item, and that read or set the items' calibration factors.
Methods:¶
calculate_fft_set ¶
Calculate the FFT of every item.
Parameters:
-
time_range(list or ndarray or PlotData, default:None) –[t_start, t_stop]in seconds; None (the default) uses each whole record. Seeanalysis.calculate_fft. -
window(str, default:None) –A
scipy.signal.windowsname, or None (the default) for a rectangular window.
Returns:
-
freq_data_list(FreqDataList) –One
FreqDataper item, in order.
calculate_tf_set ¶
Calculate the transfer functions of every item.
Parameters:
-
ch_in(int, default:0) –Column index of the input (reference) channel (default 0).
-
time_range(list or ndarray, default:None) –[t_start, t_stop]in seconds; None (the default) uses each whole record. -
window(str, default:None) –A
scipy.signal.windowsname, or None (the default) for a rectangular window. -
N_frames(int, default:1) –Number of averaging frames per item (default 1).
-
overlap(float, default:0.5) –Fractional overlap between frames (default 0.5).
Returns:
-
tf_data_list(TfDataList) –One
TfDataper item, in order, fromanalysis.calculate_tf.
calculate_cross_spectrum_matrix_set ¶
Calculate the cross-spectrum matrix of every item.
Parameters:
-
ch_in(int, default:0) –Accepted for symmetry with
calculate_tf_setand ignored: the matrix covers every channel pair. -
time_range(list or ndarray or PlotData, default:None) –[t_start, t_stop]in seconds; None (the default) uses each whole record. -
window(str, default:None) –A
scipy.signal.windowsname, or None (the default) for a rectangular window. -
N_frames(int, default:1) –Number of averaging frames per item (default 1).
-
overlap(float, default:0.5) –Fractional overlap between frames (default 0.5).
Returns:
-
cross_spec_data_list(CrossSpecDataList) –One
CrossSpecDataper item, in order, fromanalysis.calculate_cross_spectrum_matrix.
calculate_tf_averaged ¶
Calculate one TF averaged across all items with analysis.calculate_tf_averaged.
Parameters:
-
ch_in(int, default:0) –Column index of the input (reference) channel (default 0).
-
time_range(list or ndarray, default:None) –[t_start, t_stop]in seconds, applied to every item; None (the default) uses each whole record. -
window(str, default:None) –A
scipy.signal.windowsname, e.g.'hann'for random excitation. None (the default) applies no window, which suits impacts.
Returns:
-
tf_data(TfData) –The ensemble-averaged transfer functions.
calculate_cross_spectra_averaged ¶
Calculate one cross-spectrum matrix averaged across all items.
Uses analysis.calculate_cross_spectra_averaged.
Parameters:
-
time_range(list or ndarray, default:None) –[t_start, t_stop]in seconds, applied to every item; None (the default) uses each whole record. -
window(str, default:None) –A
scipy.signal.windowsname, or None (the default) for a rectangular window.
Returns:
-
cross_spec_data(CrossSpecData) –The ensemble average.
calculate_sono_set ¶
Calculate the sonogram of every item.
Parameters:
-
nperseg(int, default:None) –STFT segment length in samples; None (the default) uses about 1/50 of each record.
Returns:
-
sono_data_list(SonoDataList) –One
SonoDataper item, in order, fromanalysis.calculate_sonogram.
get_calibration_factors ¶
Return every item's channel_cal_factors.
Returns:
-
factors(list) –One per-channel array per item, in order. These are the items' own arrays, not copies, so changing an element changes the item.
set_calibration_factors_all ¶
Set every item's channel_cal_factors at once.
Parameters:
-
factors(list) –One per-channel array per item, in order, as returned by
get_calibration_factors. Itemiis givenfactors[i]itself (not a copy).
Raises:
-
IndexError–factorshas fewer entries than the list.
set_calibration_factor ¶
Set the calibration factor of one channel of one item, in place.
Prints a message and changes nothing if the list is empty or an index is out of range.
Parameters:
-
factor(float) –The new factor (volts to engineering units).
-
n_set(int, default:0) –Index of the item in the list (default 0).
-
n_chan(int, default:0) –Channel (column) index within that item (default 0).
export_to_csv ¶
Export the time data to a CSV file with file.export_to_csv.
The numbers are written raw (uncalibrated); a #-commented
header line carries each column's calibration factor and units.
See file.export_to_csv for the column layout.
Parameters:
-
filename(str, default:None) –Output file name (
.csvis added if missing). Required: leaving it out raises TypeError, since pydvma has no file dialog. -
overwrite_without_prompt(bool, default:False) –If False (the default), an existing file triggers a y/n question at the terminal.
Returns:
-
filename(str or None) –The file written, or None if the export was cancelled.
Frequency Domain Data¶
FreqData ¶
FreqData(freq_axis, freq_data, settings, units=None, channel_cal_factors=None, id_link=None, test_name=None)
One-sided complex frequency spectrum of a TimeData capture.
Produced by analysis.calculate_fft. The spectrum is the raw
np.fft.rfft of the (optionally windowed) time data — i.e. it is
not scaled to a PSD or amplitude spectrum; consumers that need
PSD should square the magnitude themselves. units and
channel_cal_factors are copied verbatim from the source TimeData.
Attributes:
-
freq_axis(ndarray) –Frequency bins in Hz (length
N//2+1). -
freq_data(ndarray) –Shape
(n_freq, n_channels)complex spectrum, one column per channel. -
settings(MySettings) –Snapshot of the analysis configuration (includes the window choice and the time range that was used).
-
units(list[str] or None) –Engineering units per channel.
-
channel_cal_factors(ndarray) –Per-channel multipliers from volts to engineering units; applied at display time.
-
id_link(UUID) –unique_idof the source TimeData. -
unique_id(UUID) –This item's own identity, minted at construction. It is what makes a pull → modify → push round trip through
pydvma.session.SessionREPLACE this result in place instead of appending a second copy beside it. Optional in the container: a file written before derived items carried ids restores without the attribute. -
test_name(str or None) –Free-form label.
-
timestamp(datetime) –When this FreqData was constructed.
-
timestring(str) –Filesystem-safe rendering of
timestamp. -
source_signature(str) –OPTIONAL, set post-construction by
analysis.calculate_fft— a 16-hex-character hash of the SOURCE samples and rate (pydvma._signature), so a loaded file can tell an intact compute chain from one whose time data changed after the compute. Genuinely optional (needs ahasattrguard): items written before signatures existed make no claim about their chain. -
source_settings(dict) –OPTIONAL, set alongside
source_signature— the analysis knobs that call used, as JSON-safe scalars, so the result is self-describing. A settings change does NOT invalidate a stored result; only a source-sample change does.
FreqDataList ¶
Bases: list
A list of FreqData spectra: a DataSet's freq_data_list.
An ordinary Python list with methods that read or set the items' calibration factors and export them to CSV.
Methods:¶
get_calibration_factors ¶
Return every item's channel_cal_factors.
Returns:
-
factors(list) –One per-channel array per item, in order. These are the items' own arrays, not copies, so changing an element changes the item.
set_calibration_factors_all ¶
Set every item's channel_cal_factors at once.
Parameters:
-
factors(list) –One per-channel array per item, in order, as returned by
get_calibration_factors. Itemiis givenfactors[i]itself (not a copy).
Raises:
-
IndexError–factorshas fewer entries than the list.
set_calibration_factor ¶
Set the calibration factor of one channel of one item, in place.
Prints a message and changes nothing if the list is empty or an index is out of range.
Parameters:
-
factor(float) –The new factor (volts to engineering units).
-
n_set(int, default:0) –Index of the item in the list (default 0).
-
n_chan(int, default:0) –Channel (column) index within that item (default 0).
export_to_csv ¶
Export the spectra to a CSV file with file.export_to_csv.
The numbers are written raw (uncalibrated); a #-commented
header line carries each column's calibration factor and units.
See file.export_to_csv for the column layout.
Parameters:
-
filename(str, default:None) –Output file name (
.csvis added if missing). Required: leaving it out raises TypeError, since pydvma has no file dialog. -
overwrite_without_prompt(bool, default:False) –If False (the default), an existing file triggers a y/n question at the terminal.
Returns:
-
filename(str or None) –The file written, or None if the export was cancelled.
Transfer Function Data¶
TfData ¶
TfData(freq_axis, tf_data, tf_coherence, settings, units=None, channel_cal_factors=None, id_link=None, test_name=None)
Transfer function H(f) from one input channel to one or more outputs.
Produced by analysis.calculate_tf (single TimeData),
analysis.calculate_tf_averaged (ensemble TimeDataList) or
analysis.calculate_bla (a best-linear-approximation run). For the
first two the convention is Pxy[in, out] / Pxy[in, in] per output
channel and tf_coherence carries the corresponding coherence.
BLA sets are different: no cross-spectrum estimator is involved
at all — the FRF comes from inverting the excitation matrix at each
excited bin — so the Pxy convention does not describe them,
tf_coherence is None (the bla_sigma_* pair is the quality
measure instead), settings.ch_in may be None (commanded-drive
mode has no measured input channel), and freq_axis holds only the
excited bins rather than a full rfft grid. bla is non-None exactly
on those sets.
Calibration: channel_cal_factors[k] is the factor for column k
— multiplying tf_data[:, k] * channel_cal_factors[k] at display time
gives the TF in engineering units. When calculated it holds the
ratio cal[out_k] / cal[in] of the source channels, and units are
constructed as "<out_unit>/<in_unit>" per output channel (compound
units bracketed, "(m/s²)/N"). It may instead be set directly, with
TfDataList.set_calibration_factor, to calibrate the TF without
knowing either transducer (a free mass: |a/F| = 1/m).
Attributes:
-
freq_axis(ndarray) –One-sided frequency bins in Hz.
-
tf_data(ndarray) –Shape
(n_freq, n_outputs), complex. One column per non-input channel. -
tf_coherence(ndarray) –Same shape, real, in [0, 1].
-
settings(MySettings) –Snapshot including the chosen
ch_inand the derivedch_out_set(the channel indices intf_data's second axis). -
units(list[str] or None) –Per-output-channel unit strings (e.g.
['m/s/N', 'g/N']). -
channel_cal_factors(ndarray) –Per-output cal factors, set to the ratio cal[out] / cal[in] when calculated. A manual override here (
TfDataList.set_calibration_factor) replaces that ratio — calibrating the TF directly, as from a known mass — and the web logger reads such a factor back as the set's transfer-function calibration. -
id_link–unique_idof the source TimeData (or list when averaged). -
unique_id(UUID) –This item's own identity, minted at construction — see
FreqData.unique_idfor why a derived item needs one. -
test_name(str or None) –Free-form label.
-
timestamp(datetime) –When constructed.
-
timestring(str) –Filesystem-safe rendering of
timestamp. -
flag_modal_TF(bool) –True when this TfData is a modal reconstruction (from
modal.reconstruct_transfer_functionormodal.reconstruct_transfer_function_global) rather than a measurement. The modal fits skip such items. -
bla_sigma_nl(ndarray or None) –Nonlinear-distortion standard deviation, shape
(n_freq, n_outputs), real, in the same linear units asabs(tf_data)— a std, not a variance, so it goes straight onto a dB axis with no further square root. PER-REALISATION: it is the distortion level of one realisation, not the error bar ontf_data, which issqrt(M)smaller. Set byanalysis.calculate_bla; None on an ordinary transfer function. -
bla_sigma_n(ndarray or None) –Measurement-noise standard deviation, same shape, units and per-realisation reading as
bla_sigma_nl. Set byanalysis.calculate_bla; None on an ordinary transfer function. -
bla(dict or None) –The BLA run spec that produced this estimate (multisine design, x-mode, channel roles, capture fs, excited bins and which excitation
qthis TfData belongs to). JSON-clean scalars only, so it round-trips through the .dvma manifest. None on an ordinary transfer function. -
source_signature(str) –OPTIONAL, set post-construction by
analysis.calculate_tf/analysis.calculate_tf_averaged— a 16-hex-character hash of the SOURCE samples and rate (pydvma._signature; for an ensemble, every source in list order), so a loaded file can tell an intact compute chain from one whose time data changed after the compute. Genuinely optional (needs ahasattrguard): items written before signatures existed, and BLA estimates, carry no signature and make no claim about their chain. -
source_settings(dict) –OPTIONAL, set alongside
source_signature— the analysis knobs that call used, as JSON-safe scalars, so the result is self-describing. A settings change does NOT invalidate a stored result; only a source-sample change does.
All three BLA attributes are set in __init__ and are declared
container fields, so they survive a .dvma round trip as None or as
their value — no hasattr guard needed, unlike the genuinely
optional iw_power_counter.
TfDataList ¶
Bases: list
A list of TfData transfer functions: a DataSet's tf_data_list.
An ordinary Python list with methods that read or set the items'
calibration factors, manage a modal reconstruction and export to
CSV. The modal fitting functions in pydvma.modal take one.
Methods:¶
get_calibration_factors ¶
Return every item's channel_cal_factors.
Returns:
-
factors(list) –One per-channel array per item, in order. These are the items' own arrays, not copies, so changing an element changes the item. For a TF each factor is the ratio
cal[out] / cal[in].
set_calibration_factors_all ¶
Set every item's channel_cal_factors at once.
Parameters:
-
factors(list) –One per-channel array per item, in order, as returned by
get_calibration_factors. Itemiis givenfactors[i]itself (not a copy). For a TF each factor is the ratiocal[out] / cal[in].
Raises:
-
IndexError–factorshas fewer entries than the list.
set_calibration_factor ¶
Set the calibration factor of one transfer function, in place.
A TF's factor is its own: analysis.calculate_tf starts it at the
ratio cal[out] / cal[in] of the source channels, and setting it
here replaces that ratio. This is how a TF is calibrated DIRECTLY,
without knowing either transducer — e.g. from a free mass, whose
accelerance is exactly 1/m: the factor is the one the measured
TF must be multiplied by to give the actual values. The time data's
own channel factors are not touched.
The web logger reads a factor set here back as the set's
transfer-function calibration (Calibrate dialog, "Transfer
function" section) when the saved file is reopened. Recalculating
the TF with analysis.calculate_tf starts again from the channel
ratio.
Prints a message and changes nothing if the list is empty or an index is out of range.
Parameters:
-
factor(float) –The multiplier for the measured TF.
-
n_set(int, default:0) –Index of the item in the list (default 0).
-
n_chan(int, default:0) –TF column within that item (default 0) — the output channels in ascending order, input left out.
-
units(str or tuple or None, default:None) –The calibrated TF's unit for that column. Either the whole string (
'(m/s)/N') or a(numerator, denominator)pair (('m/s', 'N')), which is composed with compound units bracketed exactly asanalysis.calculate_tfwrites them. None (the default) leaves the units as they are.
Raises:
-
ValueError–unitsis a sequence that is not a pair.
add_modal_reconstruction ¶
Add a modal reconstruction TF to the list, or replace the existing one.
If no item is a reconstruction (flag_modal_TF True),
tf_data is appended. Otherwise mode='replace' overwrites
the LAST item of the list (so the reconstruction is assumed to be
last) and mode='append' appends; any other mode then does
nothing.
Parameters:
-
tf_data(TfData) –The reconstruction, for example from
modal.reconstruct_transfer_function. -
mode(str, default:'replace') –'replace'(the default) or'append'.
export_to_csv ¶
Export the transfer functions to a CSV file with file.export_to_csv.
The numbers are written raw (uncalibrated); a #-commented
header line carries each column's calibration factor and units.
See file.export_to_csv for the column layout.
Parameters:
-
filename(str, default:None) –Output file name (
.csvis added if missing). Required: leaving it out raises TypeError, since pydvma has no file dialog. -
overwrite_without_prompt(bool, default:False) –If False (the default), an existing file triggers a y/n question at the terminal.
Returns:
-
filename(str or None) –The file written, or None if the export was cancelled.
Sonogram Data¶
SonoData ¶
SonoData(time_axis, freq_axis, sono_data, settings, units=None, channel_cal_factors=None, id_link=None, test_name=None)
Short-time-FFT spectrogram (sonogram) of a multi-channel TimeData.
Produced by analysis.calculate_sonogram. Each frame is a windowed
FFT of a nperseg-sample segment of the source data; segments are
overlapped by noverlap and the resulting matrix lets you see how
spectral content evolves over time. analysis.calculate_cwt produces
the same object from a Morlet wavelet transform instead. Used by
analysis.calculate_damping_from_sono to extract per-mode damping
from free-decay measurements.
Also produced by the WEB APP, when a Save is told to include the
sonogram. Such an item differs in one way a reader must know about:
its third axis holds only the channels the user chose to save, in
the order they were saved, NOT every channel of the source. So
sono_data[:, :, k], units[k] and channel_cal_factors[k]
are all indexed by PLANE, and the source channel each plane came
from is recorded in source_settings['channels'][k]. A
single-channel save is the common case (it is the default the prompt
offers), and then sono_data.shape[2] == 1 however many channels
the measurement has.
Attributes:
-
time_axis(ndarray) –Frame midpoints in seconds.
-
freq_axis(ndarray) –One-sided frequency bins in Hz.
-
sono_data(ndarray) –Shape
(n_freq, n_frames, n_channels), complex. Magnitude-squared gives a per-bin power spectrogram. For an app-written item the last axis is the SAVED channel subset — see above. -
settings(MySettings) –Snapshot including
pretrig_samples(used bycalculate_damping_from_sonoto pick the free-decay start time). -
units(list[str] or None) –Engineering units, one per PLANE of
sono_data. -
channel_cal_factors(ndarray) –Multipliers from volts to engineering units, one per PLANE of
sono_data. -
id_link–unique_idof the source TimeData. -
unique_id(UUID) –This item's own identity, minted at construction — see
FreqData.unique_idfor why a derived item needs one. -
test_name(str or None) –Free-form label.
-
timestamp(datetime) –When constructed.
-
timestring(str) –Filesystem-safe rendering of
timestamp.
SonoDataList ¶
Bases: list
A list of SonoData sonograms: a DataSet's sono_data_list.
An ordinary Python list; it adds no methods.
Cross-Spectrum Data¶
CrossSpecData ¶
CrossSpecData(freq_axis, Pxy, Cxy, settings, units=None, channel_cal_factors=None, id_link=None, test_name=None, enbw_hz=None)
Full cross-spectrum matrix Pxy[i,j,f] and coherence matrix Cxy[i,j,f].
Produced by analysis.calculate_cross_spectrum_matrix (single
TimeData) or analysis.calculate_cross_spectra_averaged (ensemble
TimeDataList). The diagonal Pxy[i, i, :] is the per-channel
auto-spectrum (= scipy.signal.welch with scaling='spectrum');
off-diagonal Pxy[i, j, :] matches scipy.signal.csd with the same
settings. Pxy is Hermitian — Pxy[j, i, :] = conj(Pxy[i, j, :]).
Attributes:
-
freq_axis(ndarray) –One-sided frequency bins in Hz.
-
Pxy(ndarray) –Shape
(n_channels, n_channels, n_freq), complex. Cross-spectrum matrix. -
Cxy(ndarray) –Same shape, real, in [0, 1]. Coherence matrix.
-
settings(MySettings) –Includes
window,time_range,N_frames,overlapactually used. -
units(list[str] or None) –Engineering units per channel.
-
channel_cal_factors(ndarray) –Per-channel multipliers from volts to engineering units. Defaults to all-ones. These are AMPLITUDE factors per channel, so a consumer combines them for the quantity it wants: the auto-spectrum
Pxy[i, i]is a power and takescal[i]**2, while the cross-spectrumPxy[i, j]takescal[i] * cal[j].Cxyis a normalised ratio and is calibration-INVARIANT — never scale it. -
enbw_hz(float or None) –Effective noise bandwidth of the window in Hz,
fs * sum(w**2) / sum(w)**2.Pxyis a power SPECTRUM (scipyscaling='spectrum'), whose level scales with the frequency resolution; dividing by this converts it to a spectral DENSITY, whose level does not:density = Pxy / enbw_hz. None on an object built before this was recorded, or by hand. -
id_link–unique_idof the source TimeData (or list of ids when averaged across a TimeDataList). -
unique_id(UUID) –This item's own identity, minted at construction — see
FreqData.unique_idfor why a derived item needs one. -
test_name(str or None) –Free-form label.
-
timestamp(datetime) –When constructed.
-
timestring(str) –Filesystem-safe rendering of
timestamp.
CrossSpecDataList ¶
Bases: list
A list of CrossSpecData items: a DataSet's cross_spec_data_list.
An ordinary Python list; it adds no methods.
Modal Data¶
ModalData ¶
A set of fitted modes — each row of M is one mode's
(fn, zn, an[chan...], pn[chan...], rk[chan...], rm[chan...])
parameter vector as produced by
modal.modal_fit_all_channels.
Use add_mode to append further modes (e.g. across separate
frequency-band fits); rows are kept sorted by fn. After any
add/delete, the summary arrays fn, zn, an, pn are
refreshed and indexable per mode.
Attributes:
-
M(ndarray) –Shape
(n_modes, 2 + 4*n_channels). Each row packs[fn, zn, an_0..an_C, pn_0..pn_C, rk_0..rk_C, rm_0..rm_C]. -
fn(ndarray) –Per-mode natural frequencies in Hz.
-
zn(ndarray) –Per-mode damping ratios.
-
an(ndarray) –Shape
(n_modes, n_channels)modal-constant amplitudes. -
pn(ndarray) –Same shape; modal-constant phases in radians.
-
channels(int) –Number of channels (=
n_channelsabove). -
settings(MySettings) –Snapshot including the source TF's settings.
-
units–Engineering units (passed through from source).
-
id_link–unique_id(s) of the TFs that produced these modes. -
unique_id(UUID) –This item's own identity, minted at construction — see
FreqData.unique_id. Modal fits are pushed back from notebooks like any other item, and without an id every push would append another copy of the fit. -
test_name(str or None) –Free-form label.
Attributes¶
timestring
instance-attribute
¶
timestring = '_' + str(t.year) + '_' + str(t.month) + '_' + str(t.day) + '_at_' + str(t.hour) + '_' + str(t.minute) + '_' + str(t.second)
Methods:¶
add_mode ¶
Add one mode to the modal matrix M.
Rows stay sorted by natural frequency, and the summaries fn,
zn, an and pn are refreshed. A row whose length does not
match the existing rows is rejected with a printed message.
Parameters:
-
xn(ndarray) –One packed mode,
[fn, zn, an_0..an_C, pn_0..pn_C, rk_0..rk_C, rm_0..rm_C]for C+1 channels (the layout ofmodal.unpack_matrix).
delete_mode ¶
Delete one or more modes (rows of M) and refresh the summaries.
Deleting the last remaining mode is allowed: M becomes an empty
(0, 2 + 4*channels) array, fn and zn become empty and
an and pn have shape (0, channels). channels is kept,
since it comes from the column count.
Parameters:
-
mode_number(int or list[int]) –Row index or indices of
Mto delete (rows are sorted byfn).
ModalDataList ¶
Bases: list
A list of ModalData fits: a DataSet's modal_data_list.
An ordinary Python list; it adds no methods.
Metadata¶
MetaData ¶
Dataset-level units and calibration, kept for legacy datasets.
Attributes:
-
units–Engineering units.
-
channel_cal_factors–Per-channel multipliers (legacy; always None here — calibration lives on each data item instead).
-
tf_cal_factors–Per-TF multipliers (legacy; always None here).
-
timestamp(datetime) –When this MetaData was built.
-
timestring(str) –Filesystem-safe rendering of
timestamp. -
unique_id(UUID) –This item's own identity, minted at construction — see
FreqData.unique_id.
MetaDataList ¶
Bases: list
A list of MetaData items: a DataSet's meta_data_list.
An ordinary Python list; it adds no methods.