# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

#   <div  style="color:#303030;font-family:'arial blACK', sans-serif,monospace; text-align: center; padding: 50px 0; vertical-align:middle;" > <img src="https://github.com/PIA-Group/ScientIST-notebooks/blob/master/_Resources/Images/Lightbulb.png?raw=true" style=" background:linear-gradient(to right,#FDC86E,#fbb144);border-radius:10px;width:150px;text-align:left; margin-left:10%"  /> <span style="position:relative; bottom:70px; margin-left:5%;font-size:170%;">    Setup your Python Workspace </span> </div>

# ## <span style="color:#fbb144;"> Keywords: </span>

# ```Python```, ```Anaconda Navigator```, ```Jupyter Notebooks```, ```IPython```, ```Spyder```

# # I. Introduction
# <br>
# <div style="width:100%; background:linear-gradient(to right,#FDC86E,#fbb144);font-family:'arial black',monospace; text-align: center; padding: 7px 0; border-radius: 5px 50px;margin-top:-15px" >  </div>

# ## <div style="color:#fbb144;"> 1. Background</div>
#

# [Python](https://www.python.org/) is a well-known programming language that primes for its simplicity (relatively easy to learn and use), for the "batteries-included" philosophy and for its numerous applications on different fields. The large number of development environment options, and diversity of useful packages is often overwhelming, which has lead to the creation of pre-configured distributions targeted at simplifying the initial package management and deployment.
#
# This notebook aims at guiding you through the setup of a development environment. In particular, we describe the Anaconda Python (https://docs.anaconda.com/anaconda) distribution designed for scientific computing using a local installation, and the cloud-based Binder (https://mybinder.org/) environment that can be used directly from a web browser.
#
# Furthermore, targeting some of the specific requirements of biomedical signal acquisition, processing, and analytics, we describe how to expand the default Anaconda Python environment with some convenient packages such as BioSPPy and pySerial.
#
#

# ## <div style="color:#fbb144;"> 2. Objectives </div>
#  
# * Understand the advantages of working in a Python environment;
# * Get acquainted with Binder and the Anaconda Navigator plus its most relevant environments; 
# * Enable an overview of different methods to install the packages coupled with a short description of some of them;
# * Setup a Python environment targeted at biomedical signal acquisition and processing.
#

# # II. Experimental
# <br>
# <div style="width:100%; background:linear-gradient(to right,#FDC86E,#fbb144);color:#282828;font-family:'arial black'; text-align: center; padding: 7px 0; border-radius: 5px 50px; margin-top:-15px" > </div>

# Python is a high-level programming language which excels for its simple and clean syntax. This is not only beneficial when it comes to readibility and therefore enabling the reduce of the expenses of program maintenance, but also for being an easy to learn programming language. Additionally, it appears to be more and more an attractive language for application development and scripting due to its open source nature. 
#
# This is a simple example of a program which sums all the digits of a number using a Jupyter Notebook.

def add_digits (n):
    if n<10:
        return n
    else:
        return add_digits(n//10)+n%10
add_digits(1568)

# Comparatively to other languages, Python is particularly appealing for scientific computing. Alternatives include **MATLAB**, **GNU Octave** and **R**; let's analyse them one by one.

# [**MATLAB**](https://www.mathworks.com/products/matlab.html) is vastly used by scientists and engineers since it allows, amonst other features, to **analyse data** and to **develop algorithms** with a high-level programming language that expresses matrix and array mathematics directly. It also includes a broad library of toolboxes enabling signal and image processing.
#
# <img src="https://github.com/PIA-Group/ScientIST-notebooks/blob/master/_Resources/Images/C.Signal_Processing_IMG/c010/Matlab.png?raw=true" alt="Matlab" border="0" width=400>
#
# However, MATLAB requires a **paid** license and extra toolboxes are also charged. This limitates the scalability and deployment of projects since only people with a license are able to run them. Besides, it is a **closed-source** software, developed exclusively by Mathworks; would the company to run out of business or change its business models to be more restrictive (financially or otherwise), MATLAB projects would eventually stop functioning.
#
# Python on the other hand is a **free**, **open-source** software. This is highly beneficial since anyone in the world can download, read and develop it allowing a much larger range of users.
#
#

# <div style="background:#946db2;font-family:'arial', monospace; text-align: center; padding: 10px 0; border-radius:10px; width:70%; margin:auto " >
#   <span style="font-size:20px;position:relative;color:white; "> Explore </span> <br>
#   <div style="background:#d0b3e6;font-size:12px"> 
#     To learn more about the differences between MATLAB and Python, visit [MATLAB vs Python](https://realpython.com/matlab-vs-python/#matlab-vs-python-comparing-features-and-philosophy).
# </div>

# [**GNU Octave**](https://www.gnu.org/software/octave/) is a high-level programming language mainly **mathematics-oriented**, suitable for solving equations, numerical linear algebra, statistical analysis and more. It includes a code editor with syntax highlighting as well as the interpreter for the language itself. It is mostly compatible with MATLAB, and often accoladed as an open-source version of the latter.
#
# <img src="https://github.com/PIA-Group/ScientIST-notebooks/blob/master/_Resources/Images/C.Signal_Processing_IMG/c010/octave.jpg?raw=true" alt="octave" border="0" width=400>
#
# Even so, Python is a more mainstream solution, hence a better option for a more **general use**. Aside from that, it presents an **object-oriented** programming style, **dynamic typing** and **high-level data types**, increasing its readability and accessibility for beginners.

# <div style="background:#946db2;font-family:'arial', monospace; text-align: center; padding: 10px 0; border-radius:10px; width:70%; margin:auto " >
#   <span style="font-size:20px;position:relative;color:white; "> Explore </span> <br>
#   <div style="background:#d0b3e6;font-size:12px"> 
#     To learn more about the differences between GNU Octave and Python, visit [GNU Octave vs Python](https://stackshare.io/stackups/octave-vs-python).
# </div>

# [R](https://www.r-project.org/) is a software environment mostly oriented for **statistical computing** and **graphics**. It has an open-source repository with thousands of packages which play a crucial part in data analysis.
#
# <img src="https://github.com/PIA-Group/ScientIST-notebooks/blob/master/_Resources/Images/C.Signal_Processing_IMG/c010/R.jpg?raw=true" alt="R" border="0" width=400>
#
# R is built by statisticians and contains their specific language. Once more, Python appears to be a more general language, plus its codes are easier to maintain and are more robust than R's.

# <div style="background:#946db2;font-family:'arial', monospace; text-align: center; padding: 10px 0; border-radius:10px; width:70%; margin:auto " >
#   <span style="font-size:20px;position:relative;color:white; "> Explore </span> <br>
#   <div style="background:#d0b3e6;font-size:12px"> 
#     To learn more about the differences between R and Python, visit [R vs Python](https://www.guru99.com/r-vs-python.html).
# </div>

# One could point out another advantage of utilizing Python as being the fact that its modules are organized in packages within libraries. This system is very usefull since it enables the programmer to choose a specific package accordingly to the necessity of the program in development. The point 2 of the next section will present some of the most relevant packages.

# <div style="background:#48ba57;font-family:'arial', monospace; text-align: center; padding: 10px 0; border-radius:10px; width:70%; margin:auto " >
#   <span style="font-size:20px;position:relative;color:white; ">  Note </span> <br>
#   <div style="background:#9de3a6;font-size:12px"> 
#     The book [A Primer on Scientific Programming with Python](https://www.springer.com/gp/book/9783662498866) serves as a first introduction to computer programming of scientific applications using Python.     
# </div>

# # III. Interfaces for Python Programming
# <br>
# <div style="width:100%; background:linear-gradient(to right,#FDC86E,#fbb144);color:#282828;font-family:'arial black'; text-align: center; padding: 7px 0; border-radius: 5px 50px; margin-top:-15px" > </div>

# In order to develop and run Python code, there are a number of options ranging from high-level virtualized environment, to command-line shells. Let's explore different possible interfaces to run Python programs. 

# ## <span style="color:#fbb144;"> Binder </span>

# This is an online service that allows the users to **access** and **run** their notebooks from a repository without any additional download. 
#
# The most common way of making a repository is through [GitHub](https://docs.github.com/en/free-pro-team@latest/github/getting-started-with-github/quickstart), which is a static tool for **sharing** and **organizing** code documents in, as mentioned before, repositories. In order to interact with the code in it, one has to access a platform capable of so. Binder appears to be the perfect ally as it enables browsing through an existing repository of Jupyter notebooks (see Section 1.3) directly on a web browser.
#
#
# In order to upload a GitHub repository, one ony has to get its URL and paste it on [Binder](https://mybinder.org/). Afterwards, click on "launch" and wait untill it's uploaded. The Jupyter Notebook setup will appear.
#
# <img src="https://github.com/PIA-Group/ScientIST-notebooks/blob/master/_Resources/Images/C.Signal_Processing_IMG/c010/Binder.gif?raw=true" alt="Binder" border="0" width=700>

# <div style="background:#946db2;font-family:'arial', monospace; text-align: center; padding: 10px 0; border-radius:10px; width:70%; margin:auto " >
#   <span style="font-size:20px;position:relative;color:white; "> Explore </span> <br>
#   <div style="background:#d0b3e6;font-size:12px"> 
#     [Binder documentation](https://github.com/alan-turing-institute/the-turing-way/blob/master/workshops/boost-research-reproducibility-binder/workshop-presentations/zero-to-binder-python.md) may be helpful to further explore this tool.
# </div>

# ## <span style="color:#fbb144;"> Anaconda Navigator </span>

# The Anaconda Navigator is a **graphical interface** to facilitate the management of Python packages and environments and allow easy access to useful developer applications. It has proven to be very useful since it provides thousands of **science and machine learning packages** through a central cloud-based repository. Furthermore, it presents multiple **data management environments** capable of being run separately without interfering with each other.
#

# ### <div style="color:#fbb144">  1. Installation and Environments </div>

# Installing the Anaconda Navigator requires just a few steps. The download website is
# [Anaconda](https://www.anaconda.com/products/individual). 

# <img src="https://github.com/PIA-Group/ScientIST-notebooks/blob/master/_Resources/Images/C.Signal_Processing_IMG/c010/Install-Anaconda.png?raw=true" alt="Install-Anaconda" border="0" width=700>

# Once having reached this point, one may choose the most suitable version, considering the operating system and capacity.
#
# After installation, this is what the navigator will look like.

# <img src="https://github.com/PIA-Group/ScientIST-notebooks/blob/master/_Resources/Images/C.Signal_Processing_IMG/c010/anaconda-nav.png?raw=true" alt="anaconda-nav" border="0" >

# One may notice there are different applications that can be selected from here. Let's analyse some of them in detail.

# #### <div style="color:#fbb144">   1.1. QtConsole  </div>

# The QtConsole covers, amongst other aspects, media output, multiline editing with syntax highlighting and graphical calltips. All of this is possible due to the existence of a IPython command-line interface.
#
#
# It gives the sense of a terminal which confers a plain, simple environment to the user in addition to being able to use any Python kernel. The image below displays an ECG signal produced using *neurokit2* on the IPython kernel (example from [neurokit2 site](https://neurokit2.readthedocs.io/en/latest/examples/simulation.html)).

# <img src="https://github.com/PIA-Group/ScientIST-notebooks/blob/master/_Resources/Images/C.Signal_Processing_IMG/c010/QTConsole-ECG.png?raw=true" alt="QTConsole-ECG" border="0">

# IPython contains embedded interpreters for multiple programming languages, providing high performance tools for computing. It also supports interactive data visualization.

# <div style="background:#946db2;font-family:'arial', monospace; text-align: center; padding: 10px 0; border-radius:10px; width:70%; margin:auto " >
#   <span style="font-size:20px;position:relative;color:white; "> Explore </span> <br>
#   <div style="background:#d0b3e6;font-size:12px"> 
#     To learn more about QtConsole funtionalities, visit [QtConsole](https://qtconsole.readthedocs.io/en/stable/).
# </div>

# #### <div style="color:#fbb144">   1.2. Spyder  </div>

# Amongst the most important Spyder features are the advanced editing, code analysis and the possibility to trace each step of your code's execution in order to debug efficiently due to its automatic syntax highlighting. It is most suitable for local development and low-level programming. Spyder provides an Integrated Development Environment (IDE) to facilitate programming of more complex software.
#
#
# It is divided in three main compartments:
# - the **Editor**, where you can open, create and edit a source file.
# - the **Console**, where you can interact directly with the Python backend and see execution results for the Editor's code.
# - the **Help panel**, where the documentation for the objects you are using in the Editor or the IPython Console is shown.
#

# <img src="https://github.com/PIA-Group/ScientIST-notebooks/blob/master/_Resources/Images/C.Signal_Processing_IMG/c010/Spyder.png?raw=true" alt="Spyder" border="0" width=750></a>

# When it comes to graphics, Spyder by default presents them inline within the interactive console. It is possible to change this configuration to make the graphic appear on a separate window. This can be much useful to edit the plot, zoom it and even save it separately.
#
# It can be configured by accessing the **Spyder Preferences > IPython Console > Graphics pane** and in the **Backend** option selecting **Automatic**. You will need to relaunch Spyder in order to take effect.

# <img src="https://github.com/PIA-Group/ScientIST-notebooks/blob/master/_Resources/Images/C.Signal_Processing_IMG/c010/ezgif-com-gif-maker-1.gif?raw=true" alt="ezgif-com-gif-maker-1" border="0" width=800>

# <div style="background:#946db2;font-family:'arial', monospace; text-align: center; padding: 10px 0; border-radius:10px; width:70%; margin:auto " >
#   <span style="font-size:20px;position:relative;color:white; "> Explore </span> <br>
#   <div style="background:#d0b3e6;font-size:12px"> 
#     To learn more about Spyder funtionalities, visit [Spyder](https://docs.spyder-ide.org/current/index.html).
# </div>

# <div style="background:#48ba57;font-family:'arial', monospace; text-align: center; padding: 10px 0; border-radius:10px; width:70%; margin:auto " >
#   <span style="font-size:20px;position:relative;color:white; ">  Note </span> <br>
#   <div style="background:#9de3a6;font-size:12px"> 
#        PyCharm is also a widely used Python IDE (Integrated Development Environment) designed with a smart code editor most suitable for high-level programming. It's a possible alternative to Spyder. For more information regarding PyCharm, visit [https://www.jetbrains.com/pycharm/](https://www.jetbrains.com/pycharm/)
#
# </div>

# #### <div style="color:#fbb144">   1.4. Jupyter Notebook  </div>

# Jupyter Notebook is a web-based interactive computing environment. It displays the input and output of a Python script, allowing the programmer to write not only code, but also narrative text, produce graphics and more. As the name suggests, it provides the sensation of a true notebook.
#
# When opening the Jupyter Notebook, you'll find the folders on your computer. You may choose a Notebook to open or create a new one using the "New" button on the top right, as shown is the gif below.

# <img src="https://github.com/PIA-Group/ScientIST-notebooks/blob/master/_Resources/Images/C.Signal_Processing_IMG/c010/Jupyter-notebook.gif?raw=true" alt="Jupyter-notebook" border="0" width=700>

# Working on a Jupyter Notebook can be largely advantageous education-wise since it displays your code and results in a sole document plus it allows the user to run cell by cell in order to obtain a better understanding of what each one does.
#
# However on a high-level programming context it could fall behind other environments, as its structure is more suitable for tutorial-like resources and not as much for tasks such as batch processing of data.

# <div style="background:#946db2;font-family:'arial', monospace; text-align: center; padding: 10px 0; border-radius:10px; width:70%; margin:auto " >
#   <span style="font-size:20px;position:relative;color:white; "> Explore </span> <br>
#   <div style="background:#d0b3e6;font-size:12px"> 
#     To learn more about Jupyter Notebook funtionalities, visit [Jupyter Notebook](https://jupyter.readthedocs.io/en/latest/running.html).
# </div>

# ### <div style="color:#fbb144">  2. Code Editor to use locally </div>

# There are several editors to use locally, for Python and further coding languages as well.
#
# Visual Studio Code has been considered the most prominent code editor and IDE (Integrated Development Environment). Let's understand its advantages and how to set it up.
#
# <img src="https://github.com/PIA-Group/ScientIST-notebooks/blob/master/_Resources/Images/C.Signal_Processing_IMG/c010/opengraph-home.png?raw=true" alt="Jupyter-notebook" border="0" width=700>
#

# #### <div style="color:#fbb144">  2.1. Visual Studio Code  </div>

# Visual Studio Code  (VScode) is a code editor redefined and optimized for building and debugging modern web and cloud applications, supporting almost every coding language.
#
# VScode is a free source-code editor made by Microsoft and works on Windows, Linux and macOS.
#
# 1. To download it, visit its page and [download it](https://code.visualstudio.com/download) 
# 2. Select the respective installer for your Windows, Linux or macOS computer.

# <div style="background:#48ba57;font-family:'arial', monospace; text-align: center; padding: 10px 0; border-radius:10px; width:70%; margin:auto " >
#   <span style="font-size:20px;position:relative;color:white; ">  Note </span> <br>
#   <div style="background:#9de3a6;font-size:12px"> 
#        Visit the oficial [VScode page](https://code.visualstudio.com/) for further documentation, tips and use cases.
#
# </div>

#
# Its main features include support for debugging, syntax highlighting, intelligent code completion, snippets, code refactoring, and embedded Git. 
#
# The whole environment preferences are adjustable by the user, and they can install extensions for sprecific further functionalities.
#
# VScode presents various advantages over any other IDE:
#
# * Cross-platform support (Windows, Linux and macOS)
#
# * Light-weight
#
# * Robust Architecture
#
# * Intelli-Sense
#
# * Freeware
#
# * Great tool support from desktop applications and web technologies
#
#

#
# <div style="background:#946db2;font-family:'arial', monospace; text-align: center; padding: 10px 0; border-radius:10px; width:70%; margin:auto " >
#   <span style="font-size:20px;position:relative;color:white; "> Explore </span> <br>
#   <div style="background:#d0b3e6;font-size:12px"> 
#     Consult this [page](https://www.educba.com/what-is-visual-studio-code/) to deepen VScode functionalities and advantages.
# </div>

# ### <div style="color:#fbb144">  3. Packages and Libraries </div>

# Packages are a very practical tool for numerous purposes. In order to install them, two main options can be used.	
#
# **1. Python Package Index (PyPI)**
# PyPI is a repository of software for the Python programming language. It enables an easy access to packages shared by the Python Community. 
#
#  **pip** is the package installer which usually is automatically installed with Python. One has to only make sure it is updated, in which case the website [pip update](https://datatofish.com/upgrade-pip/) is very illustrative.
#  
# Installing a package only takes writing:

# !pip install package_name

# **2.** The Anaconda Navigator **Environments** tab has the list of every installed and uninstalled package plus it is possible to install them, as ilustrated:
#

#
#
# <img src="https://github.com/PIA-Group/ScientIST-notebooks/blob/master/_Resources/Images/C.Signal_Processing_IMG/c010/Install-packages.gif?raw=true" alt="Install-packages" border="0" width="700" /></a>

# ### <span style="color:#fbb144;"> Scientific Computing Libraries </span>

# #### <div style="color:#fbb144">   3.1. Matplotlib  </div>

# *Matplotlib* is a comprehensive library broadly used for producing **static, animated and interactive representations** in Python including plots, histograms, bar charts, etc.. It can be used in various environments, such as Python scripts, the Python and IPython shells and the Jupyter notebook.
#
# To properly utilize this library, here are some key steps to get started.

# +
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
import numpy as np       #this library will be further explored in the next section

t = np.arange(0.0, 2*np.pi, 0.01) #timeline we want to plot

plt.grid(True)          

plt.title('Plot Example',{'size':15})  
plt.xlabel('Time (s)', color="#00a0e4")

plt.annotate('local max', xy=(1.5, 1), xytext=(2, 1.5), arrowprops=dict(facecolor='black', shrink=0.05),) #arrow that points to a local maximum

plt.axis([0,2*np.pi,-1-0.1,1+0.1]) #receives as argument [xmin,xmax,ymin,ymax]

plt.plot(t, np.sin(t),label='Sine', color="#00bfc2") 

plt.plot(t, np.cos(t),label='Cosine', color="#5756d6") 
plt.legend()

# +
Age = ['0-25','25-50','+50']
Data =[10, 23, 16]

plt.suptitle('Bar chart and plot example') 

plt.figure(figsize=(20, 4))
plt.subplot(131)
plt.bar(Age, Data,color="#00bfc2")
plt.xlabel('Age group', color="#00a0e4")
plt.ylabel('Number of individuals', color="#00a0e4")


plt.subplot(132)
plt.plot(Age,Data,color="#5756d6")
plt.xlabel('Age group', color="#00a0e4")
plt.ylabel('Number of individuals', color="#00a0e4")
plt.show
# -

# <div style="background:#946db2;font-family:'arial', monospace; text-align: center; padding: 10px 0; border-radius:10px; width:70%; margin:auto " >
#   <span style="font-size:20px;position:relative;color:white; "> Explore </span> <br>
#   <div style="background:#d0b3e6;font-size:12px"> 
#     To learn more about Matplotlib funtionalities, visit [Matplotlib](https://matplotlib.org/index.html).
# </div>

# #### <div style="color:#fbb144">   3.2. NumPy  </div>

# *NumPy* is an easy-to-use, efficient tool for scientific computing.
# For instance, it offers:
# * a **N-dimensional array** object;
# * sophisticated **mathematical functions**;
# * **linear algebra** and **random number** capabilities.
#
# Let's visualize some of its operations.

import numpy as np
np.array([[1,2,3],[4,5,6]])

np.random.randint(100) #Everytime you run this code, a different integer up to, but not including, 100  will appear.

a = np.arange(12).reshape(3,4)                   #creates a 3x4 array with the numbers from 1 to 11
b = a > 4
a, b, a[b]                                     


x = [56, 7, 3, 89, 30, 61]
np.sort(x)   #rearranges the list in ascending order

# +
x = np.arange (6)
print(x)

x.reshape(2,3) #reshapes the array, receiving as arguments (line, column)
# -

# <div style="background:#946db2;font-family:'arial', monospace; text-align: center; padding: 10px 0; border-radius:10px; width:70%; margin:auto " >
#   <span style="font-size:20px;position:relative;color:white; "> Explore </span> <br>
#   <div style="background:#d0b3e6;font-size:12px"> 
#     To learn more about NumPy funtionalities, visit [NumPy](https://numpy.org/).
# </div>

# #### <div style="color:#fbb144">   3.3. Pandas  </div>

# *Pandas* is a package designed to work with **tabular data**, namely data stored in spreadsheets and databases. It allows, for instance, the manipulation of rows and columns by selecting/modifying/eliminating specific data. 
#
# Here's some examples of how it works.

# +
import pandas as pd 

data = [['Tom', 20], ['Jack', 30], ['Meera', 25]]

df = pd.DataFrame(data, columns = ['Name', 'Age'])

print(df)
# -

print(df[df.Age > 20])

# <div style="background:#946db2;font-family:'arial', monospace; text-align: center; padding: 10px 0; border-radius:10px; width:70%; margin:auto " >
#   <span style="font-size:20px;position:relative;color:white; "> Explore </span> <br>
#   <div style="background:#d0b3e6;font-size:12px"> 
#     To learn more about Pandas funtionalities, visit [Pandas](https://pandas.pydata.org/docs/index.html).
# </div>

# #### <div style="color:#fbb144">  3.4. BioSPPy  </div>

# *BioSPPy* is a toolbox written in Python for **biosignal processing**. It covers filtering, frequency analysis of the raw signal acquired, clustering and biometrics. This package supports various biosignals, namely, Blood Volume Pulse (BVP), Eletrocardiogram (ECG), Eletrodermal Activity (EDA), Eletroencephalogram (EEG), Eletromyogram (EMG) and Respiration.
#
# Let's see an example using this package.
#

# !pip install biosppy

# The first step is to obtain the ECG raw signal, in this case, it was used the GitHub repository ([Biosignal Repository](https://github.com/PIA-Group/BioSPPy/tree/master/examples)) and saved into the "ECG.txt" document. For loading and plotting this signal, one could write the code below.
#

# +
import numpy as np
import pylab as pl
from biosppy import storage

signal, mdata = storage.load_txt(r'../X.Example_Files/ECG.txt')
Fs = mdata['sampling_rate']
N = len(signal)  # number of samples
T = (N - 1) / Fs  # duration
ts = np.linspace(0, T, N, endpoint=False)  # relative timestamps
pl.plot(ts, signal, lw=2, color="#00bfc2")
pl.grid()
pl.show()
# -

# This is a satisfactory graphic. However, there are still some artifacts resulting from powerline noise interference, DC offset originated from the acquisition device and influence of breathing noticible on the variability of the R-peaks amplitude. It is relatively simple to overcome this issue plus extract some extra signal features writting the following code.

from biosppy.signals import ecg
out = ecg.ecg(signal=signal, sampling_rate=Fs, show=True)


# <div style="background:#946db2;font-family:'arial', monospace; text-align: center; padding: 10px 0; border-radius:10px; width:70%; margin:auto " >
#   <span style="font-size:20px;position:relative;color:white; "> Explore </span> <br>
#   <div style="background:#d0b3e6;font-size:12px"> 
#     To learn more about BioSPPy funtionalities, visit [BioSPPy](https://biosppy.readthedocs.io/en/stable/).
# </div>
#

# #### <div style="color:#fbb144">   3.5. pySerial  </div>

# *pySerial* is also a package written 100% in Python. It can be particularly interesting since it allows the computer to exchange data with external hardware such as voltmeters, oscilloscopes and, in this context, devices for biosignal acquisition. This is made through **serial communication**: process of sending data one bit at a time through a communication channel (opposite of parallel communication). The development of this type of communication allowed for example the creation of the USB (Universal Serial Bus).

# <div style="background:#946db2;font-family:'arial', monospace; text-align: center; padding: 10px 0; border-radius:10px; width:70%; margin:auto " >
#   <span style="font-size:20px;position:relative;color:white; "> Explore </span> <br>
#   <div style="background:#d0b3e6;font-size:12px"> 
#     To learn more about pySerial funtionalities, visit [pySerial](https://pyserial.readthedocs.io/en/latest/pyserial.html#overview).
# </div>

# #### <div style="color:#fbb144">   3.6. Scikit-learn  </div>

# *Scikit-learn* is an open-source machine learning library suitable for **model fitting**, **data processing** and much more. All of this can be done thanks to numerous algorithms and models, called estimators. Estimators can be fitted to data using a fit method.
#
# Here's how it can be done.
#

# +
from sklearn.ensemble import RandomForestClassifier

clf = RandomForestClassifier(random_state=0)
X = [[ 1,  2,  3], [11, 12, 13]]
y = [0, 1]  # classes of each sample

clf.fit(X, y)

RandomForestClassifier(random_state=0)
# -

#
# <div style="background:#946db2;font-family:'arial', monospace; text-align: center; padding: 10px 0; border-radius:10px; width:70%; margin:auto " >
#   <span style="font-size:20px;position:relative;color:white; "> Explore </span> <br>
#   <div style="background:#d0b3e6;font-size:12px"> 
#     To learn more about Scikit-learn funtionalities, visit [Scikit-learn](https://scikit-learn.org/stable/).
# </div>

# # III. Explore
# <br>
# <div class='h1'  style="width:100%; background:linear-gradient(to right,#FDC86E,#fbb144);color:#282828;font-family:'arial black'; text-align: center; padding: 7px 0; border-radius: 5px 50px;margin-top:-15px" > </div>

# ### <div style="color:#fbb144">  3. Further Reading  </div>
#
#   The [Anaconda Site](https://www.anaconda.com/) has more information regarding the Navigator. The [Anaconda Cloud](https://anaconda.org/) is where all the pachages, projects and environments are shared.

# <div style="height:100px; background:white;border-radius:10px;text-align:center"> 
#
# <a> <img src="https://www.di.ubi.pt/~agomes/index_files/LogoIT.png" alt="it" style=" bottom: 0; width:250px;
#     display: inline;
#     left: 250px;
#     position: absolute;"/> </a>
# <img src="https://cqe.tecnico.ulisboa.pt/files/files/logos/IST_A_RGB_POS.png"
#          alt="alternate text" 
#          style="position: relative;   width:250px; float: left;
#     position: absolute;
#     display: inline;
#     bottom: 0;
#     right: 100;"/>
# </div> 

# <div style="width: 100%; ">
# <div style="background:linear-gradient(to right,#FDC86E,#fbb144);color:white;font-family:'arial', monospace; text-align: center; padding: 50px 0; border-radius:10px; height:10px; width:100%; float:left " >
# <span style="font-size:12px;position:relative; top:-25px">  Please provide us your feedback <span style="font-size:14px;position:relative;COLOR:WHITE"> <a href="https://forms.gle/C8TdLQUAS9r8BNJM8">here</a>.</span></span> 
# <br>
# <span style="font-size:17px;position:relative; top:-20px">  Suggestions are welcome! </span> 
# </div>

# ```Contributors: <NAME>; <NAME>```

StarcoderdataJupyterScriptsDedupFiltered