@@ -205,7 +205,7 @@ def __next__(self):
205205 raise StopIteration
206206
207207 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__()
209209
210210 if self ._return_type is None :
211211 return mem
@@ -334,7 +334,7 @@ def add_capture(self, start_index, metadata=None):
334334 # sort captures by start_index
335335 self ._metadata [self .CAPTURE_KEY ] = sorted (
336336 capture_list ,
337- key = lambda item : item [self .START_INDEX_KEY ]
337+ key = lambda item : item [self .START_INDEX_KEY ],
338338 )
339339
340340 def get_captures (self ):
@@ -375,13 +375,17 @@ def get_capture_byte_boundarys(self, index):
375375 compliant or noncompliant SigMF Recordings.
376376 """
377377 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+ )
379381
380382 start_byte = 0
381383 prev_start_sample = 0
382384 for ii , capture in enumerate (self .get_captures ()):
383385 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+ )
385389 prev_start_sample = self .get_capture_start (ii )
386390 if ii >= index :
387391 break
@@ -390,7 +394,11 @@ def get_capture_byte_boundarys(self, index):
390394 if index == len (self .get_captures ()) - 1 : # last captures...data is the rest of the file
391395 end_byte = path .getsize (self .data_file ) - self .get_global_field (self .TRAILING_BYTES_KEY , 0 )
392396 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+ )
394402 return (start_byte , end_byte )
395403
396404 def add_annotation (self , start_index , length = None , metadata = None ):
@@ -409,7 +417,7 @@ def add_annotation(self, start_index, length=None, metadata=None):
409417 # sort annotations by start_index
410418 self ._metadata [self .ANNOTATION_KEY ] = sorted (
411419 self ._metadata [self .ANNOTATION_KEY ],
412- key = lambda item : item [self .START_INDEX_KEY ]
420+ key = lambda item : item [self .START_INDEX_KEY ],
413421 )
414422
415423 def get_annotations (self , index = None ):
@@ -466,13 +474,18 @@ def _count_samples(self):
466474 header_bytes = sum ([c .get (self .HEADER_BYTES_KEY , 0 ) for c in self .get_captures ()])
467475 file_size = path .getsize (self .data_file ) if self .data_size_bytes is None else self .data_size_bytes
468476 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
470478 num_channels = self .get_num_channels ()
471479 sample_count = file_data_size // sample_size // num_channels
472480 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+ )
474485 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+ )
476489 self .sample_count = sample_count
477490 return sample_count
478491
@@ -503,17 +516,27 @@ def calculate_hash(self):
503516 """
504517 old_hash = self .get_global_field (self .HASH_KEY )
505518 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+ )
507524 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+ )
509530 if old_hash is not None :
510531 if old_hash != new_hash :
511532 raise SigMFFileError ("Calculated file hash does not match associated metadata." )
512533
513534 self .set_global_field (self .HASH_KEY , new_hash )
514535 return new_hash
515536
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+ ):
517540 """
518541 Set the datafile path, then recalculate sample count. If not skipped,
519542 update the hash and return the hash string.
@@ -728,7 +751,13 @@ class SigMFCollection(SigMFMetafile):
728751 STREAMS_KEY = "core:streams"
729752 COLLECTION_KEY = "collection"
730753 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 ,
732761 ]
733762 VALID_KEYS = {COLLECTION_KEY : VALID_COLLECTION_KEYS }
734763
0 commit comments