mad_gui.plugins.BaseImporter#

class mad_gui.plugins.BaseImporter(parent=None)[source]#

Classes based on this one enable the GUI to load data from different systems/formats.

Attributes:
file_type

Can restrict the format of the data/video/annotation file that can be loaded with this importer.

Methods

get_start_time(*args, **kwargs)

Get the start time of the corresponding data.

get_sync_file(video_file)

Searches for an excel file that has sync in its name and returns the file name.

get_video_signal_synchronization(sync_file)

Get information regarding sync for video and signal."

load_annotations(file_path)

This loads annotations from file_path and converts them into the format for the GUI.

load_sensor_data(file)

Loading sensor data as it is usually stored by your recording device

name()

Return a name, which is used to represent this Importer in a dropdown in the GUI.

__init__(parent=None)[source]#

Set a parent, in case this would be necessary at any later stage.

Parameters:
parent

This could for example be the main window of the GUI, in case the plugin wants to access something there. However, this is unlikely to be necessary since plugins receive either the single mad_gui.models.GlobalData or its attribute PlotData, which should be sufficient to do everything.

get_start_time(*args, **kwargs) time[source]#

Get the start time of the corresponding data.

This may be used by mad_gui.plot_tools.plots.SensorPlot to set the channel labels. However, you do not necessarily have to implement it. If you do not implement it, the x-channel will simply start at 0 seconds.

NOTE: Your importer does not have to implement this method. If you do not implement it, the first sample of the shown data will be displayed at second 0 and the x-channel is going to be in seconds.

Parameters:
sensor_data_path

The path of the sensor data that should be displayed in mad_gui.windows.MainWindow

static get_sync_file(video_file: str) str[source]#

Searches for an excel file that has sync in its name and returns the file name.

Returns:
sync_file

The path of the excel file that has sync in its name and returns the sync indices from there.

Attributes:
video_file

The path of the video file that is being shown.

classmethod get_video_signal_synchronization(sync_file: str) DataFrame[source]#

Get information regarding sync for video and signal."

The Excel file should have as first column (index) "start" and "end" and the columns should be "PLOTNAME_sample" video_ms."

Returns:
sync_indices

A dataframe which tells the gui which frames of the video correspond to which samples in the signal. Currently only implemented to accept two synchronized events. Between those, the GUI interpolates linearly.

Attributes:
sync_file

The path of the sync file for the video that is being shown.

load_annotations(file_path: Path | str) Dict[str, DataFrame][source]#

This loads annotations from file_path and converts them into the format for the GUI.

This method is called by the LoadDataDialog in case the user selects a file using the "Select annotation" button. In that case, this method should open the file specified by file_path and then create.

NOTE: Your importer does not have to implement this method in case you do not want to deliver such functionality to the user.

Parameters:
file_path

file_path to load the annotation data from

Returns:
dict

Dictionary with keys being the titles of the plots in the main window. Each of them keeps a pd.DataFrame, which at least has the columns start and end.

Examples

>>> annotations = load_annotations("/some/file.format")
>>> annotations.keys()
dict_keys(['left_sensor', 'right_sensor'])
>>>annotations['left_sensor']
    identifier    start    end    description
0            0      100    105   (gait, slow)
1            1      105    108   (gait, fast)
2            2      120    130     (standing)
load_sensor_data(file: str)[source]#

Loading sensor data as it is usually stored by your recording device

Parameters:
file

Full path to the file that should be used to load data. You will automatically receive this from the GUI which calls this importer.

Returns:
sensor_data

A dictionary with one key per sensor. Each of those, again keeps a dictionary, with at least two keys: sensor data and sampling_rate_hz. Behind the key sensor_data is a pd.DataFrame with one column per channel, sampling_rate_hz is a float. If this dictionary has further keys, those will later be stored in mad_gui.models.local.PlotData's additional_data.

Examples

>>> data = load_sensor_data("/some/file.format")
>>> data.keys()
dict_keys(['left_sensor', 'right_sensor'])
>>> data['left_sensor'].keys()
dict_keys(['sensor_data', 'sampling_rate_hz'])
>>> data['left_sensor']['sensor_data']
    acc_x    'acc_y'
0    9.81       0.1
1    9.80       0.0
2    9.82       0.1
abstract classmethod name() str[source]#

Return a name, which is used to represent this Importer in a dropdown in the GUI.