 Welcome to tutorial 1 of the course Microwave Remote Sensing in Hydrology, Installation and Basics of Python Open Source Programming Language. So, Python is an open source programming language which is currently trending as one of the most popular languages, which has got wide utility for applications in the fields of quantum mechanics, astronomy, remote sensing and image processing. So, my own interest with this language started a few years back when I was looking for a programming language for teaching that is open source and at the same time which is different packages that can be easily integrated together or linked to statistics and geographical information systems. So, that is when I came in touch with Python and of course it has a user community that that is growing by the day which makes tools easily available. So, through this tutorial, let us start by learning how to install Python using Anaconda environment. So, firstly what is Anaconda? So, Anaconda is a free and open source third party distribution of Python and R programming languages for scientific computing and the aim is to simplify package management and deployment and Anaconda also provides an IDE that stands for Integrated Development Environment which is called as Jupyter Notebook which is popular amongst the Python programming community. So, generally all the Linux systems have Python by default but in case it is not present, the version can be downloaded by clicking on the link shown below. You click on download and for this course I am going to use Python 3.7. So, once you begin, you will be led by a series of processes. You can see that it is almost 477 MB in size. So, for installation you just follow the steps one by one and make sure that it is installed always in the C drive to avoid any problems with say path discrepancies. So, as I click on the exe.exe file, the setup guide shall guide me through the installation of Anaconda. I click next and the license agreement pops up. I select the installation type, choose the location and of course there is the advanced installation options. So, it usually takes just a couple of seconds to complete the installation process. This demonstration is for Windows users. So, if you are using Mac OS suitable version of Python is available and also if you are using Ubuntu or Fedora, you can use an installation command. So, the last couple of seconds and the installation will be complete. Alright, so we have completed the installation. We have the basic version of Python with us now. So, now what I will do is I am going to open the Anaconda Navigator. The thing to remember is that for applications pertaining to hydrology, we may require some additional packages to be installed and in hydrology, some of the frequently used packages are known as NumPy or GDAL or SciPy etc., which we will be installing at this stage. So, I can go to the command prompt and also to remember is in addition whenever we need a new package or a library, the same shall be downloaded and installed as per requirement pertaining to each of our tutorials. Okay, so then I will straight away go to the command prompt. So for installing, let me type the command which goes something like conda install and then you need to type the specific library name that you need to install. For example, if I need matplotlib, I am going to install those by typing conda install matplotlib. Similarly for other libraries, so let me just delete the library name and insert matplotlib. It just takes a couple of seconds to complete. So in the meantime, let me tell you a little bit about matplotlib which is a comprehensive library for creating visualizations and these visualizations can either be static or animated or which are interactive. So as we shall be needing these for our tutorials, I have initiated the installation. So the following will be downloaded and I proceed with a yes and it automatically starts. So now let me open the Jupyter Notebook. I can go to documents, I have already created a folder named NPTEL Tutorials. So then I can easily create a new notebook which I can name as Tutorial 1, Microwave Remote Sensing in Hydrology. So before we begin in a full-fledged manner into hydrology, it is always better to learn a few basic commands of Python and the types of data and how to write functions and that is precisely what will be covered as part of this tutorial. So let us first try to understand the data types which can either be numbers or strings. So here the command type is going to return the type of data. For example, I type i equal to 5, print i plus 1 and type i. So type is going to return the type of data. If I run, I get 6 which is an integer. So in Python, there is no need to define the variable beforehand because a variable is created the moment we first assign a value to it. For example, I can type f equals 3.6 and then print f plus i. So when I run, I am going to get the type as float, there you go. Now let us try to look at strings. Strings are nothing but sequence of characters and it requires text to be written inside codes. So let me start with my name. Say I type within codes name equals j and last equals within codes i and du. So I can type print name plus last, I may need a space there and then I can type name. Then I run, I get the display as j space into and then string, okay, fine. Now let us try to look at data structures which can contain or hold more than one data in it. So what we will do is we will try to look at the built in data structures one by one and we will start with list. So lists are usually written in square brackets and it can contain items of any data type. For example, say I want to specify the different types of fruits. So fruits as such they hold data types of same type, okay. So I am going to type fruits equals within square brackets the name of fruits separated by comma and within codes. So I will type each oranges, grapes, mango and maybe banana, alright. So the thing to remember is that in Python the indices always starts at 0. So negative indices are also allowed in Python. So the last item in the list say banana is going to have minus 1 indices and the second last item will have indices of minus 2 and so on. Now let us try to understand this properly. So I want to type fruits 0 and then I want to display print fruits minus 1 and I want to display print fruits 2 to 4. Let us see what we will get when we run this. So for print fruits 0 I get peach because as I said in Python the indices starts at 0 and for fruits minus 1 I get banana because negative indices are allowed in Python and for fruits 2 to 4 I get between 2 and 4 that is grapes and mango, okay. So the indices are 0, 1, 2, okay. I can also specify something like this say items equals within square brackets. I can have both integers, strings as well as float and when I run it is going to be displayed as it is. So basically lists as such they can contain items of any data type, okay. And here is a simple command to create a list of numbers between a range. Say I want the list of numbers from 1 to n. We use the function called as range, R, A, N, G, E range. So it has a simple syntax. Let us see how it looks like. I just type list range 10 comma 100 that is it and when I run I get the output displayed like this, simple commands, okay. Now let us look at another built-in data structure which is called as tuples. This is a sequence of values which cannot be modified. For example, I am going to type my tuple equal to Boston, Washington and say 2, okay. And I am going to type print my tuple. When I run I will get what I entered that is Boston, Washington 2. Now say I want to modify the item in a tuple, okay. Say I am going to type my tuple 1 equal to T and then let us see what happens, it gives an error because if I try to modify items in a tuple, Python is going to issue an error. So tuple is a sequence of values which cannot be modified and this is usually used when we need to specify numbers which should not change, okay, moving on. So now let us look at the third built-in data structure called as dictionary. Now as I am typing the different name of different cars as well as the model color, let me tell you a little bit about dictionaries which is a collection of unordered, changeable and indexed collection. So in Python dictionaries are written as you see here in curly brackets and they have keys and values and it can take any data type as indices. Say here I am going to type the name of different cars say Mercedes Benz and BMW and say I am going to enter the model as 432 and the color is blue, okay. Say I want to print the car name, okay. I can do the same with car model or color. So in this is of course a simple example but in hydrology we can use dictionary to store say the name of automatic weather stations AWS and their corresponding rainfall values, okay. And whatever simple commands are being shown here it will be more clear when we try to work with images which are nothing but a series of numbers, okay. So I can print the car model as well as the car name and if I run I get 432 model name Mercedes Benz and BMW, okay. Simple examples for you to understand what is a dictionary. Now let us try to look at Boolean. So Booleans are nothing but true or false statements based on a condition. For example I am going to type print 10 greater than 5. Let me give a little bit of spacing and 5 greater than 6. Let me type print 10 greater than 5 or 5 greater than 6. And if I run for the first statement I am going to get false, for the second statement I am going to get true. So Booleans are nothing but true or false statements which are based on a condition, okay. Let us try to understand about conditional statements of if, LF and else. So say I am going to type A equals int integer input enter first number. So it is going to prompt the user that is me to enter the first number and similarly I am going to type it for B enter the second number, okay. And if I run, okay let me input both the numbers as 5. Now say I want to understand how to use the conditional statements of if, LF and else. So let me type say if A greater than B, print A is greater than within quotes, B. Then LF A equal to equal to B and print A is equal to A is less than B. So let me try to show you a point where each of us struggle that is with errors. So typically in Python there are 3 kinds of errors that can occur in a program. One is syntax error what you just see on your screen. The next is runtime errors and then we have semantic errors. So it seems like we have run into syntax error. So syntax is nothing but the structure of a program and the way it needs to be written following a certain number of rules. So there are rules of structure which needs to be followed. Lines are correct but syntax is wrong. So now let me try to show you the correct syntax. So there we have the answer 5 is equal to 5, please take care of the syntax, okay, alright. So once the syntax is corrected let us now try to understand about loops. So a loop iterates over a sequence and we have for loop as well as while loop. Let us try to understand that. So I am going to type in for i in range 1, 11, print i, I will get the values from 1 to 10. A simple for loop. Opposed to a for loop, a while loop only uses end condition but increment is given with an while loop. That is the loop runs until the end condition is met. So let us try to understand a little bit about while loop. Say I am going to type i equals 1, say while i less than 11, print i and then I will type i equals i plus 1, a simple while loop, if I run I get the numbers from 1 to 10, okay. So we have covered for loop, we have covered while loop. Now let us see, let us try to understand loops using break and continue. Break and continue, okay. So in Python, break and continue statements can alter the flow of a normal loop. Because we just now saw that loops iterate over a block of code until the text expression is false. But sometimes we wish to terminate the current iteration or even say the whole loop without even checking the test expression. So this is where the break and continue statements are used in such cases. So let us go with a simple example. So firstly it is an example for loop using break wherein I type for i in range 1 to 11. If i that is a modular operator 3 equal to equal to 0, break else print i and then what we will do is we will try to look at a simple example of loop using continue, okay. Say I type for i in range 1 to 11, again the same command using the modular operator equal to equal to 0, continue else print i, please be aware of the different ways in which I am trying to use break and continue, okay. Simple error let me see, the spelling of range needs to be corrected, okay. So it says name error, so the spelling of range has to be corrected, I correct it and then press on run and I get loop using break 1 to loop using continue 1 to 10. In this particular tutorial till now we learnt how to install Python and how to install the basic libraries which are used for this particular tutorials and we were also trying to understand some simple basic commands that we will be needing throughout the tutorials. We were also trying to look at the different data structures like list, dictionaries and we were also trying to understand about conditional statements and loops that is for loop and while loop and loop using break and continue. So there are a few more basic commands which are required as part of this tutorials. So as part of tutorial 1 we were trying to understand some few basic commands in Python and we stopped at loops while loop for loop and loops using break and continue. So what we will do is we will try to continue the session by trying to learn about functions. So say I want to define a function that is going to add two numbers, so I am going to use the command def add a comma b and return a plus b and say I am going to type a int input enter a that is I want the user to input the numbers for a and b. Similarly I can type b equals int input enter b within quotes and then I can write add a comma b. So when I run I am going to be prompted to enter the value for a and simple, simple functions of how to add two numbers and say I want to use while and return. So say I am going to type def man underscore range start stop and step my list and then I can type while start then stop yes my list dot append start and start plus equal to step return my list. Another simple function we will see what it does now. So now I am going to type print man underscore range say 10 comma 20 comma 2 and then I can type list range 10 comma 20 comma 2 we will see what it does. So when I run this is what I get 10, 12, 14, 16, 18. Now let us try to understand about vector operations in Python. So for this we are going to use numpy. So numpy is nothing but numerical Python this is not part of the standard Python distributions and hence before using this numpy has to be installed in the system. So as I said before it is a library for Python programming language adding support for large and multidimensional arrays and matrices along with a large collection of high level mathematical functions to operate on these arrays. So what I have done is I have imported numpy as NP. Now let us try to work with arrays. So here I am going to use ARR equals NP dot array 10, 20, 30, 40, 50, 60. So in Jupyter Notebook the fun fact is you can print without the print function. So if I just type ARR and run it is going to give me the array. Now say I want to check the dimension of an array. I am going to use ARR dot shape to check dimension of an array, there you go 6, okay. So I can also curie in an array like for an example I want all numbers in an array that is greater than 20 say. So I can use, I can type in a similar manner, if I run I get 30, 40, 50, 60 simple operations. So as I always keep saying an image is nothing but a matrix of numbers. So for this purpose it will help us if we try to understand arithmetic operations using Python, okay, few simple basic commands. So what I will do is I will type all the commands then press run to discuss about what is obtained. So let me type A equals NP dot arrange please check the spelling of arrange it is not ARR so NP dot arrange 12 then I am going to write B equals NP dot arrange 10, 22 print AB and then say I want to add both A and B, I want to subtract them multiply them and divide them. So for each operation that I want to do I am going to type NP dot add, NP dot subtract and so on, easy simple commands NP dot divide multiply. So now let us try running so that we get the output in this manner. So I can see that it has been arranged I can see A, I can see B print A, B is also present and when I type NP dot add you can see the result here, NP dot subtract is present, NP dot multiply is present and of course towards the end we have NP dot divide simple commands. Arithmetic operations, okay and remember for this you have been using numpy. So that is why in the beginning you are typing import numpy as NP, okay. Now you can also try working with different arrays say I can display B, A so the arrays get displayed like this I can add NP dot add A, B I get result A, B addition and re-iterating for better understanding because you have the arrays displayed and you can validate the results then and there. So NP dot subtract will yield a result like this and if you want NP dot multiply A, B you run it you get the result like this, NP dot divide A, B you run it you get the result like this, alright. So now that we know about arrays let us try to understand about multidimensional arrays because images are going to have more than one bands the type of images that we are working with so they are going to be arranged in the third dimension like pages of a notebook. So it will be useful if we know the basic commands of how to handle multidimensional arrays. So what I will do is let me create one I am going to type NP dot array and use the square brackets, okay. So I have created a multidimensional array now I can display it shows up like this, okay. We can create matrix using reshape method of numpy module. So I can type NP dot arrange 9 dot reshape 3, 3. Let us see what we will get as result. Again as before we can perform the basic arithmetic operations even on multidimensional arrays like addition, subtraction, multiplication and division. So let us try out some of the basic arithmetic operations but now using multidimensional arrays. What changes here? NP dot multiply which I can use NP dot divide. These are going to be very useful when you have multiple bands and then you want to do operations with arrays or multidimensional arrays, okay. Now we can even calculate operations like inverse of a matrix. So for that we have a command L I N A L G it is a linear algebra library in numpy. So using that we can even compute the inverse of a matrix in a single line. So going to type NP dot L I N A L G dot I N V inverse of M and there you have the result, okay. So in this section of the tutorial we started with how to handle arithmetic operations. We understood how numpy can be used to perform vector operations in Python and also arithmetic operations and we learned how to deal with multidimensional arrays. Hope you found this section informative and I will see you in the next tutorial. Thank you.