Skip to content

Commit 9db8cf9

Browse files
committed
add Sofa.convention_status property
1 parent a1e8187 commit 9db8cf9

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

sofar/sofa.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,54 @@ def inspect(self, file=None, issue_handling="print"):
490490
# output to console
491491
print(info_str)
492492

493+
@property
494+
def convention_status(self):
495+
"""
496+
Get the status of the SOFA convention.
497+
498+
Returns
499+
-------
500+
status : str
501+
The status of the SOFA convention
502+
503+
- ``'current'`` if the convention is up to date.
504+
- ``'deprecated'`` if the convention is outdated. In this case
505+
:py:func:`~upgrade` can be used to upgrade the data to the latest
506+
version of the convention.
507+
- ``'preliminary'`` if the convention is still under development
508+
and not contained in the official SOFA standard, which is
509+
indicated by a version number smaller than 1.0. Note that
510+
preliminary conventions may be subject to change or could be
511+
discarded completely. Data written with preliminary conventions
512+
might thus become invalid in the future.
513+
"""
514+
515+
status = None
516+
517+
# get deprecations and information about Sofa object
518+
_, _, deprecations, upgrade = self._verification_rules()
519+
convention = self.GLOBAL_SOFAConventions
520+
version = self.GLOBAL_SOFAConventionsVersion
521+
522+
# conventions can be completely deprecated or upgradable to a later
523+
# version of the same convention or to a later convention
524+
if convention in deprecations["GLOBAL:SOFAConventions"]:
525+
status = 'deprecated'
526+
elif convention in upgrade:
527+
for from_to in upgrade[convention]["from_to"]:
528+
if version in from_to[0]:
529+
status = 'deprecated'
530+
break
531+
# conventions are preliminary if they are not deprecated and have a
532+
# version number < 1.0
533+
if status is None and parse(version) < parse('1.0'):
534+
status = 'preliminary'
535+
# if both is not the case, the convention is current.
536+
if status is None:
537+
status = 'current'
538+
539+
return status
540+
493541
def add_missing(self, mandatory=True, optional=True, verbose=True):
494542
"""
495543
Add missing data with default values.

tests/test_sofa.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,26 @@ def test_inspect(capfd):
197197
assert out == "".join(text)
198198

199199

200+
@pytest.mark.parametrize(('sofa', 'status'), [
201+
# up to date convention
202+
(sf.Sofa('FreeFieldDirectivityTF'),
203+
'current'),
204+
# convention with outdated version
205+
(sf.Sofa('FreeFieldDirectivityTF', version='1.0', verify=False),
206+
'deprecated'),
207+
# deprecated convention
208+
(sf.Sofa('GeneralFIRE', verify=False),
209+
'deprecated'),
210+
# preliminary convention. NOTE: This test will fail if the convention
211+
# becomes standardized. In this case the status will change to 'deprecated'
212+
(sf.Sofa('AnnotatedEmitterAudio', version='0.2', verify=False),
213+
'preliminary'),
214+
])
215+
def test_deprecated(sofa, status):
216+
217+
assert sofa.convention_status == status
218+
219+
200220
def test_add_entry():
201221

202222
sofa = sf.Sofa("GeneralTF")

0 commit comments

Comments
 (0)