Python: a language for science

Python has become the most popular language for programming and its community is huge, active and ever-increasing. Before Python, MATLAB was the preferred language for the scientific community but now most of the researchers are migrating to Python. Like MATLAB, Python is quite easy to use but over that Python can be used for the system control, software developing, easy integration with other languages like FORTRAN, C , etc. This makes it extremely popular among all sorts of communities. Some P.Is want their students to work in Python because according to them, even when the students want to switch the field or simply leave the field, it could still be useful to them.

If you are familiar with other programming languages including MATLAB, then its very easy to switch to Python. Though, there are some issues the beginners and the MATLAB users face while making a move to Python. Here, let us deal with that issue and get started with Python.

Getting started with Python

Currently, there are two versions of Python – 2.7, and 3.6. But we will stick with Python 3.6. The steps for the version 2.7 is very similar.

Python can be downloaded directly from its official website https://www.python.org/downloads/.

But, here, we will download Python from the Anaconda website. Steps are listed below:

  1. Download the installer for the Windows, Mac, or the Linux system. For Windows, you will get a “.exe” extension file, double-click the file and follow the installation procedure.For Mac and Linux system, the file will be with the extension “.sh” (a shell- script). You can open your favorite terminal, navigate to the directory containing the downloaded Miniconda installation file. Then, you can simply type “sh Miniconda*.sh” and follow the steps prompted. You will be asked to accept the license and enter your installation location. If you don’t have any preferred location then the installer will install Miniconda in your home directory.

  2. Now, Miniconda, as well as Python 3.6, has been installed on your machine. We need some more Python libraries to get going. We can easily install these now using Miniconda. Open your terminal and type “conda install jupyter notebook pandas numpy matplotlib”.

We now have all the necessary libraries to get started with Python. Let us open a terminal again and simply type “jupyter notebook” to launch jupyter notebook. Jupyter notebook is a very popular interface which makes using Python a fun experience. It has all the features to make things simpler and useful. You can even run the shell command in the notebook. Over that, you can write your notes using the Markdown language, which is a very straight-forward language for writing. I strongly recommend you to learn Markdown. It won’t take more than 10 minutes to learn and will be useful in so many other places.

Now, that we have all the necessary tools to use Python then let’s use python to make a very simple plot.

  1. First, start jupyter notebook by typing “jupyter notebook” on your terminal.It will open “Jupyter” in your favorite browser.
  2. Now, go to the “New” tab at the top right corner and then select “Python 3”. It will open a new page for you.
  3. Let’s import some libraries which we have installed using the conda by typing the command as directed in the figure below. To execute the command, use the “Command/Ctrl + Enter” key.
  4. We also need to execute the command “%matplotlib inline” to keep our plots inline in the notebook. This is one of the many features of jupyter notebook.
  5. Let’s define our x and y values using the numpy library which we have imported as “np” for short-form.
  6. Let’s plot our data.

Linux Tutorials ( For beginners )

Linux is a very powerful platform which can be used to do almost everything in computer world. It is an open-source and free operating system. There are various distributions of Linux operating system including Ubuntu, Fedora, Debian, Mint, Opensuse etc. Even the Android operating system which has revolutionised the phone industry is a distribution of Linux operating system. About 90 % of world’s fastest computer’s uses Linux OS. Linux is very light and it even makes the weak processors do more faster things than using the Windows operating system.

Here, we will start with the basics of the navigational commands and then gradually move towards scientific programming in bash.

  1. Introduction to Linux OS, simple navigational commands, pwd (print working directory), ls (list directory), rm (remove), rmdir (remove directory), mkdir (make directory)

2. cp (copy files), mv (move or rename files), file structure in linux, root directory

3. Manipulate the directory stack: pushd (saves the current working directory in memory so it can be returned to at any time) , popd (returns to the path at the top of the directory stack)
Size of the directory: du
Check disk space: df

4. find (finding files on system), finding and removing, finding and executing some operation on it.

5. cat (for displaying text file on screen, reading text file), more (Displays text, one screen at a time), less (program similar to more, but has many more features), head (display first few lines of the file), tail (display last few lines of the file)

6. Managing and editing .bashrc, .bash_profile (These files run everytime, you refresh or start a terminal). alias, functions in linux

7. for loop in Linux

8. while loop, if-elif-else loop in linux

9. Defining arrays in linux, using echo commands
echo -n
echo -e

10. Using bash/linux to read a file, defining each columns of a file to different variables, Internal Field Separater, IFS

  • Utpal Kumar (IES, Academia Sinica)