-
Notifications
You must be signed in to change notification settings - Fork 11
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
Stream_refactor #362
base: gui
Are you sure you want to change the base?
Stream_refactor #362
Conversation
@toni-neurosc I can take today and tomorrow to work on this branch and merge it into main. You mentioned that we can further refactor those points:
I agree with the changes, they make handling of the stream easier. |
I finished now a first version of the upper changes. An example to use it now looks as follows: import py_neuromodulation as nm
from py_neuromodulation.stream.data_processor import DataProcessor
from py_neuromodulation.stream.rawdata_generator import RawDataGenerator
from py_neuromodulation.stream.mnelsl_generator import MNELSLGenerator
import asyncio
async def main():
(
RUN_NAME,
PATH_RUN,
PATH_BIDS,
PATH_OUT,
datatype,
) = nm.io.get_paths_example_data()
(
raw,
data,
sfreq,
line_noise,
coord_list,
coord_names,
) = nm.io.read_BIDS_data(PATH_RUN=PATH_RUN)
channels = nm.utils.create_channels(
ch_names=raw.ch_names,
ch_types=raw.get_channel_types(),
reference="default",
bads=raw.info["bads"],
new_names="default",
used_types=("ecog", "dbs", "seeg"),
target_keywords=["MOV_RIGHT"],
)
settings = nm.NMSettings.get_fast_compute()
data_generator = RawDataGenerator(data,
settings.sampling_rate_features_hz,
settings.segment_length_features_ms,
channels,
sfreq,
)
output_writer = nm.utils.data_writer.DataWriter(
out_dir=PATH_OUT, save_csv=True, save_interval=10, experiment_name=RUN_NAME
)
data_processor = DataProcessor(
sfreq=sfreq,
settings=settings,
channels=channels,
coord_names=coord_names,
coord_list=coord_list,
line_noise=line_noise,
verbose=True,
)
data_generator = nm.stream.rawdata_generator.RawDataGenerator(
data, settings.sampling_rate_features_hz, settings.segment_length_features_ms, channels, sfreq
)
stream = nm.Stream(verbose=True)
df_features = await stream.run(
data_processor,
data_generator,
output_writer,
)
######### Definition of LSL stream:
lsl_generator = MNELSLGenerator(
segment_length_features_ms=settings.segment_length_features_ms,
sampling_rate_features_hz=settings.sampling_rate_features_hz,
stream_name="example_stream"
)
channels = lsl_generator.get_LSL_channels()
lsl_generator = lsl_generator.get_next_batch()
stream = nm.Stream(verbose=True)
df_features = stream.run(
data_processor,
lsl_generator,
output_writer,
)
if __name__ == "__main__":
asyncio.run(main()) Through the There is not a "stream control logic" class yet. I would also need to think for some time how such a class could be included. At the moment there is the |
Couple of additional points:
|
I made some changes to the Stream class with the idea of trying to clarify where different tasks should be handled, for example:
run
not only takes parameters related to the specific run, such asout_dir
,save_csv
,save_interval
,return_df
run
function.More changes I'd like to add:
run
function