A Signal object is returned is the DataType is 'FIR',
'FIR-E', or 'FIRE'. In case of 'FIR-E', the time data
is returned with the cshape EMRN (samples are in the last
dimension) and not MRNE as in the SOFA standard (emitters are in
the last dimension).
A FrequencyData object is returned is the DataType is 'TF',
'TF-E', or 'TFE'. In case of 'TF-E', the frequency data
is returned with the cshape EMRN (frequencies are in the last
dimension) and not MRNE as in the SOFA standard (emitters are in
the last dimension).
The cshape of the object is is (M,R) with M being the number
of measurements and R being the number of receivers from the SOFA
file.
source_coordinates (Coordinates) – Coordinates object containing the data stored in
SOFA_object.SourcePosition. The domain, convention and unit are
automatically matched.
receiver_coordinates (Coordinates) – Coordinates object containing the data stored in
SOFA_object.RecevierPosition. The domain, convention and unit are
automatically matched.
Reads ‘wav’, ‘aiff’, ‘ogg’, ‘flac’, and ‘mp3’ files among others. For a
complete list see audio_formats.
Parameters:
filename (string, Path) – Input file.
dtype ({'float64', 'float32', 'int32', 'int16'}, optional) – Data type to which the data in the wav file is casted, by default
'float64'. Floating point audio data is typically in the range from
-1.0 to 1.0. Note that 'int16' and 'int32' should only
be used if the data was written in the same format. Integer data is in
the range from -2**15 to 2**15-1 for 'int16' and from
-2**31 to 2**31-1 for 'int32'. In any case, the data is
converted to float.
**kwargs – Other keyword arguments to be passed to soundfile.read. This
is needed, e.g, to read RAW audio files.
Reading int values from a float file will not scale the data to
[-1.0, 1.0). If the file contains np.array([42.6],dtype='float32'),
you will read np.array([43],dtype='int32') for dtype='int32'.
The data is created by defining at least one Expression within a
Data node in Comsol’s Results/Export section. The data format
needs to be Spreadsheet. This function supports several Expressions
as well as results for Parametric Sweeps.
For more information see
read_comsol_header.
Parameters:
filename (str, Path) – Input file. Excepted input files are .txt, .dat and .csv. .csv-
files are strongly recommended, since .txt and .dat-files vary in their
format definitions.
expressions (list of strings, optional) – This parameter defines which parts of the COMSOL data is
returned as a pyfar FrequencyData or TimeData object. By default, all
expressions are returned. COMSOL terminology is used, e.g.,
expressions=['pabe.p_t'].
Further information and a list of all expressions can be obtained with
read_comsol_header.
parameters (dict, optional) – COMSOL supports Parametric Sweeps to vary certain parameters in a
sequence of simulations. The parameters dict contains the parameters
and the their values that are to be returned.
For example, in a study with a varying angle, the dict could be
parameters={'theta':[0.0,0.7854],'phi':[0.,1.5708]}.
A list of all parameters included in a file can be obtained with
read_comsol_header. The default is None, which
means all parameters are included.
Returns:
data (FrequencyData, TimeData) – Returns a TimeData or FrequencyData object depending the domain of the
input data. The output has the cshape (#points, #expressions,
#parameter1, #parameter2, …). In case of missing parameter value
combinations in the input, the missing data is filled with nans.
If the input does not include parameters, the cshape is just
(#points, #expressions).
coordinates (Coordinates) – Evaluation points extracted from the input file as Coordinates object.
The coordinate system is always cartesian. If the input dimension is
lower than three, missing dimensions are filled with zeros.
If the input file does not include evaluation points (e.g., in case of
non-local datasets such as averages or integrals) no coordinates are
returned.
Examples
Assume a Pressure Acoustics BEM Simulation (named “pabe” in COMSOL) for
two frequencies including a Parametric Sweep with All Combinations of
certain incident angles theta and phi for the incident sound wave.
The sound pressure (“p_t”) is exported to a file comsol_sample.csv.
Read the data including all parameter combinations.
>>> data,coordinates=pf.io.read_comsol('comsol_sample.csv')>>> dataFrequencyData:(8, 1, 5, 4) channels with 2 frequencies>>> coordinates1D Coordinates object with 8 points of cshape (8,)domain: cart, convention: right, unit: metcoordinates: x in meters, y in meters, z in metersDoes not contain sampling weights
Read header information on exported data from COMSOL Multiphysics.
Note
The data is created by defining at least one Expression within a
Data node in Comsol’s Results/Export section. The data format
needs to be Spreadsheet. This function supports several Expressions
as well as results for Parametric Sweeps.
For more information see below.
Parameters:
filename (str, Path) – Input file. Excepted input files are .txt, .dat and .csv. .csv-
files are strongly recommended, since .txt and .dat-files vary in their
format definitions.
Returns:
expressions (list of strings) – When exporting data in COMSOL, certain Expressions need to be
specified that define the physical quantities to be exported. This
function returns the expressions as a list, e.g.,
expressions=['pabe.p_t'].
units (list of strings) – List of the units corresponding to expressions, e.g.,
units=['Pa'].
parameters (dict) – COMSOL supports Parametric Sweeps to vary certain parameters in a
sequence of simulations. This function returns the parameters
and the parameter values as a dict. For example, in a study with a
varying angle, the dict could be parameters={'theta':[0.0,0.7854],'phi':[0.,1.5708]}. If the input does not include parameters, an
emtpy dict is returnd. Note that the dict is same for
All Combinations and Specific Combinations of parameters as a
distinction is not possible due to the data format.
domain (string) – Domain of the input data. Only time domain ('time') or
frequency domain ('freq') simulations are supported.
domain_data (list) – List containing the sampling times or frequency bins depending
on the domain of the data in the input file.
Examples
Assume a Pressure Acoustics BEM Simulation (named “pabe” in COMSOL) for
two frequencies 100 Hz and 500 Hz including a Parametric Sweep of certain
incident angles theta and phi for the incident sound wave. The sound
pressure (“p_t”) is exported to a file comsol_sample.csv.
verify (bool, optional) – Verify if the data contained in the SOFA file agrees with the AES69
standard (see references). If the verification fails, the SOFA file
can be loaded by setting verify=False. The default is True
verbose (bool, optional) – Print the names of detected custom variables and attributes.
The default is True.
Returns:
audio (pyfar audio object) – The audio object that is returned depends on the DataType of the SOFA
object:
A FrequencyData object is returned is the DataType is 'TF',
'TF-E', or 'TFE'.
The cshape of the object is is (M,R) with M being the number
of measurements and R being the number of receivers from the SOFA
file.
source_coordinates (Coordinates) – Coordinates object containing the data stored in
SOFA_object.SourcePosition. The domain, convention and unit are
automatically matched.
receiver_coordinates (Coordinates) – Coordinates object containing the data stored in
SOFA_object.ReceiverPosition. The domain, convention and unit are
automatically matched.
Notes
This function uses the sofar package to read SOFA files [4].
filename (string, Path) – Output file. The format is determined from the file extension.
See audio_formats for all possible formats.
subtype (str, optional) – The subtype of the sound file, the default value depends on the
selected format (see default_audio_subtype).
See audio_subtypes for all possible subtypes for
a given format.
overwrite (bool) – Select wether to overwrite the audio file, if it already exists.
The default is True.
**kwargs – Other keyword arguments to be passed to soundfile.write.
Notes
Signals are flattened before writing to disk (e.g. a signal with
cshape=(3,2) will be written to disk as a six channel audio file).