@@ -205,7 +205,7 @@ def __next__(self):
205
205
raise StopIteration
206
206
207
207
def __getitem__ (self , sli ):
208
- mem = self ._memmap [sli ] # matches behavior of numpy.ndarray.__getitem__()
208
+ mem = self ._memmap [sli ] # matches behavior of numpy.ndarray.__getitem__()
209
209
210
210
if self ._return_type is None :
211
211
return mem
@@ -334,7 +334,7 @@ def add_capture(self, start_index, metadata=None):
334
334
# sort captures by start_index
335
335
self ._metadata [self .CAPTURE_KEY ] = sorted (
336
336
capture_list ,
337
- key = lambda item : item [self .START_INDEX_KEY ]
337
+ key = lambda item : item [self .START_INDEX_KEY ],
338
338
)
339
339
340
340
def get_captures (self ):
@@ -375,13 +375,17 @@ def get_capture_byte_boundarys(self, index):
375
375
compliant or noncompliant SigMF Recordings.
376
376
"""
377
377
if index >= len (self .get_captures ()):
378
- raise SigMFAccessError ("Invalid captures index {} (only {} captures in Recording)" .format (index , len (self .get_captures ())))
378
+ raise SigMFAccessError (
379
+ "Invalid captures index {} (only {} captures in Recording)" .format (index , len (self .get_captures ()))
380
+ )
379
381
380
382
start_byte = 0
381
383
prev_start_sample = 0
382
384
for ii , capture in enumerate (self .get_captures ()):
383
385
start_byte += capture .get (self .HEADER_BYTES_KEY , 0 )
384
- start_byte += (self .get_capture_start (ii ) - prev_start_sample ) * self .get_sample_size () * self .get_num_channels ()
386
+ start_byte += (
387
+ (self .get_capture_start (ii ) - prev_start_sample ) * self .get_sample_size () * self .get_num_channels ()
388
+ )
385
389
prev_start_sample = self .get_capture_start (ii )
386
390
if ii >= index :
387
391
break
@@ -390,7 +394,11 @@ def get_capture_byte_boundarys(self, index):
390
394
if index == len (self .get_captures ()) - 1 : # last captures...data is the rest of the file
391
395
end_byte = path .getsize (self .data_file ) - self .get_global_field (self .TRAILING_BYTES_KEY , 0 )
392
396
else :
393
- end_byte += (self .get_capture_start (index + 1 ) - self .get_capture_start (index )) * self .get_sample_size () * self .get_num_channels ()
397
+ end_byte += (
398
+ (self .get_capture_start (index + 1 ) - self .get_capture_start (index ))
399
+ * self .get_sample_size ()
400
+ * self .get_num_channels ()
401
+ )
394
402
return (start_byte , end_byte )
395
403
396
404
def add_annotation (self , start_index , length = None , metadata = None ):
@@ -409,7 +417,7 @@ def add_annotation(self, start_index, length=None, metadata=None):
409
417
# sort annotations by start_index
410
418
self ._metadata [self .ANNOTATION_KEY ] = sorted (
411
419
self ._metadata [self .ANNOTATION_KEY ],
412
- key = lambda item : item [self .START_INDEX_KEY ]
420
+ key = lambda item : item [self .START_INDEX_KEY ],
413
421
)
414
422
415
423
def get_annotations (self , index = None ):
@@ -466,13 +474,18 @@ def _count_samples(self):
466
474
header_bytes = sum ([c .get (self .HEADER_BYTES_KEY , 0 ) for c in self .get_captures ()])
467
475
file_size = path .getsize (self .data_file ) if self .data_size_bytes is None else self .data_size_bytes
468
476
file_data_size = file_size - self .get_global_field (self .TRAILING_BYTES_KEY , 0 ) - header_bytes # bytes
469
- sample_size = self .get_sample_size () # size of a sample in bytes
477
+ sample_size = self .get_sample_size () # size of a sample in bytes
470
478
num_channels = self .get_num_channels ()
471
479
sample_count = file_data_size // sample_size // num_channels
472
480
if file_data_size % (sample_size * num_channels ) != 0 :
473
- warnings .warn (f"File `{ self .data_file } ` does not contain an integer number of samples across channels. It may be invalid data." )
481
+ warnings .warn (
482
+ f"File `{ self .data_file } ` does not contain an integer number of samples across channels. "
483
+ "It may be invalid data."
484
+ )
474
485
if self ._get_sample_count_from_annotations () > sample_count :
475
- warnings .warn (f"File `{ self .data_file } ` ends before the final annotation in the corresponding SigMF metadata." )
486
+ warnings .warn (
487
+ f"File `{ self .data_file } ` ends before the final annotation in the corresponding SigMF metadata."
488
+ )
476
489
self .sample_count = sample_count
477
490
return sample_count
478
491
@@ -503,17 +516,27 @@ def calculate_hash(self):
503
516
"""
504
517
old_hash = self .get_global_field (self .HASH_KEY )
505
518
if self .data_file is not None :
506
- new_hash = sigmf_hash .calculate_sha512 (self .data_file , offset = self .data_offset , size = self .data_size_bytes )
519
+ new_hash = sigmf_hash .calculate_sha512 (
520
+ filename = self .data_file ,
521
+ offset = self .data_offset ,
522
+ size = self .data_size_bytes ,
523
+ )
507
524
else :
508
- new_hash = sigmf_hash .calculate_sha512 (fileobj = self .data_buffer , offset = self .data_offset , size = self .data_size_bytes )
525
+ new_hash = sigmf_hash .calculate_sha512 (
526
+ fileobj = self .data_buffer ,
527
+ offset = self .data_offset ,
528
+ size = self .data_size_bytes ,
529
+ )
509
530
if old_hash is not None :
510
531
if old_hash != new_hash :
511
532
raise SigMFFileError ("Calculated file hash does not match associated metadata." )
512
533
513
534
self .set_global_field (self .HASH_KEY , new_hash )
514
535
return new_hash
515
536
516
- def set_data_file (self , data_file = None , data_buffer = None , skip_checksum = False , offset = 0 , size_bytes = None , map_readonly = True ):
537
+ def set_data_file (
538
+ self , data_file = None , data_buffer = None , skip_checksum = False , offset = 0 , size_bytes = None , map_readonly = True
539
+ ):
517
540
"""
518
541
Set the datafile path, then recalculate sample count. If not skipped,
519
542
update the hash and return the hash string.
@@ -728,7 +751,13 @@ class SigMFCollection(SigMFMetafile):
728
751
STREAMS_KEY = "core:streams"
729
752
COLLECTION_KEY = "collection"
730
753
VALID_COLLECTION_KEYS = [
731
- AUTHOR_KEY , COLLECTION_DOI_KEY , DESCRIPTION_KEY , EXTENSIONS_KEY , LICENSE_KEY , STREAMS_KEY , VERSION_KEY
754
+ AUTHOR_KEY ,
755
+ COLLECTION_DOI_KEY ,
756
+ DESCRIPTION_KEY ,
757
+ EXTENSIONS_KEY ,
758
+ LICENSE_KEY ,
759
+ STREAMS_KEY ,
760
+ VERSION_KEY ,
732
761
]
733
762
VALID_KEYS = {COLLECTION_KEY : VALID_COLLECTION_KEYS }
734
763
0 commit comments