Load acquired data from .txt file
Difficulty Level:
Tags open☁load☁txt

A text file is one of the simplest means to store information, being a format outputted by OpenSignals .

In this Jupyter Notebook it will be explained how to load/transpose the data inside .txt file to a Python list, which consists in a step that precedes all processing operations.


1 - Importation of the needed packages

In [1]:
# Package used for loading data from the input text file
from numpy import loadtxt

# biosignalsnotebooks python package
import biosignalsnotebooks as bsnb

2 - Access to electrophysiological signals list

2.1 - Enter biosignalsplux url

2.2 - Navigate through biosignalsplux main page menu and enter in "Signal Samples" page

2.3 - Interactive buttons for accessing each signal sample file

2.4 - File url copy (right-click of the mouse in the desired signal file icon)

In [2]:
copy_link = 'https://www.biosignalsplux.com/downloads/samples/sensor_samples/biosignalsplux_Electrodermal_Activity_EDA_Sample.txt'
In [3]:
# File download.
bsnb.download(copy_link, out="download_file_name.txt")

4 - Transposition of data to a Python list

In [4]:
data = loadtxt("download_file_name.txt")

5 - Identification of acquisition sampling rate in the file header ("sampling rate" key)

In [5]:
# Embedding of .pdf file
from IPython.display import IFrame
IFrame(src="/images/load/open_txt/biosignalsplux_Blood_Volume_Pulse_(BVP)_Sample.txt", width="100%", height="350")
Out[5]:

In [6]:
sampling_rate = 1000

6 - Generation of time axis for signal plotting

In [7]:
time = bsnb.generate_time(data, sampling_rate)

7 - Final Output of the loaded data

In [8]:
print (data)
[[0.0000e+00 0.0000e+00 4.6888e+04]
 [1.0000e+00 0.0000e+00 4.6958e+04]
 [2.0000e+00 0.0000e+00 4.6872e+04]
 ...
 [2.8170e+03 0.0000e+00 3.6728e+04]
 [2.8180e+03 0.0000e+00 3.6773e+04]
 [2.8190e+03 0.0000e+00 3.6737e+04]]

Each line of the list defines a sample acquired at a specific time instant and each column can be the sample number ( nSeq ), digital input ( DI ) or a sample value ( CH1 ), like described in the file header bellow.

In [9]:
# Embedding of .pdf file
from IPython.display import IFrame
IFrame(src="/images/load/open_txt/biosignalsplux_Blood_Volume_Pulse_(BVP)_Sample.txt", width="100%", height="350")
Out[9]:

The samples of the signal under analysis are stored at the third entry of each list element (index 2).

In [10]:
channel_column = 2

8 - Graphical representation of the signal (raw data)

In [11]:
bsnb.plot(time, data[:, channel_column])

This procedure can be automatically done by load function of biosignalsnotebooks package

Text files are very popular and, like the name suggests, almost all type of contents can be stored here if they can be translated into a text format.

Numpy loadtxt function is very simple and efficient, so, it can be used even for text files not returned by OpenSignals .

We hope that you have enjoyed this guide. biosignalsnotebooks is an environment in continuous expansion, so don"t stop your journey and learn more with the remaining Notebooks !

In [12]:
from biosignalsnotebooks.__notebook_support__ import css_style_apply
css_style_apply()
.................... CSS Style Applied to Jupyter Notebook .........................
Out[12]: