Skip to content

saloot/IPythonClass

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 

Repository files navigation

Getting Started With IPython Notebooks


This tutorial is a shorter version of the more complete one here, which was provided by LCAV.

Introduction

Python is a very popular general-purpose language, with all the modern and classic constructs of a programming language that every software developer appreciates. This is what makes Python beneficial over MATLAB, besides the fact that it is not proprietary and various open source python distributions are freely and publicly available.

However, the very fact that Python is a general purpose language and not a software specific to scientific computing may be considered a drawback of it, too. To address this problem, several scientific computing packages (i.e. sets of function,classes,...) have been developed and released for it so far. These packages contain a large variety of functions which can solve everyday computational problems of researchers in many fields of engineering and science.

But the remaining problem is to find, install, maintain, manage updates and retain the consistency among all such packages as well as the Python system itself. This is where Anaconda comes in.

Anaconda

Anaconda is a completely free Python distribution (i.e. set of packages) for scientific purposes, as stated in their website. It contains more than 125 Python packages for science, mathematics, engineering and data analysis.

Installing Anaconda will not only give you an out-of-the-box ready python system as well as a fully-featured IDE (Integrated Development Environment), but also it will release you from the burden of manually installing and taking care of dependency and consistency requirements between various packages.

Installing Python and IPython Notebooks

Downloading Anaconda

To download the Anaconda, you can simply go to the link http://continuum.io/downloads and download the zip file compatible with your system. The download page looks like this:

window

It may ask for your e-mail as well. Please note that the Python version Anaconda uses is Python 2.7.

Installation on Linux

Installing Anaconda is pretty simple. On Linux-based systems, all you need to do is running the following command.

$ bash Anaconda-1.x.x-Linux-x86[ 64].sh

No root access is required. However, you will need to manually add Python executable files to your Path environment if you want to run them from every folder. This can be done by adding the following line of code to your ~/.bashrc file:

export PATH= /anaconda:$PATH

Installation on Windows

Installing Anaconda on Windows should be easy. It is automatically added to Path. In case of any prospective problem, disabling your anti-virus can be a potential solution.

window

Installation on Mac

On MacOS,  all you need to do is running the graphical installer. Anaconda will be automatically added to your path. However, in some cases an error message may appear at the installation time which is not a big deal. You can simply click Install for me only and go on.

window

It seems to happens for older versions of OS X that the following error is generated when launching the ipython notebook (see section 12)

ValueError: unknown locale: UTF-8

In that case, run the command locale in the terminal and inspect the value of the environment variable LC_CTYPE. It is probably just UTF-8.

Now open the file ~/.profile and add the following line

export LC_CTYPE='us_EN.UTF-8'

Then close the terminal session and try again. You might need to replace us_EN by a different value matching your system configuration.

Reading more about Python basics

If you are new to Python, you can start with some introdcutory online courses (such as this one).

Alternatively, you might be interested in taking a look at this tutorial, which was procided by LCAV here at EPFL.

IPython Notebooks

IPython notebooks are very interesting novel features added to recent versions of IPython. Notebooks are interactive documents that allow running Python code and reading (or writing) notes and documentations in the same place. Therefore, one can not only see the results he is reading about, but also can produce different results by changing the documented code.

A notebook is actually an extended HTML file which contains specific markup to distinguish Python codes inside the page. When displayed using a custom web server, it allows interactive execution and editing of the code inside the document. However, it can also be viewed as a usual, nicely-formatted HTML page. The document you are currently reading is itself an IPython notebook.

The command to run the IPython Notebooks web server is the following:

$ ipython notebook

When you execute the command above, a new browser window is opened which shows the notebooks in the current folder. The IPython notebook files have the ".ipynb" extension.

Creating Slides with IPython Notebooks

You can use your IPython Notebook to create slideshows as well. We have put a somewhat detailed set of instructions in the Presentation folder (check here).

Latex and IPython Notebooks

You can type math formulas just like the way you do with Latex in the IPython Notebooks. To do so, select Markdown in the cell type dropdown menu (see te figure below).

Cell Markdown

Now you can type math formulas following the latex format. For instance Latex formulas in Ipython Notebooks

And the result will be Latex formulas in Ipython Notebooks


You can also export yout notebooks into latex by opening a "terminal/command prompt" and using *nbconvert* command as follows
  1. Go to the folder that contain your IPython Notebook
  2. In the command line, type

$ ipython nbconvert --to latex your_notebook_name

Reading more about IPython Notebooks

There are a lot of notebooks available on the web which you can see and read. The GitHub repository available in here contains many useful and interesting ones. The source code of these notebooks is also available through the GitHub version control system.

Another interesting source is the book "Python For Signal Processing" which is publicly available as a series of IPython notebooks available at this address.

Working with Github

In this workshop, we are going to show you how you can publish the IPython Notebook for your paper onto Github and share it with your colleagues. For those of you who are not familiar with how Github works, we have summarized a few helpful commands to get you started.

Creating a Repository

A repository is a collection of files/folders where you store/share your code, data and paper body. To create a repository, you can simply

  1. Sign in to your Github account (or signup by creating an account)
  2. Once signed in, click on the "+" sign on top right of your screen (see the figure below) and select "New Reprository". Create a new repository on Github
  3. Select a name for your repository and click on "Create reprository". Create a new repository on Github
  4. Congratulations! Once you see a screen like the one below you are done :) Make sure to keep the URL specified in the figure below somewhere handy. We will need it shortly. Also, do not close this window for now!. Create a new repository on Github- Final step

Submitting Files to the Repository

Mac and Linux Users

Users that use Mac OS or Linux could use simple commands using terminal to submit your code.

  • Open a "Terminal" and navigate to the folder containg your codes (make sure you have some files in the folder).
  • Execute the following commands
$ git init
$ git add ./*

$ git commit -m "first commit"

$ git remote add origin the_url_to_your_repository

$ git push -u origin master

Note that the "the_url_to_your_repository" is the same URL that you have "kept somewhere handy". Here's when we need it ;)

  • Congratulations! You have successfully submitted your code. To verify, go back to your web browser and navigate to your Github repository on the web. You should see a page like the one below.
    Create a new repository on Github- Final step
  • Windows Users

    1. Donwload the Github client for Windows from here and install it.
    2. After installation, in your browser, navigate to the Github page you saw in the Step 4 above. Then, select Setup in Dekstop (see figure below) Create a new repository on Github- Final step
    3. The browser will ask for permission to launch the Github application. Please allow it ;) Create a new repository on Github- Final step
    4. Once opened, navigate to the place you want your repository be on your hard drive and clik on Clone. Create a new repository on Github- Final step
    5. You should now see a repository on the left panel in your Github application. Create a new repository on Github- Final step
    6. On your hard drive, add your codes to the repository folder. Then, go back to the Github application and you should see that new changes have been found in your repository. Create a new repository on Github- Final step
    7. At this point, add some comment to the "Summary" filed about what you changed and then click on Commit and Sync master. Create a new repository on Github- Final step
    8. Congratulations! You have successfully submitted your code. To verify, go back to your web browser and navigate to your Github repository on the web. You should see a page like the one below.
      Create a new repository on Github- Final step
    9. Now, you can edit the code on your hard drive and submit it regularly (to backup and do version control) just like what we did above. Once finished, you can share the URL of your repository with your colleagues and let them to enjoy your magnificent work as well :) Happy coding!

    Reading More About Using Git and Github

    Git and Github are twopowerful tools for backing up your code, do proper version control and share the code with your colleagues. There are lots of very good tutorials on the web, from beginner to advanced.

    Downloading Course Material

    You can simply click on the Download ZIP button on the right side of your screen, as shown in the figure below (of course there is the "Github way" as well but for now, this simpler solution should do the job ;) ).

    Download Course Materials

    Contacts

    In case you had any trouble in the above steps or ANY questions or suggestions regarding the workshop, logistics, IPython, etc. please do not hesitate to contact us (Robin or Hesam). We will be happy to help :)

    About

    No description, website, or topics provided.

    Resources

    Stars

    Watchers

    Forks

    Releases

    No releases published

    Packages

    No packages published

    Languages