All PhD students in our department (EE), in the Lyle school of engineering (SMU), are required to give a 15-min lunch-time talk in front of fellow PhD students and professors at least once every semester. This short-time talk/presentation, called the “Brown Bag Talk,” is meant to help PhD students in many ways, such as improving presentation skills, networking skills, etc. In addition, it encourages interaction among students, who are usually working in their own problems, to know about others’ work. However, the talk is not necessarily limited to one’s own PhD problem.

So, when it was my turn to lecture, I decided to talk about the use of open-source tools in research. In particular, I wanted to concentrate on two open-source tools that I regularly use in my everyday work — Python and Zotero. Zotero and its other free and open-source alternative, Mendeley, are very powerful and easy to use citation management system with lots of other useful capabilities. I also demonstrated few of the useful features of Zotero and some of the interesting language capabilities of Python during the presentation.

Here are the slides (images) from the presentation. The presentation contain animations, so I have provided a link to download the slides (powerpoint) from slideboom at the end of this post. Please feel free to use it as it may seem fit.

Also, here is the code I used to quickly demonstrate some of the features of the Python language.

#Demonstration of "range" function to create a sequence of numbers range(10) #[Out]# [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] #The above command used the "range" function to create a list of numbers between 0 and 9 #Now, suppose we want to create a sequence of "squares" of numbers between 0 and 9, it is very simple ... [i**2 for i in range(10)] #[Out]# [0, 1, 4, 9, 16, 25, 36, 49, 64, 81] #We change our mind, and now we want the squares of only the even numbers between 0 and 9 ... [i**2 for i in range(10) if i%2==0] #[Out]# [0, 4, 16, 36, 64] #Say, we needed to sum the squares of the evern numbers between 0 and 9 ... reduce(lambda x,y: x+y, [i**2 for i in range(10) if i%2==0]) #[Out]# 120 #Quick way to swap values: It is interesting in Python, because if you had to do it in C or Java, you would have to use a temporary variable, but not in Python. a = 10 b = 20 a,b = b,a # swapping step print "a =", a, "b = ", b #It works exactly the same way even if a and b were to contain large list of numbers a = range(10,20) b = range(110,120) a #[Out]# [10, 11, 12, 13, 14, 15, 16, 17, 18, 19] b #[Out]# [110, 111, 112, 113, 114, 115, 116, 117, 118, 119] a,b = b,a a #[Out]# [110, 111, 112, 113, 114, 115, 116, 117, 118, 119] b #[Out]# [10, 11, 12, 13, 14, 15, 16, 17, 18, 19] a = range(1000) b = range(5000) a[-5:] #display the last five elements of a #[Out]# [995, 996, 997, 998, 999] b[-5:] #display the last five elements of b #[Out]# [4995, 4996, 4997, 4998, 4999] a, b = b, a a[-5:] #display the last five elements of a #[Out]# [4995, 4996, 4997, 4998, 4999] b[-5:] #display the last five elements of b #[Out]# [995, 996, 997, 998, 999] ##MATH STYLE RANGE COMPARISON: pi = 3.17 assert 3.14 < pi < 3.15 0 < pi < 4 #[Out]# True 0 < -pi < 4 #[Out]# False ## This is going to blow your mind ... Python allows one to do time travel and look into the future. Allow me to show you ... 5/10 #Lets say we are trying to divide 5 by 10. #[Out]# 0 #humm ... we get "0". Well, it is not surprising when we realize that it is doing integer division. One simple solution would be to use the "type coercion" like so 5.0/10 #[Out]# 0.5 #Now, this is the part that is going to blow your mind!! The language developers have decided to make the division a "real division" by default in future versions of Python. And it turns out, WE CAN VISIT THE FUTURE IN PYTHON and use real division, like so from __future__ import division #Now, lets do 5/10 again 5/10 #[Out]# 0.5 # voilà!! We have integer division!! ## LETS SEE SOME MORE FEATURES OF THE LANGUAGE #Suppose, s is a container object s = '1234' #(this creates a string, but it could be a list as well as other container types in Python) #We can quickly reverse it like so s[::-1] #[Out]# '4321' #Now, this is powerful enough for us to write a SINGLE-LINE palindrome checking program: s == s[::-1] # obviously the above string is not a palindrome, so we should expect a false returned #[Out]# False s = s+'321' # now we make the string a palindrome s #[Out]# '1234321' s == s[::-1] # we check again, it should return true #[Out]# True ## LETS USE THE LIST COMPREHENSION FEATURE FOR LITTLE MORE COMPLEX PROBLEMS from math import pi, sin from math import pi, sin, exp #Say you want to plot one period of the sin function. Normally in a C/C++ or Java program, you would use a for loop. In the "vanilla" python you can use more more efficient constructs like a "list comprehension" x = [2*pi*i/100.0 for i in range(100)] y = [sin(i) for i in x] #To visually see the sin function (i.e. to plot it) we need to import a plotting library (package) called matplotlib import matplotlib.pyplot as plt myplot = plt.plot(x,y) #Now, lets try to create a 2-dimensional function and plot it (remember that we are still using "vanilla" python. #we will also create a small function def myfunc(x,y): return (x+y)*exp(-0.5*(x**2 + y**2)) x = [i/100.0 for i in range(-100,101)] y = [i/100.0 for i in range(-100,101)] #Lets see the first and last 10 values of x (or y) x[0:10] #[Out]# [-1.0, -0.99, -0.98, -0.97, -0.96, -0.95, -0.94, -0.93, -0.92, -0.91] x[-10:] #[Out]# [0.91, 0.92, 0.93, 0.94, 0.95, 0.96, 0.97, 0.98, 0.99, 1.0] z = [[myfunc(i,j) for j in y] for i in x] #[[evaluate function ... innerloop] outer loop] plt.imshow(z,origin='lower') #[Out]# plt.show() #We can also see a surface plot. You could use matplotlib for that. However, we will use another good plotting library called Mayavi for that. from mayavi import mlab as mmlab mmlab.clf() mmlab.surf(x,y,z,warp_scale="auto") #[Out]# #We are in IPython (QtConsole, opened with --pylab option). This is very much like a Matlab environment #Ways to generate range of numbers x = arange(-1,1.01,0.01) #using numpy's arange y = linspace(-1,1,201) #using numpy's linspace print x[0:10] print y[0:10] #Lets rewrite our function def myfunc(x,y): return (x+y)*exp(-5.0*(x**2 + y**2)) #now, instead of using python's list comprehension, we can generate range of numbers and grids just like we do in Matlab. x,y = mgrid[-1:1:201j,-1:1:201j] z = myfunc(x,y) plt.imshow(z, origin='lower') #[Out]# <matplotlib.image.AxesImage at 0x81de710>

Here is the link to the PPT (you might have to create a free account to download it. However, you can view it without creating any account):

http://www.slideboom.com/presentations/630734/Open-Source-Software-In-Scientific-Research