forked from chorus-ai/chorus_waveform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
base.py
46 lines (33 loc) · 1.67 KB
/
base.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import abc
class BaseFormat(abc.ABC):
"""
Abstract class for data formats to be tested.
For each data format that we want to benchmark, a class must be
defined that inherits from this class and defines the following
methods:
- write_waveforms: take a collection of waveform data, and save
the data to one or more files on disk
- read_waveforms: load waveforms from one or more files, and
return the requested subset of the data
"""
@abc.abstractmethod
def write_waveforms(self, path: str, waveforms: dict):
raise NotImplementedError
@abc.abstractmethod
def read_waveforms(self, path: str, start_time: float, end_time: float,
signal_names: list):
raise NotImplementedError
# kwargs is a dictionary that can be used to pass additional arguments to the format
# replaces the total_length, block_length, and block_size params which are either test specific or intrinsic to the format.
def open_waveforms(self, path: str, signal_names:list, **kwargs):
raise NotImplementedError
def read_opened_waveforms(self, opened_files: dict, start_time: float, end_time: float,
signal_names: list):
raise NotImplementedError
def close_waveforms(self, opened_files: dict):
raise NotImplementedError
def open_read_close_waveforms(self, path, start_time, end_time, signal_names, **kwargs):
opened_files = self.open_waveforms(path, signal_names, **kwargs)
output = self.read_opened_waveforms(opened_files, start_time, end_time, signal_names)
self.close_waveforms(opened_files)
return output