{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Introduction to SciPy\n", "Tutorial at EuroSciPy 2019, Bilbao\n", "## 1. Statistical analysis – Gyroscope data taken in a TGV" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "from scipy import optimize, stats\n", "%matplotlib notebook\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Importing the data" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Our gyroscope data are stored in a compressed file `data/TGV_data.csv.bz2`. Each row of the uncompressed file contains entries separated by commas and the first row contains labels explaining the content of the respective column." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "data = np.genfromtxt('data/TGV_data.csv.bz2', delimiter=',', names=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "There are five columns identified by names:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "data.dtype.names" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "time = data['Time_s']\n", "omega_x = data['Gyroscope_x_rads']" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let us first get an idea of the data." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "_ = plt.plot(time, omega_x)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Statistical analysis" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We use the data for $\\omega_x$ to demonstrate some aspects of statistical analysis with SciPy. Let us first take a look at a histogram of the data." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "n, bins = np.histogram(omega_x, bins=100, density=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Because we have set `density=True`, the data can be considered as a normalized probability distribution." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "np.sum(n)*(bins[1]-bins[0])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "