@@ -78,14 +78,27 @@ def isused(sound):
7878 return np .where ([x ['file' ]== sound ['file' ] and x ['ticks' ]== sound ['ticks' ] \
7979 for x in used_sounds ])[0 ]
8080
81+ def trim_ext (wavfile ):
82+ if len (audio_read_rec2ch ()) == 1 :
83+ withoutext = os .path .splitext (wavfile )[0 ]
84+ else :
85+ tmp = wavfile .split ('-' )
86+ withext , rec = '-' .join (tmp [:- 1 ]), tmp [- 1 ]
87+ withoutext = os .path .splitext (withext )[0 ]+ '-' + rec
88+ return withoutext
89+
8190def save_annotations ():
8291 global nrecent_annotations
8392 if nrecent_annotations > 0 :
8493 fids = {}
8594 csvwriters = {}
8695 csvfiles_current = set ([])
87- for wavfile in set ([os .path .join (* x ['file' ]) for x in annotated_sounds if x ["label" ]!= "" ]):
88- csvfile = wavfile [:- 4 ]+ "-annotated-" + songexplorer_starttime + ".csv"
96+ wavfiles = set ()
97+ for sound in annotated_sounds :
98+ if not sound ["label" ]: continue
99+ wavfiles |= set ([trim_ext (os .path .join (* sound ["file" ]))])
100+ for wavfile in wavfiles :
101+ csvfile = wavfile + "-annotated-" + songexplorer_starttime + ".csv"
89102 annotated_csvfiles_all .add (csvfile )
90103 csvfiles_current .add (csvfile )
91104 fids [wavfile ] = open (os .path .join (V .groundtruth_folder .value , csvfile ),
@@ -98,10 +111,11 @@ def save_annotations():
98111 corrected_sounds = []
99112 for annotation in annotated_sounds :
100113 if annotation ['label' ]!= "" and not annotation ['label' ].isspace ():
101- csvwriters [os .path .join (* annotation ['file' ])].writerow (
114+ wavfile_noext = trim_ext (os .path .join (* annotation ['file' ]))
115+ csvwriters [wavfile_noext ].writerow (
102116 [annotation ['file' ][1 ],
103- annotation ['ticks' ][0 ], annotation ['ticks' ][1 ],
104- 'annotated' , annotation ['label' ]])
117+ annotation ['ticks' ][0 ], annotation ['ticks' ][1 ],
118+ 'annotated' , annotation ['label' ]])
105119 iused = isused (annotation )
106120 if len (iused )> 0 and used_sounds [iused [0 ]]['kind' ]== 'annotated' :
107121 corrected_sounds .append (annotation )
@@ -110,10 +124,14 @@ def save_annotations():
110124 x ['ticks' ][1 ], 'annotated' , x ['label' ]] \
111125 for x in corrected_sounds ], \
112126 columns = ['file' ,'start' ,'stop' ,'kind' ,'label' ])
113- for wavfile in set ([os .path .join (* x ['file' ]) for x in corrected_sounds ]):
127+ wavfiles = set ()
128+ for sound in corrected_sounds :
129+ wavfile_noext = trim_ext (os .path .join (* sound ["file" ]))
130+ wavfiles |= set ([wavfile_noext ])
131+ for wavfile in wavfiles :
114132 wavdir , wavbase = os .path .split (wavfile )
115133 wavpath = os .path .join (V .groundtruth_folder .value , wavdir )
116- for csvbase in filter (lambda x : x .startswith (wavbase [: - 4 ]) and
134+ for csvbase in filter (lambda x : x .startswith (os . path . splitext ( wavbase )[ 0 ]) and
117135 x .endswith (".csv" ) and
118136 "-annotated" in x and
119137 songexplorer_starttime not in x ,
@@ -235,7 +253,8 @@ def init(_bokeh_document, _configuration_file, _use_aitch):
235253 global context_width_sec0 , context_offset_sec0
236254 global xcluster , ycluster , zcluster , ndcluster , tic2pix_max , snippet_width_pix , ilayer , ispecies , iword , inohyphen , ikind , nlayers , layers , species , words , nohyphens , kinds , used_labels , snippets_gap_sec , snippets_tic , snippets_gap_tic , snippets_decimate_by , snippets_pix , snippets_gap_pix , context_decimate_by , context_width_tic , context_offset_tic , context_sound , isnippet , xsnippet , ysnippet , file_nframes , context_midpoint_tic , ilabel , used_sounds , used_starts_sorted , used_stops , iused_stops_sorted , annotated_sounds , annotated_starts_sorted , annotated_stops , iannotated_stops_sorted , annotated_csvfiles_all , nrecent_annotations , clustered_sounds , clustered_activations , used_recording2firstsound , clustered_starts_sorted , clustered_stops , iclustered_stops_sorted , songexplorer_starttime , history_stack , history_idx , wizard , action , function , statepath , state , file_dialog_root , file_dialog_filter , nearest_sounds , status_ticker_queue , waitfor_job , dfs , remaining_isounds
237255 global user_changed_recording , user_copied_parameters
238- global audio_read , video_read , detect_labels , doubleclick_annotation , context_data , context_data_istart , model , video_findfile
256+ global audio_read , audio_read_exts , audio_read_rec2ch
257+ global video_read , detect_labels , doubleclick_annotation , context_data , context_data_istart , model , video_findfile
239258 global detect_parameters , doubleclick_parameters , model_parameters , cluster_parameters
240259
241260 bokeh_document = _bokeh_document
@@ -253,9 +272,11 @@ def init(_bokeh_document, _configuration_file, _use_aitch):
253272
254273 sys .path .insert (0 ,os .path .dirname (audio_read_plugin ))
255274 audio_read_module = importlib .import_module (os .path .basename (audio_read_plugin ))
275+ audio_read_module .audio_read_init (** audio_read_plugin_kwargs )
256276 def audio_read (wav_path , start_tic = None , stop_tic = None ):
257- return audio_read_module .audio_read (wav_path , start_tic , stop_tic ,
258- ** audio_read_plugin_kwargs )
277+ return audio_read_module .audio_read (wav_path , start_tic , stop_tic , ** audio_read_plugin_kwargs )
278+ def audio_read_exts (): return audio_read_module .audio_read_exts (** audio_read_plugin_kwargs )
279+ def audio_read_rec2ch (): return audio_read_module .audio_read_rec2ch (** audio_read_plugin_kwargs )
259280
260281 sys .path .insert (0 ,os .path .dirname (video_read_plugin ))
261282 video_read_module = importlib .import_module (os .path .basename (video_read_plugin ))
0 commit comments