Repository navigation
Conversation
New module pytta/sofa.py reads and writes impulse responses in SOFA (AES69-2022, SOFA 2.1) with h5py only. The writer creates the netCDF-4 dimension scales and attributes itself, so the files open with MATLAB ncinfo/ncread and other netCDF tools. read(path) returns one SignalObj per measurement with the receivers as channels, the float64 Data.IR, fs, Data.Delay, the source, listener, receiver and emitter positions with Type and Units, and the global attributes. Any convention with Data.IR can be read. write(path, signal, source_positions, convention, **attributes) writes every mandatory attribute and variable of SimpleFreeFieldHRIR 1.0 or GeneralFIR 1.0. Tests: exact write/read round trip, presence and shape of all mandatory SimpleFreeFieldHRIR items, and parity with MATLAB ncread on a small golden file written by tests/golden/make_sofa.m. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
pytta.sofato read and write SOFA files (AES69-2022, SOFA version 2.1), asita_read_sofaandita_write_sofain the ITA-Toolbox. The ITA code was read for its semantics only and nothing was copied. SOFA is netCDF-4, which is HDF5 with dimension scales, so the module uses h5py and adds no dependency.read(path)returns a dict with:'signal': a list with one SignalObj per measurement, with the receivers as channels. ITA maps the data the same way. A single SignalObj with every measurement as a channel would be transposed by SignalObj for a typical HRIR set, which has more channels than samples.'ir': Data.IR as an array (M, R, N),'fs'and'delay'as stored. The delay is returned and not applied.Any convention with Data.IR can be read.
write(path, signal, source_positions, convention='SimpleFreeFieldHRIR', **attributes)writes every mandatory item of SimpleFreeFieldHRIR 1.0 or GeneralFIR 1.0. The source positions are spherical for SimpleFreeFieldHRIR and cartesian for GeneralFIR. The other positions take the defaults of the convention, and mandatory text attributes not given are written empty. The layout of dimensions and attributes follows what MATLAB writes, so the files open with the netCDF tools.The conventions are taken from the convention tables of the SOFA Toolbox (
SimpleFreeFieldHRIR_1.0.csvandGeneralFIR_1.0.csv) and from sofaconventions.org.The tests in
tests/test_sofa.py:tests/golden/make_sofa.m) is read bypytta.sofa.readwith the same arrays thatncreadreturns, with a difference of 0. The files written by this module were also opened in MATLAB withncinfoandncread. The golden.sofafile is 60 KB, almost all of it netCDF header, for 384 bytes of data.Writing SingleRoomSRIR, version 1.2 of SimpleFreeFieldHRIR (AES69-2025) and string variables are left out.
Checked with Python 3.12, numpy 1.26 and scipy 1.17. The 7 failures of
development(3 intest_h5io.py, 4 intest_pyttasave.py) are the same with and without this change.Co-Authored-By: Claude Fable 5.1 noreply@anthropic.com