@@ -323,6 +323,16 @@ def convert_iq_data(xml_path: Path, sample_count: int) -> np.ndarray:
323323 return samples
324324
325325
326+ def _add_annotations (meta : SigMFFile , annotations : list ) -> None :
327+ for annotation in annotations :
328+ start_idx = annotation .get (SigMFFile .START_INDEX_KEY , 0 )
329+ length = annotation .get (SigMFFile .LENGTH_INDEX_KEY )
330+ annot_metadata = {
331+ k : v for k , v in annotation .items () if k not in [SigMFFile .START_INDEX_KEY , SigMFFile .LENGTH_INDEX_KEY ]
332+ }
333+ meta .add_annotation (start_idx , length = length , metadata = annot_metadata )
334+
335+
326336def signalhound_to_sigmf (
327337 signalhound_path : Path ,
328338 out_path : Optional [Path ] = None ,
@@ -390,16 +400,7 @@ def signalhound_to_sigmf(
390400 meta .set_data_file (data_file = data_file_path , offset = 0 )
391401 meta .data_buffer = io .BytesIO ()
392402 meta .add_capture (0 , metadata = capture_info )
393-
394- # add annotations from metadata
395- for annotation in annotations :
396- start_idx = annotation .get (SigMFFile .START_INDEX_KEY , 0 )
397- length = annotation .get (SigMFFile .LENGTH_INDEX_KEY )
398- # pass remaining fields as metadata (excluding standard annotation keys)
399- annot_metadata = {
400- k : v for k , v in annotation .items () if k not in [SigMFFile .START_INDEX_KEY , SigMFFile .LENGTH_INDEX_KEY ]
401- }
402- meta .add_annotation (start_idx , length = length , metadata = annot_metadata )
403+ _add_annotations (meta , annotations )
403404
404405 # write metadata file if output path specified
405406 if out_path is not None :
@@ -429,17 +430,7 @@ def signalhound_to_sigmf(
429430
430431 meta = SigMFFile (data_file = data_path , global_info = global_info )
431432 meta .add_capture (0 , metadata = capture_info )
432-
433- # add annotations from metadata
434- for annotation in annotations :
435- start_idx = annotation .get (SigMFFile .START_INDEX_KEY , 0 )
436- length = annotation .get (SigMFFile .LENGTH_INDEX_KEY )
437- annot_metadata = {
438- k : v
439- for k , v in annotation .items ()
440- if k not in [SigMFFile .START_INDEX_KEY , SigMFFile .LENGTH_INDEX_KEY ]
441- }
442- meta .add_annotation (start_idx , length = length , metadata = annot_metadata )
433+ _add_annotations (meta , annotations )
443434
444435 output_dir = filenames ["archive_fn" ].parent
445436 output_dir .mkdir (parents = True , exist_ok = True )
@@ -465,16 +456,7 @@ def signalhound_to_sigmf(
465456 # create sigmffile with converted iq data
466457 meta = SigMFFile (data_file = filenames ["data_fn" ], global_info = global_info )
467458 meta .add_capture (0 , metadata = capture_info )
468-
469- # add annotations from metadata
470- for annotation in annotations :
471- start_idx = annotation .get (SigMFFile .START_INDEX_KEY , 0 )
472- length = annotation .get (SigMFFile .LENGTH_INDEX_KEY )
473- # pass remaining fields as metadata (excluding standard annotation keys)
474- annot_metadata = {
475- k : v for k , v in annotation .items () if k not in [SigMFFile .START_INDEX_KEY , SigMFFile .LENGTH_INDEX_KEY ]
476- }
477- meta .add_annotation (start_idx , length = length , metadata = annot_metadata )
459+ _add_annotations (meta , annotations )
478460
479461 # write metadata file
480462 meta .tofile (filenames ["meta_fn" ], toarchive = False , overwrite = overwrite )
0 commit comments