{ "cells": [ { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## PH2150- Scientific Computing and Employabilty Skills\n", "\n", "### Introduction to Python (1 week)\n", "\n", "### Dr. Andrew Casey (a.casey@rhul.ac.uk, W054)\n", "\n", "![title](images\\ministry_of_silly_walks.jpg)\n", "###
A walk through Python" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# Aims and Objectives:\n", "\n", "![title](images\\python-logo.png)\n", "\n", "### Students will be introduced to the computing language *Python*.\n", "### Practice with the language will allow students to: \n", " \n", " * Gain a basic understanding of the syntax of *Python*\n", " * Plot and analyse experimental data\n", " * Gain insight into some topics from 1st and 2nd year courses\n", " * Preparation for final year project or possible summer placements\n", " \n", " \n", "### Employability skills\n", "\n", " * Write a professional CV and use STAR analysis techniques to produce a report. Should increase chances of gaining summer internships." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Course Structure:\n", "\n", "### The course consists of:\n", "* Post exam Python\n", "* Two lab session per week in the Autumn term (Mon Am, Thurs PM) \n", "* Weekly one hour employabilty skills lectures (Tues AM External speakers, CV training, Alumni talks)\n", "\n", "### The assesment is made up of:\n", "* Eight scientific Computing Skills problem sheets (60%)\n", "* Two employabilty assesment exercises (10%)\n", "* Final three week extending programming exercise (30%)\n" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Course Structure:\n", "\n", "### The first 4 weeks covering the basics of Python,\n", "\n", "* Variables (types assignment)\n", "* Operators\n", "* Inputs/Outputs\n", "* Control Structures (Loops, if, while, for)\n", "* Functions (User Defined, Modules)\n", "* Plotting \n", "* Fitting Data\n", "* Errors\n", "\n", "### Expanding the basic Python for scientific computing with the libraries:\n", "\n", "* NumPy (Python's n-dimensional array variable type, and functions operating on arrays)\n", "* SciPy (Fundamental library for scientific computing)\n", "* Matplotlib (Comprehensive 2D Plotting)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Course Structure:\n", "\n", "### After the basic syntax exercises will be related to your other Physics courses:\n", "### These problems come from:\n", "\n", "* Quantum Mechanics\n", "* Optics\n", "* Electromagnetism\n", "* Mathematical Methods\n", "\n", "### Finally you will bring your new computing / communications skills together in producing a GUI to demonstrate a chosen aspect of undergraduate physics.\n", "\n", "### In the weeks in which the employabilty exercises are due there will not be a computing problem sheet due in." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Course Structure:\n", "\n", "### Assesment of PH2150 problem sheets\n", "\n", "* Each problem sheet will be submitted to Turnitin via the PH2150 moodle page\n", "* Post exam problem sheets (PS1, PS2, PS3 will not be due in until the Autumn term)\n", "* PS1 will be due at the end of the day after the first session, PS2 after the 2nd and PS3 before the third.\n", "* From week two you will be introduced to a new problem sheet each week, which will be due in at the end of that week, except for the two weeks in which the employability exercise is due.\n", "* We will mark the problem sheets on an individual basis within the lab sessions, this gives instant feedback and tips on how to improve, and hopefully leaves you with a working programme for later reference.\n", "* The final report and code will be submitted to the office and marked anonymously.\n", "\n", "### They should start gently and build up to more complex problems as you become more proficient in *Python*." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## The Jupyter Notebook. \n", "Jupyter Notebook is an open-source web application that allows you to create and share documents that contain live code, equations, visualizations and explanatory text. Uses include: data cleaning and transformation, numerical simulation, statistical modeling, machine learning and much more.\n", "\n", "![title](images\\Jupyter_logo.png)\n", "\n", "The lecture notes will be stored as Jupyter notebooks, this is a mix of formatted text, python code and code output. It requires the Jupyter notebook server to run it though, and therefore isn't a stand-alone but there is no difference between the Python code that goes into a programme file or a Jupyter notebook." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Why Python?\n", "\n", "### More detail about this question in the moodle notes, but the essence is that:\n", "\n", "* Rapid development time\n", "* Open source (free to have at home, on your own machines)\n", "* Cross-platform (Windows, Macs, Linux, Android, Raspberry Pi) software that you write on one system will work in any other.\n", "* Its easy to do easy things, and possible to do really complicated things.\n", "* Growing user base in academia and industry.\n", "\n", "* Check out the number of SEPnet summer placement students who were using Python (also recent Alumni talks where they had an edge over others because of their python skills)\n" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Who's using python?\n", " \n", "\"Python has been an important part of Google since the beginning, and remains so as the system grows and evolves. Today dozens of Google engineers use Python, and we're looking for more people with skills in this language.\" said Peter Norvig, director of search quality at Google, Inc.\n", "![title](images\\googlelogo.gif)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Who's using python?\n", "\n", "\"Python is fast enough for our site and allows us to produce maintainable features in record times, with a minimum of developers,\" said Cuong Do, Software Architect, YouTube.com.\n", "![title](images\\youtubelogo.png)\n" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Who's using python?\n", "\n", "\"Python plays a key role in our production pipeline. Without it a project the size of Star Wars: Episode II would have been very difficult to pull off. From crowd rendering to batch processing to compositing, Python binds all things together,\" said Tommy Burnette, Senior Technical Director, Industrial Light & Magic.\n", "\n", "\"Python is everywhere at ILM. It's used to extend the capabilities of our applications, as well as providing the glue between them. Every CG image we create has involved Python somewhere in the process,\" said Philip Peterson, Principal Engineer, Research & Development, Industrial Light & Magic.\n", "\n", "![title](images\\ilmlogo.png)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Who's using python?\n", "\n", "\"NASA is using Python to implement a CAD/CAE/PDM repository and model management, integration, and transformation system which will be the core infrastructure for its next generation collaborative engineering environment. We chose Python because it provides maximum productivity, code that's clear and easy to maintain, strong and extensive (and growing!) libraries, and excellent capabilities for integration with other applications on any platform. All of these characteristics are essential for building efficient, flexible, scalable, and well-integrated systems, which is exactly what we need. Python has met or exceeded every requirement we've had,\" said Steve Waterbury, Software Group Leader, NASA STEP Testbed.\n", "\n", "![title](images\\nasalogo1.png)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Which version of Python?\n", "\n", "* There are two variants 2.x and since 2008 3.x (not backwards compatible)\n", "* They are around 90% the same and if you learn one you should have few problems with the other.\n", "* Up until last year we used a 2.x distribution of python, Specifically Python 2.7.3 contained within Enthoughts Canopy distribution https://www.enthought.com/products/canopy/, this will still be available on the teaching lab machines.\n", "### However:\n", "* According to the creators of python \"Python 2.x is legacy, Python 3.x is the present and future of the language\"\n", "* The remaining libraries that we use in PH2150 have been \"ported\" into 3.x\n", "* During this summer the College has migrated to Windows 10 and have installed 3.x on all of the teaching lab machines, .\n", "### The Python Environment that has been installed is called Ananconda:\n", "* Specifically, https://www.anaconda.com/download/ 64-bit windows, python 3.6, Anaconda 5.1\n", "* May be upgraded over the summer to Anaconda 2019, Python 3.7" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## The Python Environment\n", "\n", "We are now going to take a look at Anaconda, but which ever environment you choose to run python in it requires two elements:\n", "\n", "\n", "* A development Environment, where you edit code. This could be a basic text editor (not word processor), but it usual to use a text editor optimised for coding (this then will have useful features like recognising elements of the code and distinguishing them by colour, auto-completing commands, error checking, trace-back etc)\n", "\n", "* The Interpreter, the Python shell, where the computer runs the code.\n", "\n", "* These can be combined to form an integrated development environment (IDE) such as in Canopy, or Spyder (Scientific PYthon Development EnviRonment) within the Anaconda distribution.\n", "\n", "To open the environment lauch Anaconda Navigator from the start menu:\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "slideshow": { "slide_type": "slide" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The square root of 7.2= 2.6832815729997477\n" ] } ], "source": [ "# An example of an interpreter\n", "#Here the hash symbol signifies a comment and the interpreter skips the line after the #\n", "from math import sqrt\n", "x=7.2 # Here I am assigning the value 7.2 to the variable x\n", "y=sqrt(x)\n", "print('The square root of 7.2=',y) " ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "![title](images\\AnacondaNavigator.png)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "![title](images\\AnacondaEnvironment.png)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "![title](images\\Spyder.png)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Post Exam Notes and Problem Sheets\n", "\n", "Until the moodle rollover will be stored on the departmental twiki:\n", "\n", "https://twiki.ph.rhul.ac.uk/twiki/bin/view/Students/UnderGraduates/PostExamPython\n", "\n", "* Introduction Course Notes\n", "* Notes on packages NumPy and SciPy\n", "* Problem sheets 1-3 with accompanying material\n", "\n", "* Uploaded Jupyter Notebooks contained code examples\n", "\n", "During the course this material will be moved to moodle" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Further reading\n", "\n", " * The Python Software foundation: https://www.python.org/, The official web page of the Python programming language, contains tutorials, documents, reference library.\n", "* http://www.numpy.org/, the array\n", "* https://scipy.org/, scientific python library, documentation and tutorials\n", "* https://matplotlib.org/, Matplotlib is a Python 2D plotting library which produces publication quality figures (check-out the gallery)\n", "* http://www.python.org/dev/peps/pep-0008 - Style guide for Python programming. Highly recommended. \n", "\n", "* https://www.codecademy.com/ self learning website\n", "* https://software-carpentry.org/ online tutorials\n", "* http://https://stackoverflow.com/, an online developer community, question and answer site\n", "* \n" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Books\n", "This course is for solving physics problems, we get onto Numpy, SCipy very quickly, in some general programming books these are advanced topics (chapters 90+) or not covered at all. There are many good python books for the basic syntax, for the more physics relate problems I recommend:\n", "* NEW.. Introduction ot Python for Science and Engineering, David J. Pine (Very close match to most topics)\n", "* A Primer on Scientific Programming with Python, Hans Petter Langtangen\n", "* Introduction to numerical programming, Titus Beu\n", "* Numerical Methods in Engineering with Python, Jaan Kiusalaas\n", "and more general\n", "* Beginning Python, from novice to professional, Magnus Hetland.\n", "* Learn Python the Hard Way, Zed Shaw.\n", "* Learn Python in one day and Learn it well, Jamie Chan" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "celltoolbar": "Slideshow", "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "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.7.0" } }, "nbformat": 4, "nbformat_minor": 1 }