Skip to content

Commit f30a0f3

Browse files
author
Gregory Parkes
committed
added properties to SigMFFile
1 parent 4cdc35e commit f30a0f3

1 file changed

Lines changed: 127 additions & 8 deletions

File tree

sigmf/sigmffile.py

Lines changed: 127 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,38 @@ class SigMFFile(SigMFMetafile):
146146
CAPTURE_KEY = "captures"
147147
ANNOTATION_KEY = "annotations"
148148
VALID_GLOBAL_KEYS = [
149-
AUTHOR_KEY, COLLECTION_KEY, DATASET_KEY, DATATYPE_KEY, DATA_DOI_KEY, DESCRIPTION_KEY, EXTENSIONS_KEY,
150-
GEOLOCATION_KEY, HASH_KEY, HW_KEY, LICENSE_KEY, META_DOI_KEY, METADATA_ONLY_KEY, NUM_CHANNELS_KEY, RECORDER_KEY,
151-
SAMPLE_RATE_KEY, START_OFFSET_KEY, TRAILING_BYTES_KEY, VERSION_KEY
149+
AUTHOR_KEY,
150+
COLLECTION_KEY,
151+
DATASET_KEY,
152+
DATATYPE_KEY,
153+
DATA_DOI_KEY,
154+
DESCRIPTION_KEY,
155+
EXTENSIONS_KEY,
156+
GEOLOCATION_KEY,
157+
HASH_KEY,
158+
HW_KEY,
159+
LICENSE_KEY,
160+
META_DOI_KEY,
161+
METADATA_ONLY_KEY,
162+
NUM_CHANNELS_KEY,
163+
RECORDER_KEY,
164+
SAMPLE_RATE_KEY,
165+
START_OFFSET_KEY,
166+
TRAILING_BYTES_KEY,
167+
VERSION_KEY,
152168
]
153169
VALID_CAPTURE_KEYS = [DATETIME_KEY, FREQUENCY_KEY, HEADER_BYTES_KEY, GLOBAL_INDEX_KEY, START_INDEX_KEY]
154170
VALID_ANNOTATION_KEYS = [
155-
COMMENT_KEY, FHI_KEY, FLO_KEY, GENERATOR_KEY, LABEL_KEY, LAT_KEY, LENGTH_INDEX_KEY, LON_KEY, START_INDEX_KEY,
156-
UUID_KEY
171+
COMMENT_KEY,
172+
FHI_KEY,
173+
FLO_KEY,
174+
GENERATOR_KEY,
175+
LABEL_KEY,
176+
LAT_KEY,
177+
LENGTH_INDEX_KEY,
178+
LON_KEY,
179+
START_INDEX_KEY,
180+
UUID_KEY,
157181
]
158182
VALID_KEYS = {GLOBAL_KEY: VALID_GLOBAL_KEYS, CAPTURE_KEY: VALID_CAPTURE_KEYS, ANNOTATION_KEY: VALID_ANNOTATION_KEYS}
159183

@@ -262,6 +286,96 @@ def _is_conforming_dataset(self):
262286
# if we get here, the file exists and is conforming
263287
return True
264288

289+
@property
290+
def datatype(self) -> str:
291+
"""Fetches the datatype."""
292+
return self.get_global_field("core:datatype")
293+
294+
@property
295+
def sample_rate(self) -> float:
296+
"""Fetches the sample_rate in Hz."""
297+
return float(self.get_global_field("core:sample_rate"))
298+
299+
@property
300+
def version(self) -> str:
301+
"""Fetches the version."""
302+
return self.get_global_field("core:version")
303+
304+
@property
305+
def author(self) -> str | None:
306+
"""Fetches the author."""
307+
return self.get_global_field("core:author")
308+
309+
@property
310+
def collection(self) -> str | None:
311+
"""Fetches the collection."""
312+
return self.get_global_field("core:collection")
313+
314+
@property
315+
def dataset(self) -> str | None:
316+
"""Fetches the dataset."""
317+
return self.get_global_field("core:dataset")
318+
319+
@property
320+
def data_doi(self) -> str | None:
321+
"""Fetches the author."""
322+
return self.get_global_field("core:data_doi")
323+
324+
@property
325+
def description(self) -> str | None:
326+
"""Fetches the description."""
327+
return self.get_global_field("core:description")
328+
329+
@property
330+
def hw(self) -> str | None:
331+
"""Fetches the author."""
332+
return self.get_global_field("core:hw")
333+
334+
@property
335+
def license(self) -> str | None:
336+
"""Fetches the license."""
337+
return self.get_global_field("core:license")
338+
339+
@property
340+
def metadata_only(self) -> bool | None:
341+
"""Fetches the metadata_only."""
342+
return self.get_global_field("core:metadata_only")
343+
344+
@property
345+
def meta_doi(self) -> str | None:
346+
"""Fetches the author."""
347+
return self.get_global_field("core:meta_doi")
348+
349+
@property
350+
def num_channels(self) -> int | None:
351+
"""Fetches the num_channels."""
352+
return self.get_global_field("core:num_channels", 1)
353+
354+
@property
355+
def offset(self) -> int | None:
356+
"""Fetches the offset."""
357+
return self.get_global_field("core:offset", 0)
358+
359+
@property
360+
def recorder(self) -> str | None:
361+
"""Fetches the recorder."""
362+
return self.get_global_field("core:recorder")
363+
364+
@property
365+
def sha512(self) -> str | None:
366+
"""Fetches the sha512."""
367+
return self.get_global_field("core:sha512")
368+
369+
@property
370+
def trailing_bytes(self) -> int | None:
371+
"""Fetches the trailing bytes."""
372+
return self.get_global_field("core:trailing_bytes")
373+
374+
@property
375+
def geolocation(self):
376+
"""Fetches the geolocation."""
377+
return self.get_global_field("core:geolocation")
378+
265379
def get_schema(self):
266380
"""
267381
Return a schema object valid for the current metadata
@@ -768,7 +882,9 @@ class SigMFCollection(SigMFMetafile):
768882
]
769883
VALID_KEYS = {COLLECTION_KEY: VALID_COLLECTION_KEYS}
770884

771-
def __init__(self, metafiles: list = None, metadata: dict = None, base_path=None, skip_checksums: bool = False) -> None:
885+
def __init__(
886+
self, metafiles: list = None, metadata: dict = None, base_path=None, skip_checksums: bool = False
887+
) -> None:
772888
"""
773889
Create a SigMF Collection object.
774890
@@ -1046,6 +1162,7 @@ def fromarchive(archive_path, dir=None, skip_checksum=False):
10461162
access SigMF archives without extracting them.
10471163
"""
10481164
from .archivereader import SigMFArchiveReader
1165+
10491166
return SigMFArchiveReader(archive_path, skip_checksum=skip_checksum).sigmffile
10501167

10511168

@@ -1119,8 +1236,10 @@ def get_sigmf_filenames(filename):
11191236
# suffix, because the filename might contain '.' characters which are part
11201237
# of the filename rather than an extension.
11211238
sigmf_suffixes = [
1122-
SIGMF_DATASET_EXT, SIGMF_METADATA_EXT,
1123-
SIGMF_ARCHIVE_EXT, SIGMF_COLLECTION_EXT,
1239+
SIGMF_DATASET_EXT,
1240+
SIGMF_METADATA_EXT,
1241+
SIGMF_ARCHIVE_EXT,
1242+
SIGMF_COLLECTION_EXT,
11241243
]
11251244
if stem_path.suffix in sigmf_suffixes:
11261245
with_suffix_path = stem_path

0 commit comments

Comments
 (0)