 Welcome to the tutorial 2 of the course on microwave remote sensing in hydrology. So in this tutorial, we shall introduce you to synthetic aperture radar or SAR image processing using Python and in particular we shall be using the LO's Pulsar data where Pulsar stands for phased array type L band synthetic aperture radar. So it is an active microwave sensor that uses L band microwave frequency. So as before, let us move on to the section and then we will discuss further, okay. So shown here are the SAR data formats. The SAR data can be made available either as a raw image that is containing intensity and phase informations or as single look complex image that is SLC image or as a multi-looked image. The table here shows the processing levels and their corresponding definitions. For example, if you look at processing level 1.1, it means range compression and one look azimuth compression are performed and that data is complex on the slant range coordinate and 1.5 means after range and multi-look azimuth compression are performed and radiometric and geometric corrections are performed as per map projections. So I realize that a few of the terminologies that may appear new to you now, it will be covered as the course progresses with time, so no worries, okay. Now firstly, let us try to understand where to access the data. So the Alaska Satellite Facility or ASF data search portal can be used to get access to the ALOS Pulsar data and this is how the site looks like. You have search filters, date filters, additional filters and path and frame filters. There are different search types available, data sets available and filters if you wish to add and so on. So one can keep on exploring more as per interest, okay. So what I will do is let me try to zoom on to India and let me try to zoom to Mumbai and maybe the campus of IIT Bombay, okay. I can see the Powai Lake. Yes, so what I will do is I will try to show how to download the ALOS Pulsar data over IIT Bombay campus. So what I need to do is I need to draw a bounding box over the region of interest. So I have identified Powai Lake, so now with a right click I need to draw a bounding box defining the region of interest, okay. So once your area is defined, search type and data set is defined, you click the search button and you will be loaded or presented with the data sets towards your left side, okay. So these are the data sets that are popping up and of course the scene details are present in the right side. So ALOS Pulsar, L band, start time, stop time and other details are also given so, okay. So I can zoom out and see how the thumbnail looks like that is also possible. So for this exercise we shall work with ALOS Pulsar data that has been downloaded in a similar manner. So before we move further a little bit about synthetic aperture radar images. So SAR image, I like to look at it as a complex number. A synthetic aperture radar image pixels are nothing but complex numbers that stores both amplitude as well as the phase information. Because you know when an electromagnetic wave is getting scattered from a position say having coordinates x, y on the earth surface, the physical terrain is causing changes in both the amplitude as well as the phase of a wave. And the synthetic aperture radar in fact measures this number pair which is nothing but A cos phi and A sin phi where phi is the phase and A is the amplitude. So the local reflectivity at each pixel can be represented by the complex number and hence SAR data are known as complex images. So from these complex images one can calculate the intensity which is given by i equal to a square and usually the amplitude intensity and log images are easier to interpret than the phase image. So hence for this particular tutorial we shall be using the intensity images. And as before I am going to display the libraries which we shall be using as part of this tutorial. Feel free to pause the screen as and when required. So for this particular tutorial we will be requiring G-dial numpy that supports large multi-dimensional arrays and matrices. We will use pillow PIL which stands for Python Imaging Library which is a free open source library that supports opening and manipulating different image file formats. And of course we will be using matplotlib which is a visualization package. Let me move on and show you the functions that will which we will be using as part of this tutorial. So what I have done is I have displayed the function name as well as what it does. So for example g-dial.open it is used to open a synthetic aperture radar image. Similarly I have read as array which reads the data into an array as an array. I can get the number of bands of an image using get raster band function and I can create an intensity image using numpy.absolute. I can compute the face using numpy.angle. To display an image I can use plt.imshow command and say I want to flip an image upside down. So I can use the np.flipboard function and I can even stack the bands to create an RGB image using the numpy.dstack function. And of course to create an array I can use numpy.array. So again these are the specific functions which will be used as part of this tutorial and feel free to pause as before. So what to do to get started? So to get ready as before let me go to the command prompt and type the commands one by one. So first I am going to type the command conda create n g-dial to create an environment. So it is already created in my system that is why it is displaying remove existing environment. If you are doing it for the first time it starts creating. So if you have not already done so then this is the first thing you have to do, create an environment. So I am going to type yes and the next thing to do is I need to activate the environment. So these are the commands for that conda activate g-dial. So g-dial stands for geospatial data abstraction library gdal. So it is an efficient tool to work with rasters especially when you are using remote sensing data sets in python. So yes so these packages are going to be installed as before I proceed with a yes command. So as I was saying g-dial is highly efficient to work with remote sensing data sets in python and here in particular we shall be using g-dial to open volume file consisting of all the bands and metadata of the SAR data. So as I am installing g-dial you will have noticed that the related packages get installed one by one and usually it just takes a couple of seconds to complete the installation. So I think we are almost done here and remember always for plotting purposes we need matplotlib now that you are slowly getting familiarized with the different libraries that will be required as part of the tutorials. So once the process is completed I am going to type as before conda install jupiter proceed yes just a couple of seconds and these tutorials have been designed for a windows user. So just a disclaimer there. So once all the downloading and extracting packages are completed we are good to proceed. So I am going to install matplotlib for visualization the following new packages will be installed of course yes okay. So now we have created a new environment we have downloaded all the necessary libraries and then now I am going to open the jupiter notebook from here. So this is what my screen is going to look like okay. I can go to documents I have already created a folder named NPTEL tutorials and I already have a jupiter notebook which is empty of course but which is named tutorial to microwave remote sensing in hydrology okay. So first let us try to import all the necessary libraries that is the first thing we do. So I am going to type from osgeo import g dial okay remember g dial is nothing but geospatial data abstraction library and then of course I am going to type import numpy as NP import matplotlib.pyplot as plt from p i l import image and import math. So now I have imported all the necessary libraries now what I need to do is I need to specify the file path where the alos pulsar data is present yes. So as you see here I have specified the file path where the alos pulsar data is present and I am going to use the volume files that is why VOL okay. It has a lengthy nomenclature the file name is very long and if you want to know about the specific nomenclature that is used for alos pulsar data I would suggest that you check the product format description by the ESA that is European Space Agency okay. Now after specifying the file path let me open the same. So this is the file path that I have typed in where the downloaded image is present. So now I want to see how the data looks like. So I can type the command g dial dot open file path okay it gets saved into pulsar. Now say I want to know how many number of rows are there in the image how many number of columns are there or how many bands does the image contain. So I can use simple commands like this raster x size which gives the number of columns of an image and raster y size which gives the number of rows and of course raster count gives us the number of bands. So I have used raster x size, raster y size and raster count and I have run it. So I want to see the values. So I get the number of columns as 4640 number of rows as 18 432 and it is a two band image okay. So we have learnt to download the allospulsar data so far. We have learnt to specify the file path of where the file is downloaded is available and to open it using the g dial dot open and also we have understood how many rows are there, how many columns are there and how many bands are there for the image that we downloaded okay. Now before we move further there are a few terminologies which I feel this is the right time to introduce them. So to begin with electromagnetic waves consist of electric and magnetic fields which tend to oscillate in a mutually perpendicular direction as well as they are perpendicular to the direction of travel of the wave as shown here you know and the perpendicular polarization planes are called vertical and horizontal with reference to the earth's surface with usually x direction taken as horizontal and y direction taken as vertical. So in order to describe how a wave travels we use this property known as polarization wherein the direction of polarization is usually taken to be that of the electric field vector and not the magnetic field vector. I am making a distinction here because most of the common manifestations of electromagnetic radiation are due to the electric field and not the magnetic field. So in this context we have some terminologies common terminologies that are used here like say H H which means horizontally transmitted and horizontally received and we have V V which means vertically transmitted hits the target and then vertically received. We have H V polarization and V H polarization where every time H stands for horizontal and V stands for vertical. With this background let us try to separate the H H and H V bands of the LO spalsar data using get raster band commands a few more commands we will understand as we proceed in the tutorials. So by now we know how many number of rows columns and bands are there in the image. Now what I want to do is I want to separately see how the H H band looks like and how the H V band looks like. So let me use get raster band. So I am going to type palsar dot get raster band 1 H V equals palsar dot get raster band and I am going to run it. Now we can read as array both the H H and H V bands using the read as array function as was displayed in one of the previous slides. Say I want to read it separately into an array. So I use H H dot read as array I am going to name it H H dot underscore a r r and H V underscore a r r. Remember in programming it is highly important how you name a file do not name like 1 2 3 you will find it difficult to understand what you have saved. So I am going to save it with the appropriate name H H underscore a r r and H V underscore a r r. What are these? These are the arrays. So I have used the read as array to read the H H and H V bands separately into these. And as discussed in one of the earlier slides now we want to estimate the intensity image and that can be done by calculating the absolute values. So what I will do is I am going to type H H underscore intensity that is the name I have given equal to NP dot absolute H H underscore array square and similarly a command for H V underscore intensity. Okay. I can run it. So NP dot absolute function it calculates the absolute value element wise. Now say I want to visualize how it is going to look like. So I can use these commands that is PLT dot subplots 1 comma 1 fig size 12 comma 8. So 1 comma 1 stands for 1 row 1 column okay and fig a size fig size means 12 and 8 these are subjective they just means number of units in the x direction and y direction basically the aspect ratio. So then I am going to use PLT dot IM show okay NP dot angle H H underscore ARR CMAP is nothing but the color map. So here PLT dot subplots it creates figures and multiple axes and PLT dot IM show it is used to display data as an image and PLT dot color bar it is used to add a color bar. So simple examples to help you understand how to visualize an image okay. So you wait for a few seconds and you get the image displayed like this. So again fig size is how many units in x and y direction it is subjective and as you can see in your screen the figure is a grayscale image. So it contains grayscale intensities you can see the number of rows and number of columns. Now let us try to understand what NP dot where does. So NP dot where is a function which returns the indices of elements in an input array where the given condition is satisfied. For example I can type H H underscore intensity equal to NP dot where H H underscore intensity equal to equal to 0 and similarly you know I can have another command for H V underscore intensity. So NP dot where is a function that returns indices of elements in an input array where the given condition is satisfied okay. H V underscore intensity alright and as before let us try to visualize how the figure looks like. So we are going to use PLT dot subplots PLT dot IM show and PLT dot color bar. By now you must be familiar with these functions. So I am using NP dot flip board which is used for flipping an image for flipping array so that the resulting image is not displayed in an upside down manner okay. Now just to see how the natural log of the intensity image will look like as before I am going to type PLT dot color bar and when I press run I can see the figure just takes a couple of seconds and there you go you have the figure. So at least some faint features are visible isn't it? This is how the natural log of the intensity image is going to look like. So in this part of the tutorial section till now we try to understand about synthetic aperture radar image processing using Python. So in particular we understood how to access the LO spalsar data, how to download it, how to open it in Python, how to separate the HH and HV bands of the image and how to do basic operations, how to visualize the image, how to calculate intensity values and so on. So now we will try to understand about multi-looking of SAR image. So I am giving you a new term here multi-looking. So multi-looking of SAR image is performed to make rectangular pixels to square by converting from slant range to ground range geometry. So in your screen you can see SLC image and a multi-looked image and the difference can be self-explanatory. So another advantage of multi-looking is that it reduces speckle in the image considerably and let us try to understand multi-looking in layman language. So the independent measurements can be obtained by splitting the synthetic aperture Doppler bandwidth and each of these independent measurements can result in separate images which are called as looks and the process of averaging in intensity is known as multi-looking. So with the resultant image called as L look. So it is to be noted that each look should be in the same position without any relative radiometric distortion and they need to be measured at the same frequency and polarization. Again you know there may be few terminologies that are appearing here which may be new to you but rest assured these will be covered as the course progresses with time. So shown here is a sample of how an SLC image looks like and how a multi-looked image looks like. You can easily see the difference very prominently, isn't it? Now for the sample exercise for this tutorial I have illustrated graphically what we are about to do for the sake of clarity. So shown here is an SLC image with rows, azimuth, columns, range and what we are about to do is to convert it into N look image or L look image. So the illustration shown here is how to convert an SLC image into a two look image. You can see what we are doing it is nothing but we are trying to make the rectangular pixels to square by converting from slant range to ground range geometry and we are performing averaging in intensity and hence the name multi-looking. Now with respect to LO spalsar data we can even calculate the optimum multi-look number for the LO spalsar data and this part is covered in the lectures. So for the sample exercise for this particular tutorial we have calculated the optimum multi-look number. So let us try how this can be performed, how multi-looking of SAR image can be performed in Python. So here I have added the number of looks, num looks as 5 and I have entered NP dot array range from 0 to num looks multiplied by maths dot floor and then the expression is in front of you. So here NP dot array is for creating an array, range is from 0 to the number specified and maths dot floor is for rounding to the nearest integer. A colon operator, a colon is used to fetch data and index ranges or arrays. So we get to specify the starting and ending index and separate them using a colon. So what I am going to type is looked hh equal to hh underscore arr which is nothing but the array that we have seen earlier within square brackets ind which we just typed and colon and similarly I can type a command for looked hb and I can run it. So now I am going to type for i in range num looks plus 1 for look in range num looks minus 1 looked hh equal to looked hh plus hh underscore arr within square brackets ind plus look and then colon. So remember colon is used to fetch data and index ranges or arrays. This is just one example, one sample code I am showing. Feel free to explore your own version of this particular code. Sample images are shown here for a single look, for two look in azimuth, for four look in azimuth and for 10 looks in azimuth and two looks in range. So in this part of the tutorial 2, we started with trying to understand about synthetic aperture radar image as a complex number and then we downloaded the LO spalsar data, we opened it in python and we tried to use some simple functions to look at the number of rows and columns and bands that the downloaded image contained. We try to understand about polarization and then we try to visualize the data using plt.subplots, plt.imshow and plt.colorbar. Also we learnt about what is multi-looking of synthetic aperture radar image and a sample code was presented. For this particular section of the tutorial, we shall be using the LO spalsar data which was downloaded for Mumbai region and as before I hope you are familiar with the processing levels now, processing level 1, 1.1, 1.5 and what they mean, we have already covered it as part of tutorial 2 and by now you also may be aware about what is INQ that is intensity and phase information in a synthetic aperture radar image. Now firstly, let us try to understand about what are sigma naught images. So, most of the active microwave targets are earth surface rather than individual targets. So, here we are talking about the earth surface and for a radar system when it transmits energy, that energy is getting incident upon the target and here the target is earth surface and among the incident energy some proportion of it shall get scattered from the target. Again by target again I am referring to distributed target area that is the earth surface and not an individual target. Why I am emphasizing this is the area of distributed target in imaging systems is related to the image pixel where pixel is the smallest unit of an image. But then if we want to compare say the measurements from different instruments, this poses a problem. The summary is we would like some sort of a normalized measure which is independent of pixel or footprint size which means we need to relate the target area that contributes to scattering to the actual geometric area of the ground surface. And this is what is called as normalized backscatter coefficient and in radar remote sensing it is also referred to as sigma naught images. Now again this is also called as differential radar cross section or normalized radar cross section that is NRCS etc. and it is unitless. So sigma naught is the actual property what we are interested in as it is not instrument specific. So in this particular tutorial we are trying to understand or decipher sigma naught imagery from the LO Spalcer data. So in front of you you can see an empirical relationship wherein i refers to the real part of the synthetic aperture radar imagery, q refers to the imaginary part and c, f1 and a are nothing but the calibration factors. So what we did is specific to the LO Spalcer dataset which was used in this particular tutorial we have estimated the values of c, f1 and a and used these constants for our conversion to sigma naught imagery. So again let me re-iterate for this particular tutorial it is specific to LO Spalcer dataset. If you try to use a dataset from some other satellite again the constants the calibration factors are going to differ. Now let us try to understand how to perform the conversion in Python. So NP log 10 is a mathematical function that gives us the natural logarithm of any array with base 10. So we are using NP log 10 and NP dot absolute. NP dot absolute here calculates the absolute value element wise. So as you can see I have entered the constants 83 and 32 specific to the LO Spalcer L 1.1 data to estimate the sigma hh and sigma hv. Here h refers to horizontal v refers to vertical and by now you are aware that hh and hv are nothing but polarization horizontal transmit horizontal receive that is hh and hv is horizontal transmit and vertical receive. Now what I will do is in addition to writing a statement to calculate sigma hh and hv let me try also to write a simple line which gives me sigma hh minus sigma hv that is I am trying to do image differencing here. So now that we have the sigma hh and hv values let us try to use something known as a d-stack function. That is why the title is kept stacking to generate RGB plot. So d-stack is equivalent to concatenating an array along the third dimension or third axis and say you want to create an RGB image using three bands of say sigma hh, sigma hv and sigma hh minus sigma hv. How do you do that using python? So let us see how we can perform this operation. So firstly I want to normalize the array that is why I am using np.max which returns the maximum value and np.min that returns the minimum value. np.min sigma hh. Similarly I can get the normalized form for sigma hv as well by using np.max and np.min. So here what am I doing? I am normalizing the image so that I can directly use the d-stack function. So let me write a similar line of code for normalizing the sigma hv image and remember as the third band we are using sigma hh minus sigma hv that is we are trying to work with image differencing. So let me follow a similar line of code to normalize the sigma hh minus sigma hv component. np.max sigma hh minus hv minus np.min sigma hh underscore hv yes. Now say you know I want to directly use the d-stack function and say I want to visualize the plots side by side. So as I said earlier d-stack is nothing but you are concatenating an array along the third axis and the function you use is np.d-stack and then you write all the components that is sigma hh underscore norm that is normalized component of sigma hh normalized component of sigma hv and then normalized component of sigma hh minus hv. Now as I said earlier for visualizing the plots as subplots side by side we can use a function known as plt.subplots and imshow. Say the image that I am dealing with say it is huge and I am specific to display a certain number of rows and columns even that is possible. So in the first line it is plt.subplots 1, 3 1 row 3 columns figure size 14, 22 that is specific number of units along the x direction number of units along the y direction. And then as axis I am using the imshow function and for sigma hv I want to display only the rows from 500 to 1500 and the columns from 2200 to 3000. It so happens that if the image you are working with is large huge in size may take some time for the mathematical operations to be completed and that is why you know quickly you can specify the number of rows and columns on which the operation has to be performed so that you get a quicker output. So I am trying to use the imshow function here. CMAP is nothing but the color map that is gray. So as the third axis I am trying to show the RGB. So what am I trying to show? I am trying to show you three figures arranged side by side. The first figure is nothing but sigma hv, the second figure is nothing but sigma hh and the third figure is nothing but the stacked RGB image. Right? Let us see how to visualize the image which is going to look something like this. You can even add titles to it. So you have the leftmost image sigma hh in the middle sigma hv and then the RGB image towards the right side. So what we did just now was to estimate the sigma not imagery and also to use the destack function to create an RGB image. Now in Python it is also possible that you can get to crop the images and maybe you can save the image, open the image. There are some simple commands available for that. So now let us try to understand simple means of how to crop the images. So for this particular operation I am going to use the plt.im save function. It helps to save the image as the name suggests and here I am specifying the format as well .png format. Now which means I want sigma hv image to be saved as sigma hv.png and I am also flipping the image. Turning it upside down, flipping the image using a function np.flippled. Again cmap is nothing but color map. Simple lines to let you save an image. Sigma hh, cmap equal to gray. So now let us try to load the image. To load the image remember we import the image module from pillow and call the image. So that is why the line is written from pil import image. So we are importing the image module to call the image. So once done I can use the image.open function to open the image. So now I am opening the image.size gives you the number of rows and columns which are saved in w,h. So hv.size gives the count of number of elements along a given axis and a simple command hv.crop lets us crop the image. So here image left upper point is specified as 500, 500 and the right lower point is specified as w-1000 and h-2000. So what I will do is just for the sake of consistency I am going to write a similar lines of code for the hh imagery as well. Simple functions image.open, hh.size that is dot size whatever comes in front is up to you and then dot crop. So I have cropped the image both hh image and hv image and I have also specified the left upper point and the right lower point. np.array gives you a grid of values all of which are of the same type and which are indexed by tuple of non-negative numbers, non-negative integers. colon, colon it means start, stop and step. Colon, colon 1 means start, stop and step. Simple means of using numpy arrays. So what we learned just now is how to save an image in a particular format, how to open an image by calling in the image module from pillow and then how to estimate the size of the image that is how many number of rows it has, how many number of columns it has and how to crop an image. Simple operations which will be helpful once we move on to statistics using Python. So overall in this part of the section we learnt how to convert sigma not images from L 1.1 of LO's Pulsar data and we understood how to stack the images into RGB and finally we went through the simple operations of cropping image, saving, etc which will come in handy as the tutorials progress with time. Hope you found this section useful and I will see you in the next class. Thank you.