-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds the StreamingBinWriter class that allows bin data to be streamed… #29
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,11 +21,11 @@ | |
|
||
from .dict2xml import dict2xml | ||
from .xml_files import XML | ||
from .bin_writer import BinWriter | ||
from .bin_writer import BinWriter, StreamingBinWriter | ||
from .devices import coordinates_and_sensor_layout | ||
import json | ||
|
||
__all__ = ['Writer', 'BinWriter'] | ||
__all__ = ['Writer', 'BinWriter', 'StreamingBinWriter'] | ||
|
||
|
||
class Writer: | ||
|
@@ -34,25 +34,32 @@ def __init__(self, filename: str): | |
self.filename = filename | ||
self.files: Dict[str, Any] = {} | ||
self._bin_file_added = False | ||
self.mffdir, self.ext = splitext(self.filename) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Am I correct in guessing that the intent here is to populate / prepare the filename variable at the time the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, because in order to stream a file to a directory that directory needs to be created first, so I needed some means of accessing the name of the directory to pass to the bin writer. |
||
self.mffdir += '.mff' | ||
self.file_created = False | ||
|
||
def create_directory(self): | ||
"""Creates the directory for the recording.""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the .mff directory contains a lot of extra info files besides just the signals, we might want to edit the description to say we are creating the directory for all parts of the .mff file. |
||
if not self.file_created: | ||
makedirs(self.mffdir, exist_ok=False) | ||
self.file_created = True | ||
|
||
def write(self): | ||
"""write contents to .mff/.mfz file""" | ||
# create .mff directory | ||
mffdir, ext = splitext(self.filename) | ||
mffdir += '.mff' | ||
makedirs(mffdir, exist_ok=False) | ||
|
||
self.create_directory() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not disagreeing, but why break out this functionality into its own function? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because currently it only creates the folder when write is called. Write needs to be called only after all of the data is collected, but in order to stream the EEG data to a file, the directory needs to already exist. |
||
|
||
# write .xml/.bin files. For .xml files we need to set the default | ||
# namespace to avoid `ns0:` being prepended to each tag. | ||
for filename, (content, typ) in self.files.items(): | ||
if '.xml' == splitext(filename)[1]: | ||
ET.register_namespace('', typ._xmlns[1:-1]) | ||
content.write(join(mffdir, filename), encoding='UTF-8', | ||
content.write(join(self.mffdir, filename), encoding='UTF-8', | ||
xml_declaration=True, method='xml') | ||
|
||
# convert from .mff to .mfz | ||
if ext == '.mfz': | ||
check_output(['mff2mfz.py', mffdir]) | ||
if self.ext == '.mfz': | ||
check_output(['mff2mfz.py', self.mffdir]) | ||
|
||
def export_to_json(self, data): | ||
"""export data to .json file""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are then any limitations / expectations for
sampling_rate
,mffdir
, ordata_type
that are non-obvious from the casual read?(i.e. We don't support smb file paths or some such)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added some comments.
Specifically, as regards the mffdir value, the directory must exist before the object is created, and this is noted. As far as limitations to where the folder can exist: this utilizes the same underlying functionality as the builtin open() and so has the same characteristics. These characteristics are shared by the BinWriter class as it uses open() directly to write the file.