osl_dynamics.data.rw
#
Functions for reading and writing data.
Module Contents#
Functions#
|
Validates inputs. |
|
Returns the extension of a file. |
|
Lists a directory. |
|
Loads time series data. |
|
Load a fif file. |
|
Loads a MATLAB file. |
|
Wrapper for scipy.io.loadmat or mat73.loadmat. |
Attributes#
- osl_dynamics.data.rw.validate_inputs(inputs)[source]#
Validates inputs.
- Parameters:
inputs (list of str or str or np.ndarray) – Inputs files or data.
- Returns:
validated_inputs – Validated inputs.
- Return type:
list of str or str
- osl_dynamics.data.rw.file_ext(filename)[source]#
Returns the extension of a file.
- Parameters:
filename (str) – Path to file.
- osl_dynamics.data.rw.list_dir(path, keep_ext=None)[source]#
Lists a directory.
- Parameters:
path (str) – Directory to list.
keep_ext (str or list, optional) – Extensions of files to include in the returned list. Default is to include all files.
- Returns:
files – Full path to files with the correct extension.
- Return type:
list
- osl_dynamics.data.rw.load_data(data, data_field='X', picks=None, reject_by_annotation=None, mmap_location=None, mmap_mode='c')[source]#
Loads time series data.
Checks the data shape is time by channels and that the data is
float32
.- Parameters:
data (numpy.ndarray or str or list) – An array or path to a
.npy
,.mat
,.txt
or.fif
file containing the data.data_field (str, optional) – If a MATLAB filename is passed, this is the field that corresponds to the data.
picks (str or list of str, optional) – Argument passed to mne.io.Raw.get_data or mne.Epochs.get_data. Only used if a fif file is passed.
reject_by_annotation (str, optional) –
Argument passed to mne.io.Raw.get_data. Only used if a fif file is passed.
mmap_location (str, optional) – Filename to save the data as a numpy memory map.
mmap_mode (str, optional) – Mode to load memory maps in. Default is
'c'
.
- Returns:
data – Data.
- Return type:
np.memmap or np.ndarray
- osl_dynamics.data.rw.load_fif(filename, picks=None, reject_by_annotation=None)[source]#
Load a fif file.
- Parameters:
filename (str) – Path to fif file. Must end with
'raw.fif'
or'epo.fif'
.picks (str or list of str, optional) –
Argument passed to mne.io.Raw.get_data or mne.Epochs.get_data.
reject_by_annotation (str, optional) –
Argument passed to mne.io.Raw.get_data.
- Returns:
data – Time series data in format (n_samples, n_channels). If an
mne.Epochs
fif file is pass ('epo.fif'
) the we concatenate the epochs in the first axis.- Return type:
np.ndarray
- osl_dynamics.data.rw.load_matlab(filename, field)[source]#
Loads a MATLAB file.
- Parameters:
filename (str) – Filename of MATLAB file to read.
field (str) – Field that corresponds to the data.
- Returns:
data – Data in the MATLAB file.
- Return type:
np.ndarray
- osl_dynamics.data.rw.loadmat(filename, return_dict=False)[source]#
Wrapper for scipy.io.loadmat or mat73.loadmat.
- Parameters:
filename (str) – Filename of MATLAB file to read.
return_dict (bool, optional) – If there’s only one field should we still return a
dict
? Default is to return a numpy array if there is only one field. If there are multiple fields, adict
is always returned.
- Returns:
mat – Data in the MATLAB file.
- Return type:
dict or np.ndarray