sdynpy.core.sdynpy_data.NDDataArray
- class NDDataArray(shape, nelements, data_dimension, ordinate_dtype='float64', buffer=None, offset=0, strides=None, order=None)[source]
Bases:
SdynpyArray
Generic N-Dimensional data structure
This data structure can contain real or complex data. More specific SDynPy data arrays inherit from this superclass.
- __init__()
Methods
argmax
([reduction])Returns the index of the maximum ordinate in the data array
argmin
([reduction])Returns the index of the minimum ordinate in the data array
downsample
(factor)Downsample a signal by keeping only every n-th abscissa/ordinate pair.
extract_elements
(indices)Parses elements from the data array specified by the passed indices
extract_elements_by_abscissa
(min_abscissa, ...)Extracts elements with abscissa values within the specified range
from_uff
(unv_data_dict[, squeeze])Create a data array from a unv dictionary from read_unv
from_unv
(unv_data_dict[, squeeze])Create a data array from a unv dictionary from read_unv
get_drive_points
([return_indices])Returns data arrays where the reference is equal to the response
get_reciprocal_data
([return_indices])Gets reciprocal pairs of data from an NDDataArray.
interpolate
(interpolated_abscissa[, kind])Interpolates the NDDataArray using SciPy's interp1d.
join
(data_arrays[, increment_abscissa])Joins several data arrays together by concatenating their ordinates
load
(filename)Load in the specified file into a SDynPy array object
max
([reduction])Returns the maximum ordinate in the data array
min
([reduction])Returns the minimum ordinate in the data array
plot
([one_axis, subplots_kwargs, ...])Plot the data array
plot_image
([ax, reduction_function, ...])reshape_to_matrix
([error_if_missing])Reshapes a data array to a matrix with response coordinates along the rows and reference coordinates along the columns
save
(filename)Save the array to a numpy file
to_imat_struct
([Version, SetRecord, ...])Creates a Matlab structure that can be read the IMAT toolbox.
to_imat_struct_array
([Version, SetRecord, ...])Creates a Matlab structure that can be read the IMAT toolbox.
to_shape_array
([abscissa_values])Converts an NDDataArray to a ShapeArray
transform_coordinate_system
(...[, ...])Performs coordinate system transformations on the data
validate_common_abscissa
(**allclose_kwargs)Returns True if all functions have the same abscissa
zero_pad
([num_samples, update_abscissa, ...])Add zeros to the beginning or end of a signal
Attributes
The spacing of the abscissa in the function.
Number of dimensions to the data
Returns the function type of the data array as a FunctionTypes Enum
AbscissaValueExtractor that can be indexed to extract an abscissa range
AbscissaIndexExtractor that can be indexed to extract specific elements
Number of coordinates defining the data array
Number of elements in each data array
CoordinateArray corresponding to the response coordinates
CoordinateArray corresponding to the response coordinates
- property abscissa_spacing
The spacing of the abscissa in the function. Returns ValueError if abscissa are not evenly spaced.
- argmax(reduction=None, *argmax_args, **argmax_kwargs)[source]
Returns the index of the maximum ordinate in the data array
- Parameters
reduction (function, optional) – Optional function to modify the data, e.g. to select maximum of the absolute value. The default is None.
*argmax_args (various) – Additional arguments passed to np.argmax
**argmax_kwargs (various) – Additional keyword arguments passed to np.argmax
- Returns
Index of the maximum of the flattened ordinate. Use np.unravel_index with self.ordinate.shape to get the unflattened index.
- Return type
int
- argmin(reduction=None, *argmin_args, **argmin_kwargs)[source]
Returns the index of the minimum ordinate in the data array
- Parameters
reduction (function, optional) – Optional function to modify the data, e.g. to select minimum of the absolute value. The default is None.
*argmin_args (various) – Additional arguments passed to np.argmax
**argmin_kwargs (various) – Additional keyword arguments passed to np.argmax
- Returns
Index of the minimum of the flattened ordinate. Use np.unravel_index with self.ordinate.shape to get the unflattened index.
- Return type
int
- property data_dimension
Number of dimensions to the data
- downsample(factor)[source]
Downsample a signal by keeping only every n-th abscissa/ordinate pair.
- Parameters
factor (int) – Downsample factor. Only the factor-th abcissa will be kept.
- Returns
The downsampled data object
- Return type
- extract_elements(indices)[source]
Parses elements from the data array specified by the passed indices
- Parameters
indices – Any type of indices into a np.ndarray to select the elements to keep
- Returns
Array reduced to specified elements
- Return type
- extract_elements_by_abscissa(min_abscissa, max_abscissa)[source]
Extracts elements with abscissa values within the specified range
- Parameters
min_abscissa (float) – Minimum abscissa value to keep
max_abscissa (float) – Maximum abscissa value to keep.
- Returns
Array reduced to specified elements.
- Return type
- static from_uff(unv_data_dict, squeeze=True)
Create a data array from a unv dictionary from read_unv
- Parameters
unv_data_dict (dict) – Dictionary containing data from read_unv
squeeze (bool, optional) – Automatically reduce dimension of the read data if possible. The default is True.
- Returns
return_functions – Data read from unv
- Return type
- static from_unv(unv_data_dict, squeeze=True)[source]
Create a data array from a unv dictionary from read_unv
- Parameters
unv_data_dict (dict) – Dictionary containing data from read_unv
squeeze (bool, optional) – Automatically reduce dimension of the read data if possible. The default is True.
- Returns
return_functions – Data read from unv
- Return type
- property function_type
Returns the function type of the data array as a FunctionTypes Enum
- get_drive_points(return_indices=False)[source]
Returns data arrays where the reference is equal to the response
- Parameters
return_indices (bool, optional) – If True, it will return a set of indices into the original array that extract the drive point functions. If False, then the drive point functions are returned directly. The default is False.
- Raises
ValueError – If the data does not have reference and response coordinates, the method will raise a ValueError.
- Returns
If return_indices is True, this will return the indices into the original array that extract the drive point data. If return_indices is False, this will return the drive point NDDataArrays directly.
- Return type
np.ndarray or NDDataArray subclass
- get_reciprocal_data(return_indices=False)[source]
Gets reciprocal pairs of data from an NDDataArray.
- Parameters
return_indices (bool, optional) – If True, it will return a set of indices into the original array that extract the reciprocal functions. If False, then the reciprocal functions are returned directly. The default is False.
- Raises
ValueError – If the data does not have reference and response coordinates, the method will raise a ValueError.
- Returns
If return_indices is True, this will return the indices into the original array that extract the reciprocal data. If return_indices is False, this will return the reciprocal NDDataArrays directly.
- Return type
np.ndarray or NDDataArray subclass
- property idx_by_ab
AbscissaValueExtractor that can be indexed to extract an abscissa range
- property idx_by_el
AbscissaIndexExtractor that can be indexed to extract specific elements
- interpolate(interpolated_abscissa, kind='linear', **kwargs)[source]
Interpolates the NDDataArray using SciPy’s interp1d.
- Parameters
interpolated_abscissa (ndarray) – Abscissa values at which to interpolate the function. If multi-dimensional, it will be flattened.
kind (str or int, optional) – Specifies the kind of interpolation as a string or as an integer specifying the order of the spline interpolator to use. The string has to be one of ‘linear’, ‘nearest’, ‘nearest-up’, ‘zero’, ‘slinear’, ‘quadratic’, ‘cubic’, ‘previous’, or ‘next’. ‘zero’, ‘slinear’, ‘quadratic’ and ‘cubic’ refer to a spline interpolation of zeroth, first, second or third order; ‘previous’ and ‘next’ simply return the previous or next value of the point; ‘nearest-up’ and ‘nearest’ differ when interpolating half-integers (e.g. 0.5, 1.5) in that ‘nearest-up’ rounds up and ‘nearest’ rounds down. Default is ‘linear’.
**kwargs – Additional arguments to scipy.interpolate.interp1d.
- Returns
Array with interpolated arguments
- Return type
- classmethod join(data_arrays, increment_abscissa=True)[source]
Joins several data arrays together by concatenating their ordinates
- Parameters
data_arrays (NDDataArray) – Arrays to concatenate
increment_abscissa (bool, optional) – Determines how the abscissa concatenation is handled. If False, the abscissa is left as it was in the original functions. If True, it will be incremented so it is continuous.
- Return type
NDDataArray subclass
- classmethod load(filename)[source]
Load in the specified file into a SDynPy array object
- Parameters
filename (str) – Filename specifying the file to load. If the filename has extension .unv or .uff, it will be loaded as a universal file. Otherwise, it will be loaded as a NumPy file.
- Raises
AttributeError – Raised if a unv file is loaded from a class that does not have a from_unv attribute defined.
- Returns
SDynpy array of the appropriate type from the loaded file.
- Return type
cls
- max(reduction=None, *max_args, **max_kwargs)[source]
Returns the maximum ordinate in the data array
- Parameters
reduction (function, optional) – Optional function to modify the data, e.g. to select maximum of the absolute value. The default is None.
*max_args (various) – Additional arguments passed to np.max
**max_kwargs (various) – Additional keyword arguments passed to np.max
- Returns
Maximum value in the ordinate.
- Return type
Value
- min(reduction=None, *min_args, **min_kwargs)[source]
Returns the minimum ordinate in the data array
- Parameters
reduction (function, optional) – Optional function to modify the data, e.g. to select minimum of the absolute value. The default is None.
*min_args (various) – Additional arguments passed to np.min
**min_kwargs (various) – Additional keyword arguments passed to np.min
- Returns
Minimum value in the ordinate.
- Return type
Value
- property num_coordinates
Number of coordinates defining the data array
- property num_elements
Number of elements in each data array
- plot(one_axis: bool = True, subplots_kwargs: dict = {}, plot_kwargs: dict = {}, abscissa_markers=None, abscissa_marker_labels=None, abscissa_marker_type='vline', abscissa_marker_plot_kwargs={})[source]
Plot the data array
- Parameters
one_axis (bool, optional) – Set to True to plot all data on one axis. Set to False to plot data on multiple subplots. one_axis can also be set to a matplotlib axis to plot data on an existing axis. The default is True.
subplots_kwargs (dict, optional) – Keywords passed to the matplotlib subplots function to create the figure and axes. The default is {}.
plot_kwargs (dict, optional) – Keywords passed to the matplotlib plot function. The default is {}.
abscissa_markers (ndarray, optional) – Array containing abscissa values to mark on the plot to denote significant events.
abscissa_marker_labels (str or ndarray) – Array of strings to label the abscissa_markers with, or alternatively a format string that accepts index and abscissa inputs (e.g. ‘{index:}: {abscissa:0.2f}’). By default no label will be applied.
abscissa_marker_type (str) – The type of marker to use. This can either be the string ‘vline’ or a valid matplotlib symbol specifier (e.g. ‘o’, ‘x’, ‘.’).
abscissa_marker_plot_kwargs (dict) – Additional keyword arguments used when plotting the abscissa label markers.
- Returns
axis – On which the data were plotted
- Return type
matplotlib axis or array of axes
- plot_image(ax=None, reduction_function=None, colorbar_scale='linear', colorbar_min=None, colorbar_max=None)[source]
- property reference_coordinate
CoordinateArray corresponding to the response coordinates
- reshape_to_matrix(error_if_missing=True)[source]
Reshapes a data array to a matrix with response coordinates along the rows and reference coordinates along the columns
- Parameters
error_if_missing (bool) – If True, an error will be thrown if there are missing data objects when trying to make a matrix of functions (i.e. if a response degree of freedom is missing from one reference). If False, response coordinates will simply be discarded if they do not exist for all references. Default is True.
- Returns
output_array – 2D Array of NDDataArray
- Return type
Data Aarray
- property response_coordinate
CoordinateArray corresponding to the response coordinates
- save(filename)[source]
Save the array to a numpy file
- Parameters
filename (str) – Filename that the array will be saved to. Will be appended with .npz if not specified in the filename
- to_imat_struct(Version=None, SetRecord=None, CreateDate: Optional[datetime] = None, ModifyDate: Optional[datetime] = None, OwnerName=None, AbscissaDataType=None, AbscissaTypeQual=None, AbscissaAxisLab=None, AbscissaUnitsLab=None, OrdNumDataType=None, OrdNumTypeQual=None, OrdDenDataType=None, OrdDenTypeQual=None, OrdinateAxisLab=None, OrdinateUnitsLab=None, ZAxisDataType=None, ZAxisTypeQual=None, ZGeneralValue=None, ZRPMValue=None, ZOrderValue=None, ZTimeValue=None, UserValue1=None, UserValue2=None, UserValue3=None, UserValue4=None, SamplingType=None, WeightingType=None, WindowType=None, AmplitudeUnits=None, Normalization=None, OctaveFormat=None, OctaveAvgType=None, ExpDampingFact=None, PulsesPerRev=None, MeasurementRun=None, LoadCase=None, IRIGTime=None)[source]
Creates a Matlab structure that can be read the IMAT toolbox.
This structure can be read by the IMAT toolbox in Matlab to create an imat_fn object. Note this is generally a faster function than to_imat_struct_array.
- Parameters
Version (TYPE, optional) – DESCRIPTION. The default is None.
SetRecord (TYPE, optional) – DESCRIPTION. The default is None.
CreateDate (datetime, optional) – DESCRIPTION. The default is None.
ModifyDate (datetime, optional) – DESCRIPTION. The default is None.
OwnerName (TYPE, optional) – DESCRIPTION. The default is None.
AbscissaDataType (TYPE, optional) – DESCRIPTION. The default is None.
AbscissaTypeQual (TYPE, optional) – DESCRIPTION. The default is None.
AbscissaAxisLab (TYPE, optional) – DESCRIPTION. The default is None.
AbscissaUnitsLab (TYPE, optional) – DESCRIPTION. The default is None.
OrdNumDataType (TYPE, optional) – DESCRIPTION. The default is None.
OrdNumTypeQual (TYPE, optional) – DESCRIPTION. The default is None.
OrdDenDataType (TYPE, optional) – DESCRIPTION. The default is None.
OrdDenTypeQual (TYPE, optional) – DESCRIPTION. The default is None.
OrdinateAxisLab (TYPE, optional) – DESCRIPTION. The default is None.
OrdinateUnitsLab (TYPE, optional) – DESCRIPTION. The default is None.
ZAxisDataType (TYPE, optional) – DESCRIPTION. The default is None.
ZAxisTypeQual (TYPE, optional) – DESCRIPTION. The default is None.
ZGeneralValue (TYPE, optional) – DESCRIPTION. The default is None.
ZRPMValue (TYPE, optional) – DESCRIPTION. The default is None.
ZOrderValue (TYPE, optional) – DESCRIPTION. The default is None.
ZTimeValue (TYPE, optional) – DESCRIPTION. The default is None.
UserValue1 (TYPE, optional) – DESCRIPTION. The default is None.
UserValue2 (TYPE, optional) – DESCRIPTION. The default is None.
UserValue3 (TYPE, optional) – DESCRIPTION. The default is None.
UserValue4 (TYPE, optional) – DESCRIPTION. The default is None.
SamplingType (TYPE, optional) – DESCRIPTION. The default is None.
WeightingType (TYPE, optional) – DESCRIPTION. The default is None.
WindowType (TYPE, optional) – DESCRIPTION. The default is None.
AmplitudeUnits (TYPE, optional) – DESCRIPTION. The default is None.
Normalization (TYPE, optional) – DESCRIPTION. The default is None.
OctaveFormat (TYPE, optional) – DESCRIPTION. The default is None.
OctaveAvgType (TYPE, optional) – DESCRIPTION. The default is None.
ExpDampingFact (TYPE, optional) – DESCRIPTION. The default is None.
PulsesPerRev (TYPE, optional) – DESCRIPTION. The default is None.
MeasurementRun (TYPE, optional) – DESCRIPTION. The default is None.
LoadCase (TYPE, optional) – DESCRIPTION. The default is None.
IRIGTime (TYPE, optional) – DESCRIPTION. The default is None.
- Returns
data_dict – DESCRIPTION.
- Return type
TYPE
- to_imat_struct_array(Version=1, SetRecord=0, CreateDate: Optional[datetime] = None, ModifyDate: Optional[datetime] = None, OwnerName='', AbscissaDataType=SpecificDataType.UNKNOWN, AbscissaTypeQual=TypeQual.TRANSLATION, AbscissaAxisLab='', AbscissaUnitsLab='', OrdNumDataType=SpecificDataType.UNKNOWN, OrdNumTypeQual=TypeQual.TRANSLATION, OrdDenDataType=SpecificDataType.UNKNOWN, OrdDenTypeQual=TypeQual.TRANSLATION, OrdinateAxisLab='', OrdinateUnitsLab='', ZAxisDataType=SpecificDataType.UNKNOWN, ZAxisTypeQual=TypeQual.TRANSLATION, ZGeneralValue=0, ZRPMValue=0, ZOrderValue=0, ZTimeValue=0, UserValue1=0, UserValue2=0, UserValue3=0, UserValue4=0, SamplingType='Dynamic', WeightingType='None', WindowType='None', AmplitudeUnits='Unknown', Normalization='Unknown', OctaveFormat=0, OctaveAvgType='None', ExpDampingFact=0, PulsesPerRev=0, MeasurementRun=0, LoadCase=0, IRIGTime='', verbose=False)[source]
Creates a Matlab structure that can be read the IMAT toolbox.
This structure can be read by the IMAT toolbox in Matlab to create an imat_fn object. Note this is generally a slower function than to_imat_struct.
- Parameters
Version (int, optional) – The version number of the function. The default is 1.
SetRecord (int, optional) – The set record of the function. The default is 0.
CreateDate (datetime, optional) – The date that the function was created. The default is Now.
ModifyDate (datetime, optional) – The date that the function was modified. The default is Now.
OwnerName (str, optional) – The owner of the dataset. The default is ‘’.
AbscissaDataType (SpecificDataType, optional) – The type of data associated with the Abscissa of the function. The default is SpecificDataType.UNKNOWN.
AbscissaTypeQual (TypeQual, optional) – The qualifier associated with the abscissa of the function. The default is TypeQual.TRANSLATION.
AbscissaAxisLab (str, optional) – String used to label the abscissa axis. The default is ‘’.
AbscissaUnitsLab (str, optional) – String used to label the units on the abscissa axis. The default is ‘’.
OrdNumDataType (SpecificDataType, optional) – The type of data associated with the numerator of the ordinate of the function. The default is SpecificDataType.UNKNOWN.
OrdNumTypeQual (TypeQual, optional) – The qualifier associated with the numerator of the ordinate of the function. The default is TypeQual.TRANSLATION.
OrdDenDataType (SpecificDataType, optional) – The type of data associated with the denominator of the ordinate of the function. The default is SpecificDataType.UNKNOWN.
OrdDenTypeQual (TypeQual, optional) – The qualifier associated with the denominator of the ordinate of the function. The default is TypeQual.TRANSLATION.
OrdinateAxisLab (str, optional) – String used to label the ordinate axis. The default is ‘’.
OrdinateUnitsLab (TYPE, optional) – String used to label the units on the ordinate axis. The default is ‘’.
ZAxisDataType (TYPE, optional) – DESCRIPTION. The default is SpecificDataType.UNKNOWN.
ZAxisTypeQual (TYPE, optional) – DESCRIPTION. The default is TypeQual.TRANSLATION.
ZGeneralValue (TYPE, optional) – DESCRIPTION. The default is 0.
ZRPMValue (TYPE, optional) – DESCRIPTION. The default is 0.
ZOrderValue (TYPE, optional) – DESCRIPTION. The default is 0.
ZTimeValue (TYPE, optional) – DESCRIPTION. The default is 0.
UserValue1 (TYPE, optional) – DESCRIPTION. The default is 0.
UserValue2 (TYPE, optional) – DESCRIPTION. The default is 0.
UserValue3 (TYPE, optional) – DESCRIPTION. The default is 0.
UserValue4 (TYPE, optional) – DESCRIPTION. The default is 0.
SamplingType (TYPE, optional) – DESCRIPTION. The default is ‘Dynamic’.
WeightingType (TYPE, optional) – DESCRIPTION. The default is ‘None’.
WindowType (TYPE, optional) – DESCRIPTION. The default is ‘None’.
AmplitudeUnits (TYPE, optional) – DESCRIPTION. The default is ‘Unknown’.
Normalization (TYPE, optional) – DESCRIPTION. The default is ‘Unknown’.
OctaveFormat (TYPE, optional) – DESCRIPTION. The default is 0.
OctaveAvgType (TYPE, optional) – DESCRIPTION. The default is ‘None’.
ExpDampingFact (TYPE, optional) – DESCRIPTION. The default is 0.
PulsesPerRev (TYPE, optional) – DESCRIPTION. The default is 0.
MeasurementRun (TYPE, optional) – DESCRIPTION. The default is 0.
LoadCase (TYPE, optional) – DESCRIPTION. The default is 0.
IRIGTime (TYPE, optional) – DESCRIPTION. The default is ‘’.
verbose (TYPE, optional) – DESCRIPTION. The default is False.
- Returns
output_struct – A numpy structured array that can be saved to a mat file using scipy.io.savemat.
- Return type
np.ndarray
- to_shape_array(abscissa_values=None)[source]
Converts an NDDataArray to a ShapeArray
- Parameters
abscissa_values (ndarray, optional) – Abscissa values at which the shapes will be created. The default is to create shapes at all abscissa values. If an entry in abscissa_values does not match a value in abscissa, the closest abscissa value will be selected
- Raises
ValueError – If the data does not have common abscissa across all functions or if duplicate response coordinates occur in the NDDataArray
- Returns
ShapeArray containing the NDDataArray’s ordinate as its shape_matrix
- Return type
- transform_coordinate_system(original_geometry, new_geometry, node_id_map=None, rotations=False)[source]
Performs coordinate system transformations on the data
- Parameters
original_geometry (Geometry) – The Geometry in which the shapes are currently defined
new_geometry (Geometry) – The Geometry in which the shapes are desired to be defined
node_id_map (id_map, optional) – If the original and new geometries do not have common node ids, an id_map can be specified to map the original geometry node ids to new geometry node ids. The default is None, which means no mapping will occur, and the geometries have common id numbers.
rotations (bool, optional) – If True, also transform rotational degrees of freedom. The default is False.
- Returns
A NDDataArray that can now be plotted with the new geometry
- Return type
NDDataArray or Subclass
- validate_common_abscissa(**allclose_kwargs)[source]
Returns True if all functions have the same abscissa
- Parameters
**allclose_kwargs (various) – Arguments to np.allclose to specify tolerances
- Returns
True if all functions have the same abscissa
- Return type
bool
- zero_pad(num_samples=0, update_abscissa=True, left=False, right=True, use_next_fast_len=False)[source]
Add zeros to the beginning or end of a signal
- Parameters
num_samples (int, optional) – Number of zeros to add to the function. If not specified, no zeros are added unless use_next_fast_len is True
update_abscissa (bool, optional) – If True, modify the abscissa to keep the same abscissa spacing. The function must have equally spaced abscissa for this to work. If False, the added abscissa will have a value of zero. The default is True.
left (bool, optional) – Add zeros to the left side (beginning) of the function. The default is False. If both left and right are specified, the zeros will be split half on the left and half on the right.
right (bool, optional) – Add zeros to the right side (end) of the function. The default is True. If both left and right are specified, the zeros will be split half on the left and half on the right
use_next_fast_len (bool, optional) – If True, potentially add additional zeros to the value specified by num_samples to allow the total length of the final signal to reach fast values for FFT as specified by scipy.fft.next_fast_len.
- Returns
The zero-padded version of the function
- Return type
NDDataArray subclass