SOFA: http://www.sofaconventions.org/
Example file from https://depositonce.tu-berlin.de/handle/11303/245.2, also available at http://sofacoustics.org/data/database/tuburo/.
This is only about reading files, creating and writing to SOFA files is beyond the scope of this page.
scipy.io.netcdf (v0.18) doesn't support NetCDF4.
http://docs.scipy.org/doc/scipy/reference/generated/scipy.io.netcdf.netcdf_file.html
from scipy.io import netcdf_file
try:
netcdf_file('RIR_AllAbsorbers_ArrayCentre_Emitters1to64.sofa')
except Exception as e:
print(e)
Error: RIR_AllAbsorbers_ArrayCentre_Emitters1to64.sofa is not a valid NetCDF 3 file
import scipy
scipy.__version__
'1.10.1'
based on Scientific.IO.NetCDF API
Debian package python3-netcdf4
http://unidata.github.io/netcdf4-python/
https://github.com/Unidata/netcdf4-python
http://nbviewer.ipython.org/github/Unidata/netcdf4-python/blob/master/examples/reading_netCDF.ipynb
http://nbviewer.ipython.org/github/Unidata/netcdf4-python/blob/master/examples/writing_netCDF.ipynb
import netCDF4
f = netCDF4.Dataset('RIR_AllAbsorbers_ArrayCentre_Emitters1to64.sofa')
f
<class 'netCDF4._netCDF4.Dataset'> root group (NETCDF4 data model, file format HDF5): Conventions: SOFA Version: 1.0 SOFAConventions: GeneralFIRE SOFAConventionsVersion: 1.0 APIName: ARI SOFA API for Matlab/Octave APIVersion: 1.1.1 ApplicationName: Matlab ApplicationVersion: R2013a AuthorContact: vera.erbes@uni-rostock.de Comment: RIR measurements of 64-channel loudspeaker array at University of Rostock. DataType: FIRE History: Converted from the TU Berlin/University of Rostock format Upgraded from SOFA 0.6 License: Creative Commons Attribution-NonCommercial-ShareAlike 4.0 Organization: University of Rostock, Institute of Communications Engineering References: V. Erbes, M. Geier, S. Weinzierl and S. Spors (2015): Database of single-channel and binaural room impulse responses of a 64-channel loudspeaker array. Proc. of the 138th AES Conv., Warsaw, Poland RoomType: shoebox Origin: Acoustically measured with omnidirectional microphone DateCreated: 2014-12-01 13:50:46 DateModified: 2020-04-02 09:36:39 Title: Rostock RIR audio lab, broadband absorbers on walls and ceiling, listener in centre of array RoomDescription: University of Rostock, INT Audio Lab, Room 8202, broadband absorbers on walls and ceiling, mid-frequency reverberation time = 0.32 s ListenerDescription: iSEMcon EMX-7150 EmitterDescription: Neumann KH 120 A DatabaseName: Multichannel RIRs University of Rostock ListenerShortName: OmniMic SourceDescription: 64-channel loudspeaker array dimensions(sizes): I(1), C(3), R(1), E(64), N(44100), M(1), S(0) variables(dimensions): float64 ListenerPosition(I, C), float64 ReceiverPosition(R, C, I), float64 SourcePosition(I, C), float64 EmitterPosition(E, C, I), float64 SourceUp(I, C), float64 SourceView(I, C), float64 EmitterUp(E, C, I), float64 EmitterView(E, C, I), float64 RoomCornerA(I, C), float64 RoomCornerB(I, C), float64 Data.IR(M, R, E, N), float64 Data.SamplingRate(I), float64 Data.Delay(I, R, E) groups:
f.variables
{'ListenerPosition': <class 'netCDF4._netCDF4.Variable'> float64 ListenerPosition(I, C) Type: cartesian Units: metre unlimited dimensions: current shape = (1, 3) filling on, default _FillValue of 9.969209968386869e+36 used, 'ReceiverPosition': <class 'netCDF4._netCDF4.Variable'> float64 ReceiverPosition(R, C, I) Type: cartesian Units: metre unlimited dimensions: current shape = (1, 3, 1) filling on, default _FillValue of 9.969209968386869e+36 used, 'SourcePosition': <class 'netCDF4._netCDF4.Variable'> float64 SourcePosition(I, C) Type: cartesian Units: metre unlimited dimensions: current shape = (1, 3) filling on, default _FillValue of 9.969209968386869e+36 used, 'EmitterPosition': <class 'netCDF4._netCDF4.Variable'> float64 EmitterPosition(E, C, I) Type: cartesian Units: metre unlimited dimensions: current shape = (64, 3, 1) filling on, default _FillValue of 9.969209968386869e+36 used, 'SourceUp': <class 'netCDF4._netCDF4.Variable'> float64 SourceUp(I, C) unlimited dimensions: current shape = (1, 3) filling on, default _FillValue of 9.969209968386869e+36 used, 'SourceView': <class 'netCDF4._netCDF4.Variable'> float64 SourceView(I, C) Type: cartesian Units: metre unlimited dimensions: current shape = (1, 3) filling on, default _FillValue of 9.969209968386869e+36 used, 'EmitterUp': <class 'netCDF4._netCDF4.Variable'> float64 EmitterUp(E, C, I) unlimited dimensions: current shape = (64, 3, 1) filling on, default _FillValue of 9.969209968386869e+36 used, 'EmitterView': <class 'netCDF4._netCDF4.Variable'> float64 EmitterView(E, C, I) Type: cartesian Units: metre unlimited dimensions: current shape = (64, 3, 1) filling on, default _FillValue of 9.969209968386869e+36 used, 'RoomCornerA': <class 'netCDF4._netCDF4.Variable'> float64 RoomCornerA(I, C) Type: cartesian Units: metre unlimited dimensions: current shape = (1, 3) filling on, default _FillValue of 9.969209968386869e+36 used, 'RoomCornerB': <class 'netCDF4._netCDF4.Variable'> float64 RoomCornerB(I, C) Type: cartesian Units: metre unlimited dimensions: current shape = (1, 3) filling on, default _FillValue of 9.969209968386869e+36 used, 'Data.IR': <class 'netCDF4._netCDF4.Variable'> float64 Data.IR(M, R, E, N) unlimited dimensions: current shape = (1, 1, 64, 44100) filling on, default _FillValue of 9.969209968386869e+36 used, 'Data.SamplingRate': <class 'netCDF4._netCDF4.Variable'> float64 Data.SamplingRate(I) Units: hertz unlimited dimensions: current shape = (1,) filling on, default _FillValue of 9.969209968386869e+36 used, 'Data.Delay': <class 'netCDF4._netCDF4.Variable'> float64 Data.Delay(I, R, E) unlimited dimensions: current shape = (1, 1, 64) filling on, default _FillValue of 9.969209968386869e+36 used}
var = f.variables['Data.IR']
var
<class 'netCDF4._netCDF4.Variable'> float64 Data.IR(M, R, E, N) unlimited dimensions: current shape = (1, 1, 64, 44100) filling on, default _FillValue of 9.969209968386869e+36 used
data = var[0, 0]
data.shape
(64, 44100)
f.close()
netCDF4.__version__
'1.6.4'
netCDF4.__netcdf4libversion__
'4.9.3-development'
netCDF4.__hdf5libversion__
'1.12.2'
ScientificPython (not to be confused with SciPy!)
http://dirac.cnrs-orleans.fr/plone/software/scientificpython
https://bitbucket.org/khinsen/scientificpython
Only for Python 2, no Python 3 support?
Example:
from Scientific.IO.NetCDF import NetCDFFile
f = NetCDFFile('RIR_AllAbsorbers_ArrayCentre_Emitters1to64.sofa')
var = f.variables['Data.IR']
var.typecode() # 'd'
data = var.getValue()
data.shape # (1, 1, 64, 44100)
Open SOFA file as HDF5 (there are a lot of warnings but it seems to work)
import tables
f = tables.open_file('RIR_AllAbsorbers_ArrayCentre_Emitters1to64.sofa')
#f
#f.root
It's impossible to get Data.IR
by attribute access because sadly it contains a period.
var = f.get_node('/Data.IR')
var
/home/mg/git/.venv/lib/python3.11/site-packages/tables/attributeset.py:290: DataTypeWarning: Unsupported type for attribute 'DIMENSION_LIST' in node 'Data.IR'. Offending HDF5 class: 9 value = self._g_getattr(self._v_node, name)
/Data.IR (CArray(1, 1, 64, 44100)shuffle, zlib(1)) '' atom := Float64Atom(shape=(), dflt=9.969209968386869e+36) maindim := 0 flavor := 'numpy' byteorder := 'little' chunkshape := (1, 1, 32, 22050)
CArray
$\to$ chunked array
var.dtype
dtype('float64')
var.shape
(1, 1, 64, 44100)
data = var[0, 0]
type(data)
numpy.ndarray
f.close()
tables.__version__
'3.9.0'
import h5py
f = h5py.File('RIR_AllAbsorbers_ArrayCentre_Emitters1to64.sofa')
f
<HDF5 file "RIR_AllAbsorbers_ArrayCentre_Emitters1to64.sofa" (mode r)>
f.attrs['Conventions']
b'SOFA'
f.attrs['SOFAConventions']
b'GeneralFIRE'
f.attrs['RoomType']
b'shoebox'
var = f['Data.IR']
var
<HDF5 dataset "Data.IR": shape (1, 1, 64, 44100), type "<f8">
data = var[0, 0]
type(data)
numpy.ndarray
f.close()
h5py.__version__
'3.9.0'
Uses the h5py
module (see above). The NetCDF4 C library is not needed.
import h5netcdf
f = h5netcdf.File('RIR_AllAbsorbers_ArrayCentre_Emitters1to64.sofa', 'r')
f
<h5netcdf.File 'RIR_AllAbsorbers_ArrayCentre_Emitters1to64.sofa' (mode r)> Dimensions: I: <h5netcdf.Dimension 'I': size 1> C: <h5netcdf.Dimension 'C': size 3> R: <h5netcdf.Dimension 'R': size 1> E: <h5netcdf.Dimension 'E': size 64> N: <h5netcdf.Dimension 'N': size 44100> M: <h5netcdf.Dimension 'M': size 1> S: <h5netcdf.Dimension 'S': size 0 (unlimited)> Groups: Variables: ListenerPosition: ('I', 'C') float64 ReceiverPosition: ('R', 'C', 'I') float64 SourcePosition: ('I', 'C') float64 EmitterPosition: ('E', 'C', 'I') float64 SourceUp: ('I', 'C') float64 SourceView: ('I', 'C') float64 EmitterUp: ('E', 'C', 'I') float64 EmitterView: ('E', 'C', 'I') float64 RoomCornerA: ('I', 'C') float64 RoomCornerB: ('I', 'C') float64 Data.IR: ('M', 'R', 'E', 'N') float64 Data.SamplingRate: ('I',) float64 Data.Delay: ('I', 'R', 'E') float64 Attributes: Conventions: 'SOFA' Version: '1.0' SOFAConventions: 'GeneralFIRE' SOFAConventionsVersion: '1.0' APIName: 'ARI SOFA API for Matlab/Octave' APIVersion: '1.1.1' ApplicationName: 'Matlab' ApplicationVersion: 'R2013a' AuthorContact: 'vera.erbes@uni-rostock.de' Comment: 'RIR measurements of 64-channel loudspeaker array at University of Rostock.' DataType: 'FIRE' History: 'Converted from the TU Berlin/University of Rostock format\nUpgraded from SOFA 0.6' License: 'Creative Commons Attribution-NonCommercial-ShareAlike 4.0' Organization: 'University of Rostock, Institute of Communications Engineering' References: 'V. Erbes, M. Geier, S. Weinzierl and S. Spors (2015): Database of single-channel and binaural room impulse responses of a 64-channel loudspeaker array. Proc. of the 138th AES Conv., Warsaw, Poland' RoomType: 'shoebox' Origin: 'Acoustically measured with omnidirectional microphone' DateCreated: '2014-12-01 13:50:46' DateModified: '2020-04-02 09:36:39' Title: 'Rostock RIR audio lab, broadband absorbers on walls and ceiling, listener in centre of array' RoomDescription: 'University of Rostock, INT Audio Lab, Room 8202, broadband absorbers on walls and ceiling, mid-frequency reverberation time = 0.32 s' ListenerDescription: 'iSEMcon EMX-7150' EmitterDescription: 'Neumann KH 120 A' DatabaseName: 'Multichannel RIRs University of Rostock' ListenerShortName: 'OmniMic' SourceDescription: '64-channel loudspeaker array'
var = f['Data.IR']
var
<h5netcdf.Variable '/Data.IR': dimensions ('M', 'R', 'E', 'N'), shape (1, 1, 64, 44100), dtype float64> Attributes:
data = var[0, 0]
type(data)
numpy.ndarray
f.close()
h5netcdf.__version__
'1.2.0'