Joint plot with Matplotlib - Today I am releasing a simple module to create joint plot with Matplotlib on github. Joint plot is available in the excellent seaborn library but unfortunately it’s not always available on many systems. Recently I needed this functionality, so wrote this simple module with matplotlib. The functionality is almost similar to seaborn but with limited feature. […]
Quarterly Results Analysis with Python - Every quarter when results come out, I spend sufficient hours looking at the financial results of the stocks I am tracking to elicit nagging comments from my better half. So developed this simple python script which does the analysis and generates me the PDF which I email to myself to look at during office commute. […]
OD Command in Windows with Python - I have seen OD command for last two years but had never bothered to look it up. It always remained under the surface. Life went on well without it, until now. During a recent debugging crisis, had to resort to this command for an efficient way to check binary results. All the while had to […]
Get Mount Drive from mount path in windows - Things that are simple in Linux and UNIX based system always end up becoming a head ache in windows, but unfortunately most of our work-life runs on windows. And if you don’t have admin rights to install specialized modules in your python installation, then here’s a hacked version of routine that should do the job.
Few Python Regex for FORTRAN Code - Most of my day job involves Fortran code and finding quick details is a regular need. Here are four regex in python that I have been using for some time now. Sharing it here. To Find Subroutines and Functions To Find All Call Statements To Find Variables (Integer, Double Precision, Logical, Real) […]
Simple trick to read mixed format data with numpy’s genfromtxt - Suppose your data is like the following Let’s load it with numpy using genfromtxt This prints the following Numeric data is read but not quite as what we wanted. Notice the NaN. You can supply genfromtxt the datatypes using the keyword format like dtype=([(‘f0’, ‘<i4’), (‘f1’, ‘<i4’), (‘f2’, ‘<i4’), (‘f3’, ‘<f8’), (‘f4’, ‘|S14’)]) But that […]
Quick Gantt Chart with Matplotlib - The problem: You need a quick Gantt chart for a quick proposal report and you dint have any project planner software installed. Solution: While there are many different ways, you only have access to python, well Here’s a simple Gantt chart plotter with just matplotlib. Not for rigorous use but a good substitute to make […]
Biplot in Python revisited. - Mark sent a recent email complaining the previous biplot code not working. Though I was not able to replicate his errors,but from the error message figured the error was due to the PCA numbers supplied. That reminded me of the simplification task that I intended to do on the previous version to make it work […]
Visualizing 3d Triangles With Pure Matplotlib Function - The problem: STL file is read, you want to do a quick sanity check if it’s correct and don’t have access to VTK or third party STL viewer. Solution: Use matplotlib to visualize the STL. Here’s a simple matplotlib script to visualize the STL triangles.
Matlab to Python – some code examples - Two years back, I was converting a matlab script to python, here are some of the errors that I encountered during the conversion. Found them documented in that converted script, posting them here for wider audience. Matlab to Python 1. () to  SyntaxError: can’t assign to function call 2. 1 to 0 IndexError: index […]
Pdf With Matplotlib - I thought everyone knew about but i was surprised this this little feature of matplotlib is not that known as widely as I assumed. We all know we can save a plot from matplotlib to pdf but there other little feature hiding in the backends where we can write out a multiple page pdf Here’s […]
Biplot with Python - I have plotted Biplot in Matlab and have created it using fortran in the past. Last month, while playing with PCA, needed to plot biplots in python. Unlike MATLAB, there is no straight forward implementation of biplot in python, so wrote a simple python function to plot it given score and coefficients from a principal […]
FEM in Python A Simple Start Guide - Wrote this a couple of months back. Yet another tutorial in python, if you are interested in finite element analysis. Nicely goes with this excellent tutorial on FEM. Click the below link to view the tutorial. FEM with Python
What can Software Teams Learn From Aviation? - This pycon talk combines my two passions, aviation and software development. Grab a cold coffee and watch this very interesting talk. Just a little over half an hour, if you have any interest in any of this two stream, you will like the talk. What can Python-based software teams learn from aviation? Why should software […]
Exploring Matplotlib Styles - Last week got some free time. Used it to upgrade my python installation on Mac, a long awaited task. Looking at the upgrade log, was most excited to finally see the new version of matplotlib. So launched it and went straight to the new style package. Matplotlib is great at graphs but the default style […]
A Gentle Introduction to the Finite Element Method - Almost every engineer today have some knowledge of theoretical and practical aspects of FEM. And many have played with various software packages at some point of time. Well that is enough if you just want to perform analysis but if you want to truly understand the mathematical aspects of FEM and want to get a […]
Quick Intro to 2D and 3D Visualization in Python - Posted a quick tutorial introducing visualization in python. This tutorial offers a quick look at some common 2d and 3d Visualization available in python. This tutorial is meant to give anyone a quick start in matplotlib and mayavi.mlab. The tutorial was written as part of CSRP program of AeSIAA which I am volunteering as a […]
Quick Basic Python Tutorial - I have just posted a Quick Basic Python Tutorial on github. View it here Quick Introduction to Basic Python. Short and simple for those who cannot wait to get started.
Displaying Truss - The truss program that was posted two weeks back, looked incomplete without a proper visualisations, so here’s a small VTK function written to display the truss with any quantity like stress/reactions or displacement.
Python Over Other Languages - Found this interesting Infographics on Python over other languages. There is no mention of fortran, but everything said for c++ applies to fortran via Intellipaat
Analysing Trusses – a python program - Was digging into my laptop and found this Truss program written in python. Computes, displacement, stresses and reactions.
Simple Python code to Extract Fortran Routines and its Argument - Suppose you got a long fortran file full of code, and want to parse it and get the subroutine/functions defined in the file along with its argument. Here’s a simple python code to extract all this info in one go
A Simple but useful Python tip. - Want to convert a numpy arrays containing coords from x1,y1,z1 x2,y2,z2 . . . xn,yn,zn to x1 y1 z1 x2 y2 z2 …. xn yn zn Example
An Example of Model View Controller Design Pattern with Tkinter Python - Model-view-controller (MVC) is the design pattern for successfully and efficiently relating the user interface to underlying data models. This is a useful pattern for the reuse of object code and a pattern that allows to significantly reduce the time it takes to develop applications with user interfaces. I have used MVC pattern in my ICP […]
Class version of Spring FEM in Python - Was cleaning the laptop and found this class version of the spring FEM code that I have posted earlier. Not the best implementation but Posting it here just in case…
Fortran from python – Python Binding for Fortran Code - As an aeronautical engineer, I received fortran as a legacy. From NAL to working for Rolls-Royce, work life revolves around fortran. This is the language that I have been programming for 12+ years now. That explains this many fortran related posts here and here. But from couple of years, I am falling in love with Python. Here […]
Simple Introduction To Working With HDF In PYTHON? - In May 2014 I wrote this tutorial, but stupidly made it as a gif format. Don’t know why? Today had the chance to revisit that page and I felt the GIF format made the tutorial useless, so dumped it and used ipython notebook to create a more updated but simple tutorial to get started working […]
Map Your Google Location History in 3D - Inspired by this post “Map Your Google Location History”, I re-mashed the excellent tutorial and added a new function to view google location history on a 3D globe. Basemap is cool but VTK visualisation toolkit is cooler. Check the results. And here’s the python notebook to generate the above result. Cool isn’t it?
Karhunen Loeve Transform in Python - In the theory of stochastic processes, the Karhunen–Loève theorem (named after Kari Karhunen and Michel Loève), also known as the Kosambi–Karhunen–Loève theorem is a representation of a stochastic process as an infinite linear combination of orthogonal functions, analogous to a Fourier series representation of a function on a bounded interval. Here’s an exercise I did […]
A Shorter Version…. - Looking at Voronoi with python, someone remarked it’s complicated. Well here’s the simplified version without any GUI or pluff. 4 simple lines to get the above voronoi diagram.. Do you know, voronoi has wide applications and can be used to determine optimum locations for cell phone towers.
Voronoi with Python - A few weeks back, a colleague was searching for matlab for a task to get the Voronoi diagram from some points he had. I suggested why not use #python? He was not convinced and he got hold of matlab license and did his job. But I had this itch for trying Voronoi in python, so […]
Rotate - You don’t learn cool things everyday. And today is not everyday, learnt this neat trick to rotate a matrix with a one liner in #python!!! Simple and powerful. Waiting for a chance to use it somewhere in actual code… Want to understand what’s happening visit this page by Peter Norvig, director of research Google!!
Why Choose Python now revealed? - I am playing with reveal.js for a week now. Reveal is html presentation framework. Its awesome. Love the html presentations!! Moreover Powerpoint!. Ipython notebook and reveal.js are my new presentation tool. During this week, this particular post “Why Choose Python?” is getting lot of attention, so decided to try reveal on this post… so here’s […]
Fun Experiments with Markov Chain - A stochastic process is a mathematical model that evolves over time in a probabilistic manner. Markov chain is a special kind of stochastic process, where the outcome of the experiment depends only on the outcome of the previous experiment. That is the next state of the system depends only on the present state, not on […]
Exploring AirWire with Pandas – A Dashboard from Session Histroy - Last week received my internet bill and my wife wondered how much data we are using and if someone was snooping at our wifi? Assured her, this isn’t the case but her doubt lingered. Went to the ISP website, downloaded the session data and showed her. Still not convinced, so imported the data into pandas. […]
Little Experiments with BeautifulSoup - Look at any conference related to python, web scraping is one of the topic that is always there. This prompted me to BeautifulSoup. I am toying with it for few months now, but yesterday got a real chance to use it. Here’s a small function that I used yesterday to scrape out all the test […]
Python GUI Development Video Tutorial - Found this is at google+… Useful for anyone interested in Python GUI development. Found this to be a very helpful resource for learning to use PySide. Sit back, watch and learn!!! update: if for some reason, the video do not work for you, please visit this youtube link.
Foundation of FEM - “Spring is the foundation of FEM. Understand this well and you are through in this course.” said the IISC professor as we settled on the hard benches on the first day of our 6 month FEM course at IISC, bangalore. The course proved very useful. Learnt a lot. Fortunately , being in NAL had access […]
Matplotlib Embedded with Tkinter. - I have already done this with wx and with pyqt and we know tkinter does not suck, so here’s simple demo of using matplotlib with Tkinter. Advantage of tkinter is its available as a standard module in python, so no extra downloads required.
How to Read HDF5 with Python – a simple introduction - HDF keeps coming into my world from one place or the other. A colleague is working on it, then it showed up in a side project i am working and now I stumbled on a video praising hdf5. So finally decided to dig into it and find more about it. HDF stands for Hierarchical Data […]
Simple functions to collect data from excel files using xlrd and python - It’s no secret. Excel is abused and misused in so many different ways and the most rough abuse is disregarding Excel’s inherent 2D table structure and using it to collect data as an excel based form. Recently had a task where I faced two hundred or so such forms, from where needed to pull the […]
My Netas with PANDAS - Was surfing internet and found this affidavit data filled by candidates of election 2014 in a convenient comma separated file format. Couldn’t resist myself. The tinkerer in me wanted to play with this data, so tinkering began. Using Pandas library, loaded the data and first two results brought some surprises. So spent the next couple […]
Coming to Numpy from Matlab – bookmark this - I am old time matlab user. After C and fortran discovered matlab while working in NAL. Once hooked, have not touched excel for any computation, at least in NAL. But after NAL, the trend declined, mostly due to unavailability of matlab. But now when I am write python(which I do a lot 🙂 ), I […]
Simple and Minimal File Selection GUI with Standard Python - I have a simple script which parses an excel file and does some data analysis on it’s contents and reports it as a html output. I don’t need a UI, but right now I’m prompting the user for the file to parse using raw_input which is very inconvenient. So needed to find a quick and […]
Python App to perform ICP alignment finally out - Before reading further, if you haven’t seen the demo yet, please visit this page. Go now! there’s a Raptor waiting for you. Done that.. good.. As everybody and everything is in github now a days, so have posted the code in github at this url. PythonICPvtk Check it out. Work in progress and will try […]
3 Simple Steps to fix ipython notebook error on MAC OS X - I thought I did something stupid to my installation of python on mac and python notebook stopped working. ipython works but ipython notebook went haywire. Tried reinstalling python but the problem remained. Everytime got this error when ipython notebook was invoked. Today, the lazy me corrected the problem with help from this post. It turns […]
Few examples of Matlab to Python conversions - A few days back, was converting a matlab code to python. Out of habit , I kept going back to matlab syntax. I logged all places that I made these errors. So here are the notes. Hope its of some use. 1. () to  SyntaxError: can’t assign to function call 2. 1 to 0 […]
A Semi Functional VTK ICP App – Demo - Experiments with VTK continues. My motivation got a booster when I learnt about the open source implementation of iterative closest point algorithm present in VTK. So here’s the labor of love of playing with ICP in VTK. A semi functional VTK ICP App. Watch the demo, code coming soon. Side note: The raptor used […]
GIF animation in Python in 3 Steps - GIF animation in Matlab in 3 steps is a popular post here on this blog. Learnt the technique while trying to plot the results from the Karhunen-Loeve Expansion in September 2012. Since then, I have moved from matlab to python. But I wanted to recreate that same thing in Python. This is where I have […]
Untar a Tar File With Python - Users of Mac, Linux and Unix operating systems have it easy. Along with the omnipresent zip, they do have ready-to-use tools for most compression formats built right into the operating system. Windows user lack the luxury. To unzip a tar or tar.gz format in windows, a 3rd party download like winrar is required. Reluctant to […]
Second Saturday - My daughter loves Second Saturdays of the month. Every Saturday, when she is getting ready for school, she asks “When is the next second Saturday?”. Her school’s off on second saturday. So to relieve myself of hunting for a calendar every time, wrote a little program that gives all the second saturdays for a given […]
Save and Read Numpy Data in gz format - Learnt it recently. A neat hidden feature in numpy. I use loadtxt and savetxt to transfer ASCII coordinates and other information to and fro with an in house finite element software. The quick plotting and ready availability of high level scientific libraries makes it easy to get a quick prototype up and running in python. […]
Gotchas in Python For Matlab Users - “What an odd place to put these comments!” This was my first thought when I saw this. With goal of Apprentice to Guru in mind, I was browsing through some python code and came upon this python file by Roland Memisevic. Lot of useful information for anyone moving to python from matlab.
From this to that – STL Viewer App Update….. - Had a little bit of time this weekend and kids were unusually busy among themselves, so started working on the STL Viewer App and here’s the result. In fact, making this video look longer because of the random variables running around.
Advice from an Old Programmer - Was reading the online book Learning Python the Hard Way and landed on this page, Here’s some of the things that jumped out for me. On Programming Which programming language you learn and use doesn’t matter. Do not get sucked into the religion surrounding programming languages as that will only blind you to their true […]
From Apprentice to Guru – Python Progression Path - I am using and learning python since two and half year now. But 2013 was the year, I really picked this on full throttle. Used it in many live projects for quick prototyping and experiments. Successfully completed an online Rice University course with distinction. Blogged about it here. A few weeks back, was thinking of […]
STL Viewer – a VTK and wxpython powered App - Tinkering with VTK and wxpython, got this basic app for loading and viewing STL files. The GUI is wxpython, vtk provides the STL file reader. Needs lot more refinement, than I have time to give it now. So will come back to the app latter. Tested on windows 7 and /xp. View the code here
DateLine with Python - Recently discovered geektool on Mac OS and with it geeklets. Geeklets are small programs that decorate and serve some little functions like the windows sidebar gadgets. The coolest geeklet that I like is a calendar displayed as a line. Upon investigation found many people are using a small app dateline to create the calendar. Reluctant […]
2014 – What a Coincidence? - Over at the codegolf stackexchange, there’s an interesting piece of challenge. Produce the number 2014 without any numbers in your source code Lot of different tries by many people, but I especially liked this one. What a coincidence? Don’t forget to check out the link for many other equally interesting solutions!
Time In Words with Python - Have been playing with geektool this week. While tinkering with it, remembered a text clock that I saw in Opensuse Linux. Sometime back, I wrote a fortran program to do this. But today cooked up a python script to do just that. Here’s the result. And here’s the code.
Lights, Cameras, Action : A Simple Example to Embed VTK with wxPython - Well matplotlib with wxPython is cool, but VTK with wxPython is awesome. What is VTK? The Visualization ToolKit (VTK) is an open source, freely available software system for 3D computer graphics, image processing, and visualization used by thousands of researchers and developers around the world. VTK consists of a C++ class library, and several interpreted […]
Matplotlib with wxPython example with Pan/Zoom functionality - As this post said, I don’t enjoy coding with pyQt, but somehow wxPython escapes that curfew. What is wxPython? Like pyQt, wxPython is a GUI toolkit for the Python programming language. It allows Python programmers to create programs with a robust, highly functional graphical user interface, simply and easily. It is implemented as a Python […]
Simple pyQT and MatplotLib Example with Zoom/Pan - Someone in office wanted a quick demo on how to use zoom functionality of matplotlib with pyQt. Pointed him to some good and basic matplotlib examples but none was good enough. Next day morning, just went to net and found this post titled How to embed matplotib in pyqt – for Dummies. And building on […]
Binary STL File Reader in Python Powered by Numpy - At the STL and Fortran post Don Durschmidt asked if the stl binary reader fortran code can be made faster for reading big files. As Abraham Maslow said “To a man with a hammer, everything looks like a nail” Likewise to an Engineer smitten by python, everything is pythonable. So while exploring and thinking about […]
Common Pitfalls to Avoid while converting Matlab code to Python - After fortran and excel, my most used piece of software/language/tool was Matlab. It has been a constant companion in office for me for quick prototyping. Seriously started using it when I was in NAL and ever since have used it off and on in office. Then came python and slowly python has become my numerical/computation […]
Happy Diwali and learn a simple way to create animation with python - Colorful lights, delicious sweets, and sparkling crackers. That’s Diwali. Kids are so happy. Can’t describe the joy in their eyes!!! Well to end the day, here’s a super simple python animation to celebrate Diwali. Wish you Happy Diwali!
Sieve of Eratosthenes - In mathematics, the sieve of Eratosthenes is a simple, ancient algorithm for finding all prime numbers up to any given limit. Here’s a Python Implementation of sieve of Eratosthenes. So what are the prime weeks of the year? print SOE(53) [ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, […]
Game with QPython on Android Phone - During recent visit to my native village, sitting at my cousin’s shop and playing with his android phone discovered Qpython on Android play store. QPython is a script engine running on Android devices like phone or tablet, It embeds the python interpreter, console, editor, SL4A library for android, which can make android device run python […]
The Zen of Python - So you have successfully installed python on your Mac, windows, android or ios device. Before you begin coding, here’s a simple hidden command to remind yourself of the philosophy behind python. At the python prompt type the following >>import this Try it. This will produce the following text. This is part of all standard python. […]
Why Choose Python? - Every engineer should know how to program. It makes you 10x times more productive than the engineer who doesn’t program. Having the ability to create software slaves is a big advantage, in any job, and in any domain. So which programming language to learn? You ask? Python, python and python. Following are few advantages that […]
Python VTK script to Display 3D xyz data - This Plot3 python matplotlib script is useful. But there are times when all I have is a txt or csv file with the xyz data and I just want to see the 3d view. Firing up python IDE , loading the data and using the plot3 script becomes too many steps. And the output 3d […]
Discover Some Useful Python Numpy Functions - It’s always true. Unless you actually work on something, you don’t get to the practical stuff. I have been dabbing with numpy in python for a year now but all this was academic until the time I actually used it in a recent project. And during this time, found some practical functions of numpy that […]
Happy Independence Day - Happy Independence Day. Today India is celebrating its 67th year of Independence!! Getting tired of static greetings, I created this interactive python coded animation, to celebrate the occasion. Here’s the video of the animation!! To give it a try follow this link. Click run and then drag your mouse within the black screen. Here’s the […]
Top 5 posts - These posts have been the most popular for the first half of 2013! How to create a fortran dll in visual studio? Ever green post. Always stays at the top. Lot of people converting fortran into DLL’s! Gif animation in Matlab in 3 simple steps. 3 steps is all that is needed to get a […]
Plot3 in Python – ‘almost’ like Matlab - Here’s an interesting picture titled “language family” from 1985!! Found via this blog. But this post is really about mimicking Matlab’s very useful plot3 command in python using matplotlib !! The following function gives a bare bone plot3 command in python. Plot3 in python
Number Game in Python for my daughter. - This is a game I developed for my 5 year old daughter. I used to play this when I was a kid, now with this she plays it online. Thanks to codesculptor. Its an awesome platform for using python online! I intend to develop more games for her on this platform. Play the game by clicking […]
Solving Ax=B by SVD - Solving Ax=B by inverting matrix A can be lot more computationally intensive than solving directly. Python’s NumPy has linalg.solve(A, B), which returns the ‘x’ array x = numpy.linalg.solve(A,B) It uses a LU decomposition method for solving (not inversion). SVD can also be used to solve without the need for inverting matrix A. Here’s the function […]