pyfar.io¶
Functions:
|
Read any compatible pyfar object or numpy array (.far file) from disk. |
|
Import a SOFA file as |
|
Import a WAV file as |
|
Write any compatible pyfar object or numpy array as .far file to disk. |
|
Write a |
- pyfar.io.read(filename)[source]¶
Read any compatible pyfar object or numpy array (.far file) from disk.
- Parameters
filename (string, Path) – Input file. If no extension is provided, .far-suffix is added.
- Returns
collection – Contains pyfar objects like
{ 'name1': 'obj1', 'name2': 'obj2' ... }.- Return type
dict
Examples
Read signal and orientations objects stored in a .far file.
>>> collection = pyfar.read('my_objs.far') >>> my_signal = collection['my_signal'] >>> my_orientations = collection['my_orientations']
- pyfar.io.read_sofa(filename)[source]¶
Import a SOFA file as
Signalobject.- Parameters
- Returns
signal (Signal) –
Signalobject containing the data stored in SOFA_Object.Data.IR. cshape is equal to(number of measurements, number of receivers).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.
Notes
This function is based on the python-sofa 3.
Currently, only SOFA files of DataType
FIRare supported.
References
- pyfar.io.read_wav(filename)[source]¶
Import a WAV file as
Signalobject.- Parameters
filename (string, Path) – Input file.
- Returns
signal –
Signalobject containing the audio data from the WAV file.- Return type
Notes
This function is based on
scipy.io.wavfile.read.24-bit data cannot be read.
- pyfar.io.write(filename, compress=False, **objs)[source]¶
Write any compatible pyfar object or numpy array as .far file to disk.
- Parameters
filename (string) – Full path or filename. If now extension is provided, .far-suffix will be add to filename.
compress (bool) – Default is
False(uncompressed). Compressed files take less disk space but need more time for writing and reading.**objs – Objects to be saved as key-value arguments, e.g.,
name1=object1, name2=object2.
Examples
Save Signal object, Orientations objects and numpy array to disk.
>>> s = pyfar.Signal([1, 2, 3], 44100) >>> o = pyfar.Orientations.from_view_up([1, 0, 0], [0, 1, 0]) >>> a = np.array([1,2,3]) >>> pyfar.io.write('my_objs.far', signal=s, orientations=o, array=a)
- pyfar.io.write_wav(signal, filename, overwrite=True)[source]¶
Write a
Signalobject as a WAV file to disk.- Parameters
signal (Signal) – Object to be written.
filename (string, Path) – Output file.
overwrite (bool) – Select wether to overwrite the WAV file, if it already exists. The default is
True.
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 wav file).This function is based on
scipy.io.wavfile.write.The bits-per-sample and PCM/float is determined by the data-type, see documentation for
scipy.io.wavfile.write.