-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrite_verification_rules.py
356 lines (347 loc) · 13.5 KB
/
write_verification_rules.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
"""
Write rules for validating SOFA files to json files.
Writes the following json files:
rules.json
Rules for verifying SOFA conventions and files
unit_aliases.json
Allowed aliases for the standard units
For a more detailed information about the json files refer to _readme.txt
"""
# %%
import json
import os
from sofar.utils import _get_conventions
# deprecations
# NOTE: no further specific tests are enforced for deprecated conventions,
# i.e., there are no entries in `rules` for them.
deprecations = {
"GLOBAL:SOFAConventions": {
"GeneralFIRE":"GenerelFIR-E",
"MultiSpeakerBRIR": "SingleRoomMIMOSRIR",
"MusicalInstrumentDirectivityTF": "FreeFieldDirectivityTF",
"SimpleBRIR": "SingleRoomSRIR",
"SingleRoomDRIR": "SingleRoomSRIR",
"SimpleFreeFieldDirectivityTF": "FreeFieldDirectivityTF",
"SimpleFreeFieldSOS": "SimpleFreeFieldHRSOS",
"SimpleFreeFieldTF": "SimpleFreeFieldHRTF",
"SingleTrackedAudio":
"AnnotatedEmitterAudio or AnnotatedReceiverAudio",
},
}
# definition of valid coordinate systems. Not defined explicitly in AES69 but
# dozens of mentions of the following:
coords_min = ["cartesian", "spherical"]
coords_full = coords_min + ["spherical harmonics"]
# definition of units acordings to AES69 Table 7
units_min = ["metre", "degree, degree, metre"]
units_full = units_min + [units_min[1]]
# allowed alternative versions of units
# NOTE: AES69 allows multi-unit strings to be separated by comma, comma plus
# space and space (AES69 Section 4.7.8). This means that the unit
# "cubic metre" will be tested as a multi unit string and is thus also
# split in the aliases. A separate test for verifying that "cubic" is
# followed be "metre" must be performed.
unit_aliases = {
"metre": "metre",
"metres": "metre",
"meter": "metre",
"meters": "metre",
"cubic": "cubic",
"degree": "degree",
"degrees": "degree",
"second": "second",
"seconds": "second",
}
# possible values for restricted dimensions in the API
# Dimensions for spherical harmonics (considering orders up to 100) according
# to AES69 Eq. (5) and (6)
sh_dimension = ([(N+1)**2 for N in range(100)],
"(N+1)**2 where N is the spherical harmonics order")
# Dimensions for SOS (considering up to 100 sections) according to AES69
# Appendix C.5.2
sos_dimension = ([6 * (N + 1) for N in range(100)],
"an integer multiple of 6 greater 0")
# verification rules
rules = {
# Global --------------------------------------------------------------
# Check value of GLOBAL_DataType (AES69 Annex C)
# (FIRE and TFE are legacy data types from SOFA version 1.0)
"GLOBAL:DataType": {
"value": ["Audio", "FIR", "FIR-E", "FIRE", "TF", "TF-E", "SOS"],
"specific": {
"Audio": {
"Data.SamplingRate": None,
"Data.SamplingRate:Units": ["hertz"]},
"FIR": {
"Data.IR": None,
"Data.Delay": None,
"Data.SamplingRate": None,
"Data.SamplingRate:Units": ["hertz"]},
"FIR-E": {
"Data.IR": None,
"Data.Delay": None,
"Data.SamplingRate": None,
"Data.SamplingRate:Units": ["hertz"]},
"FIRE": {
"Data.IR": None,
"Data.Delay": None,
"Data.SamplingRate": None,
"Data.SamplingRate:Units": ["hertz"]},
"TF": {
"Data.Real": None,
"Data.Imag": None,
"N": None,
"N:Units": ["hertz"]},
"TF-E": {
"Data.Real": None,
"Data.Imag": None,
"N": None,
"N:Units": ["hertz"]},
"TFE": {
"Data.Real": None,
"Data.Imag": None,
"N": None,
"N:Units": ["hertz"]},
"SOS": {
"Data.SOS": None,
"Data.Delay": None,
"Data.SamplingRate": None,
"Data.SamplingRate:Units": ["hertz"],
# Checking the dimension of N if having SOS data
# (assuming up to 100 second order sections)
"_dimensions": {
"N": {
"value": sos_dimension[0],
"value_str": sos_dimension[1]},
}}}},
# Specified in AES69 Section 4.7.7 and Table 6
"GLOBAL:RoomType": {
"value": ["free field", "reverberant", "shoebox", "dae"],
"specific": {
"reverberant": {
"GLOBAL:RoomDescription": None},
"shoebox": {
"RoomCornerA": None,
"RoomCornerB": None},
"dae": {
"GLOBAL:RoomGeometry": None}}},
# Specified in AES69 Annex D
"GLOBAL:SOFAConventions": {
"value": _get_conventions(return_type="name"),
"specific": {
"AnnotatedEmitterAudio": {
"Data.Emitter": None},
"AnnotatedReceiverAudio": {
"Data.Receiver": None},
"GeneralFIR": {
"GLOBAL:DataType": ["FIR"]},
"GeneralFIR-E": {
"GLOBAL:DataType": ["FIR-E"]},
"GeneralTF": {
"GLOBAL:DataType": ["TF"]},
"GeneralTF-E": {
"GLOBAL:DataType": ["TF-E"]},
"SimpleFreeFieldHRIR": {
"GLOBAL:DataType": ["FIR"],
"GLOBAL:RoomType": ["free field"],
"EmitterPosition:Type": coords_min,
"_dimensions": {
"E": {
"value": [1],
"value_str": "1"}}},
"SimpleFreeFieldHRTF": {
"GLOBAL:DataType": ["TF"],
"GLOBAL:RoomType": ["free field"],
"EmitterPosition:Type": coords_min,
"_dimensions": {
"E": {
"value": [1],
"value_str": "1"}}},
"SimpleFreeFieldHRSOS": {
"GLOBAL:DataType": ["SOS"],
"GLOBAL:RoomType": ["free field"],
"EmitterPosition:Type": coords_min,
"_dimensions": {
"E": {
"value": [1],
"value_str": "1"}}},
"FreeFieldHRIR": {
"GLOBAL:DataType": ["FIR-E"],
"GLOBAL:RoomType": ["free field"]},
"FreeFieldHRTF": {
"GLOBAL:DataType": ["TF-E"],
"GLOBAL:RoomType": ["free field"]},
"SimpleHeadphoneIR": {
"GLOBAL:DataType": ["FIR"]},
"SingleRoomSRIR": {
"GLOBAL:DataType": ["FIR"]},
"SingleRoomMIMOSRIR": {
"GLOBAL:DataType": ["FIR-E"]},
"FreeFieldDirectivityTF": {
"GLOBAL:DataType": ["TF"]}}},
# check NLongName (AES69 Tables C.3 and C.4)
"N:LongName": {
"value": ["frequency"]},
# Listener ------------------------------------------------------------
# Possible values and dependencies are specified in
# AES69 Section 4.7.3
# ---------------------------------------------------------------------
# Check values and consistency of if ListenerPosition Type and Unit
"ListenerPosition:Type": {
"value": coords_min,
"specific": {
coords_min[0]: {
"ListenerPosition:Units": [units_min[0]]},
coords_min[1]: {
"ListenerPosition:Units": [units_min[1]]},
}},
# Check if dependencies of ListenerView are contained
"ListenerView": {
"value": None,
"general": ["ListenerView:Type", "ListenerView:Units"]},
# Check values and consistency of if ListenerView Type and Unit
"ListenerView:Type": {
"value": coords_min,
"specific": {
coords_min[0]: {
"ListenerView:Units": [units_min[0]]},
coords_min[1]: {
"ListenerView:Units": [units_min[1]]},
}},
# Check if dependencies of ListenerUp are contained
"ListenerUp": {
"value": None,
"general": ["ListenerView"]},
# Receiver ------------------------------------------------------------
# Possible values and dependencies are specified in
# AES69 Section 4.7.4
# ---------------------------------------------------------------------
# Check values and consistency of if ReceiverPosition Type and Unit
"ReceiverPosition:Type": {
"value": coords_full,
"specific": {
coords_full[0]: {
"ReceiverPosition:Units": [units_full[0]]},
coords_full[1]: {
"ReceiverPosition:Units": [units_full[1]]},
coords_full[2]: {
"ReceiverPosition:Units": [units_full[2]],
"_dimensions": {
# Check dimension R if using spherical harmonics for the
# receiver (assuming SH orders < 100)
"R": {
"value": sh_dimension[0],
"value_str": sh_dimension[1]}}},
}},
# Check if dependencies of ReceiverView are contained
"ReceiverView": {
"value": None,
"general": ["ReceiverView:Type", "ReceiverView:Units"]},
# Check values and consistency of if ReceiverView Type and Unit
"ReceiverView:Type": {
"value": coords_min,
"specific": {
coords_min[0]: {
"ReceiverView:Units": [units_min[0]]},
coords_min[1]: {
"ReceiverView:Units": [units_min[1]]},
}},
# Check if dependencies of ReceiverUp are contained
"ReceiverUp": {
"value": None,
"general": ["ReceiverView"]},
# Source --------------------------------------------------------------
# Possible values and dependencies are specified in
# AES69 Section 4.7.5
# ---------------------------------------------------------------------
# Check values and consistency of if SourcePosition Type and Unit
"SourcePosition:Type": {
"value": coords_min,
"specific": {
coords_min[0]: {
"SourcePosition:Units": [units_min[0]]},
coords_min[1]: {
"SourcePosition:Units": [units_min[1]]},
}},
# Check if dependencies of SourceView are contained
"SourceView": {
"value": None,
"general": ["SourceView:Type", "SourceView:Units"]},
# Check values and consistency of if SourceView Type and Unit
"SourceView:Type": {
"value": coords_min,
"specific": {
coords_min[0]: {
"SourceView:Units": [units_min[0]]},
coords_min[1]: {
"SourceView:Units": [units_min[1]]},
}},
# Check if dependencies of SourceUp are contained
"SourceUp": {
"value": None,
"general": ["SourceView"]},
# Emitter -------------------------------------------------------------
# Possible values and dependencies are specified in
# AES69 Section 4.7.6
# ---------------------------------------------------------------------
# Check values and consistency of if EmitterPosition Type and Unit
"EmitterPosition:Type": {
"value": coords_full,
"specific": {
coords_full[0]: {
"EmitterPosition:Units": [units_full[0]]},
coords_full[1]: {
"EmitterPosition:Units": [units_full[1]]},
coords_full[2]: {
"EmitterPosition:Units": [units_full[2]],
"_dimensions": {
# Check dimension R if using spherical harmonics for the
# receiver (assuming SH orders < 100)
"E": {
"value": sh_dimension[0],
"value_str": sh_dimension[1]}}},
}},
# Check if dependencies of EmitterView are contained
"EmitterView": {
"value": None,
"general": ["EmitterView:Type", "EmitterView:Units"]},
# Check values and consistency of if EmitterView Type and Unit
"EmitterView:Type": {
"value": coords_min,
"specific": {
coords_min[0]: {
"EmitterView:Units": [units_min[0]]},
coords_min[1]: {
"EmitterView:Units": [units_min[1]]},
}},
# Check if dependencies of EmitterUp are contained
"EmitterUp": {
"value": None,
"general": ["EmitterView"]},
# Check if dependencies of EmitterDescriptions are contained (specified in
# 5.3, D.12.5, D.13.5, D.14.5, D15.5)
"EmitterDescriptions": {
"value": None,
"general": ["GLOBAL:EmitterDescription"]},
# Room ----------------------------------------------------------------
# Possible values and dependencies are specified in
# AES69 Section 4.7.7
# ---------------------------------------------------------------------
"RoomVolume": {
"value": None,
"general": ["RoomVolume:Units"]},
"RoomTemperature": {
"value": None,
"general": ["RoomTemperature:Units"]},
"RoomVolume:Units": {
"value": ["cubic metre"]},
"RoomTemperature:Units": {
"value": ["kelvin"]},
}
# write to json files
for content, name in zip([rules, unit_aliases, deprecations],
["rules", "unit_aliases", "deprecations"]):
json_file = os.path.join(
os.path.dirname(__file__), "rules", name + '.json')
with open(json_file, 'w') as file:
json.dump(content, file, indent=4)