Skip to content

Commit

Permalink
added namespace conversion from scaper to tag_open
Browse files Browse the repository at this point in the history
  • Loading branch information
bmcfee committed Jun 4, 2018
1 parent 12a4831 commit 1674862
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
14 changes: 14 additions & 0 deletions jams/nsconvert.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,20 @@ def tag_to_open(annotation):
return annotation


@_conversion('tag_open', 'scaper')
def scaper_to_tag(annotation):
'''Convert scaper annotations to tag_open'''

annotation.namespace = 'tag_open'

data = annotation.pop_data()
for obs in data:
annotation.append(time=obs.time, duration=obs.duration,
confidence=obs.confidence, value=obs.value['label'])

return annotation


@_conversion('beat', 'beat_position')
def beat_position(annotation):
'''Convert beat_position to beat'''
Expand Down
31 changes: 31 additions & 0 deletions tests/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,37 @@ def test_beat_position():
assert obs1.confidence == obs2.confidence


def test_scaper_tag_open():
ann = jams.Annotation(namespace='scaper')

value = {
"source_time": 5,
"event_duration": 0.5310546236891855,
"event_time": 5.6543442662431795,
"time_stretch": 0.8455598669219283,
"pitch_shift": -1.2204911976305648,
"snr": 7.790682558359417,
"label": 'gun_shot',
"role": "foreground",
"source_file": "/audio/foreground/gun_shot/135544-6-17-0.wav"
}

ann.append(time=0, duration=1, value=value)

ann2 = jams.convert(ann, 'tag_open')

ann.validate()
ann2.validate()
assert ann2.namespace == 'tag_open'

assert len(ann) == len(ann2)
for obs1, obs2 in zip(ann.data, ann2.data):
assert obs1.time == obs2.time
assert obs1.duration == obs2.duration
assert obs1.confidence == obs2.confidence
assert obs1.value['label'] == obs2.value


def test_can_convert_equal():

ann = jams.Annotation(namespace='chord')
Expand Down

0 comments on commit 1674862

Please sign in to comment.