{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "\n", "Effective computation in Biomechanics\n", "\n", "Romain Martinez " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "< [Preface](00.00-preface.ipynb) | [Contents](index.ipynb) | [Python fundamentals](01.01-python-base.ipynb) >" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Introduction to Python" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Why programming?\n", "\n", "All modern biomechanics relies on a computer in some part of their scientific workflow. Some only use computers as word processing\n", "devices. Others may use computers that collect and analyze data.\n", "\n", "This course introduces ways to harness computers to accomplish and automate most aspect of research.\n", "\n", "This is not a pure biomechanics course nor a pure programming course. This course is about what\n", "happens when those two worlds collide. This course is about _computational biomechanics_." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Why Python?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Python is huge\n", "\n", "\n", "\n", "Developers use Python to work on small, personal projects all the way up to some of the largest internet companies in the world:\n", "\n", "- [Facebook](https://engineering.fb.com/production-engineering/python-in-production-engineering/)\n", "- [Instagram](https://thenewstack.io/instagram-makes-smooth-move-python-3/)\n", "- [Google](https://stackoverflow.com/questions/2560310/heavy-usage-of-python-at-google/2561008#2561008)\n", "- [Netflix](https://medium.com/netflix-techblog/python-at-netflix-86b6028b3b3e)\n", "- [Reddit](https://redditblog.com/2005/12/05/on-lisp/)\n", "- [Dropbox](https://anvilventures.com/blog/looking-inside-the-box.html)\n", "- [The black hole picture](https://www.sciencenews.org/article/black-hole-first-picture-event-horizon-telescope)\n", "\n", "Python is [the fastest-growing](https://insights.stackoverflow.com/survey/2019#technology), the four most popular and is the second most loved programming language." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "" ], "text/plain": [ "alt.Chart(...)" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas as pd\n", "import altair as alt\n", "\n", "%load_ext lab_black\n", "\n", "df = pd.read_csv(\"../data/google-trends.csv\", parse_dates=[\"Date\"]).melt(\n", " id_vars=\"Date\", var_name=\"Language\", value_name=\"Interest\"\n", ")\n", "\n", "alt.Chart(df).mark_line().encode(\n", " alt.X(\"Date\", title=None), alt.Y(\"Interest\"), alt.Color(\"Language\")\n", ").properties(title=\"Google Trends interest over time\")" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "" ], "text/plain": [ "alt.Chart(...)" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "alt.Chart(df.query('Language == \"Matlab\"')).mark_rect().encode(\n", " alt.X(\"month(Date)\"), alt.Y(\"year(Date)\"), alt.Color(\"Interest\"),\n", ").properties(title=\"Matlab is seasonal\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This great popularity has three advantages for you:\n", "\n", "1. With more than [210,000 packages](https://pypi.org/), someone has probably already made a package for your application. These range from processing PDF files to building and hosting an interactive website to working with highly optimized mathematical and scientific functions.\n", "2. You can easily find answers to your problems on Google or [Stackoverflow](https://stackoverflow.com/)\n", "3. More people can understand your code and collaborate" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Python is open and free" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "MATLAB is proprietary, closed-source software. For most people, a licence to use MATLAB is quite expensive, which means that if you have code in MATLAB, then only people who can afford a licence will be able to run it. Plus, users are charged for each additional toolbox they want to install to extend the basic functionality of MATLAB. Aside from the cost, the MATLAB language is developed exclusively by Mathworks. If Mathworks were ever to go out of business, then MATLAB would no longer be able to be developed and might eventually stop functioning.\n", "\n", "Your Academic Matlab setup will cost your employer (or you) __USD 17,840 / user / year__ ($\\approx$ CAD 23,500) once graduated.\n", "\n", "| Product | Cost/user/year |\n", "|-----------------------------------------|----------------|\n", "| Bioinformatics | 400 |\n", "| Control System | 400 |\n", "| Curve fitting | 400 |\n", "| Data acquisition | 400 |\n", "| Image Processing Toolbox | 400 |\n", "| Instrument Control Toolbox | 400 |\n", "| Parallel Computing Toolbox | 400 |\n", "| Signal Processing Toolbox | 400 |\n", "| Statistics and Machine Learning Toolbox | 400 |\n", "| Symbolic Math Toolbox | 400 |\n", "| Global Optimization Toolbox | 400 |\n", "| System Identification Toolbox | 400 |\n", "| Optimization Toolbox | 500 |\n", "| Simulink Control Design | 500 |\n", "| Deep Learning Toolbox | 500 |\n", "| Partial Differential Equation Toolbox | 500 |\n", "| Wavelet Toolbox | 500 |\n", "| DSP System | 540 |\n", "| Computer Vision Toolbox | 540 |\n", "| Econometrics Toolbox | 740 |\n", "| Financial Toolbox | 740 |\n", "| MATLAB Compiler | 800 |\n", "| MATLAB Compiler SDK | 800 |\n", "| Matlab | 860 |\n", "| Simscape | 860 |\n", "| Simscape Multibody | 860 |\n", "| Stateflow | 1200 |\n", "| Simulink | 1300 |\n", "| SimBiology | 1300 |\n", "| __TOTAL__ | __17,840__ |" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In science using open-source software has some pretty big benefits.\n", "\n", "Paul Romer, the 2018 Nobel Laureate in Economics, is a recent convert to Python. By his estimation, switching to open-source software in general, and Python in particular, brought greater integrity and accountability to his research.\n", "This was because all of the code could be shared and run by any interested reader.\n", "\n", "For all of these reasons, and many more, Python is an excellent choice to replace MATLAB as your programming language of choice." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Running Python code" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Python distribution\n", "\n", "\n", "\n", "We recommend [Miniconda](https://docs.conda.io/en/latest/miniconda.html) to use python and manage libraries.\n", "\n", "Miniconda is a Python distribution that comes with Conda, which we will then use to install everything we need.\n", "If you have not done so already, please download and install Miniconda or use [Binder]() to avoid installation troubleshoot." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Integrated Development Environment\n", "\n", "We recommend:\n", "\n", "- [Jupyter lab](https://github.com/jupyterlab/jupyterlab) for analysis\n", "\n", "- [PyCharm](https://www.jetbrains.com/pycharm/) for software development (writing complex functions, packages, etc.)\n", "\n", "\n", "\n", "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Complete setup for this course\n", "\n", "1. Download and Install [Miniconda](https://docs.conda.io/en/latest/miniconda.html) with Python 3\n", "2. Clone [this repo](https://github.com/pyomeca/tutorials)\n", "3. Install the dependencies with:\n", "\n", "```bash\n", "conda install jupyterlab -c conda-forge # install jupyter lab\n", "cd tutorials # go into tutorials directory\n", "conda env create # install dependencies\n", "conda activate tutorials # activate the course environment\n", "jupyter lab # open jupyter lab\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "< [Preface](00.00-preface.ipynb) | [Contents](index.ipynb) | [Python fundamentals](01.01-python-base.ipynb) >" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "conda-env-tutorials-py" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.1" }, "pycharm": { "stem_cell": { "cell_type": "raw", "metadata": { "collapsed": false }, "source": [] } }, "toc-autonumbering": true }, "nbformat": 4, "nbformat_minor": 4 }