Utility

The utility.py can do the following:

Reading CSV files

class spikes.utility.ReadCSV(path, log=False)[source]

Reads the CSV files in a given folder.

If no folder names is give, this program searches for folder Data; If no location is given.

Parameters
  • path (str) – Needed. Location of the directory containing the data files.

  • log (bool) – Default False. Verbose mode.

get_feature_names()[source]

Reads feature names from feature_names_eeg.txt if it is present else creates a feature names automatically.

Return type

dict

Return data_dict

A dictionary of Python list, which contains number_of_features and name_features.

get_samples()[source]

Reads all the sample starting with sam*.csv and returns a Pandas DataFrame.

Return type

dict

Return samples

A dictionary of samples and labels (this depends if you have labels file).

>>> data = ReadCSV('Data')
>>> data.get_samples()
    {
    'labels': [...],
    'samples: array(...)
    }
get_split_data(split_to=0.5)[source]

Split samples into training and testing data.

The default test size is 0.5 (50%)

Parameters

split_to (float) – Percentage split training and testing. Defaults to 0.5.

Return type

dict

Returns

Dictionary of train_samples, train_labels, test_samples, test_labels and split_percentage.

sample_size()[source]

Returns the length of the sample size.

Return type

int

Return size

Length on samples.

time_feature_length()[source]

Returns the time length of a file by counting it’s number of columns.

Return type

dict

Return data_dict

Dictionary of time_length and feature_length.

Helpers

Reads the data from folders and json files.

spikes.utility.atoi(text)[source]

Checks if the file names contain numbers.

Parameters

text (str) – File name.

Return type

bool

Returns

True or false based on the digits in text.

spikes.utility.natural_keys(text)[source]

Splits the number from the file name.

Parameters

text (str) – File name.

Return type

list

Returns

Splits the text if number is present in it.