Thursday, June 19, 2014

Wait, Midterm blog post already?

It's almost been five weeks since my project started - FIVE weeks! I have no idea where they went. All my days over the past few weeks have kind of blurred together in my memory. As I started writing this blog post I tried to count the number of weeks and tried to remember what I did each week. So wait, it's been five weeks? "Hmm, let's think. I spent about one week getting my hands wet with WCSAxes, then I spent about one week implementing a tricky feature, and then one week writing a testing framework and then one week working on smaller bugs and writing documentation. But that's only four weeks - where did the fifth week go?" And then it hit me, I'd spent about two weeks writing a testing framework. It took me a good ten minutes of sorting through my GitHub commit history to realize that. It's strange how when you look back at things, every task seems like it shouldn't have taken as long as it did.

Like I said, I've spent two weeks so far developing a testing framework for WCSAxes. So what does the testing framework entail? As I've explained in my earlier posts, WCSAxes is a framework for plotting astronomical images so ultimately we want to make sure it plots all those images correctly. If a developer makes changes to the code, then we want to make sure there's a way to test that the new code doesn't break things, like labels being added on top of each other in an image for instance. Matplotlib has an image comparison method that I decided to use in our tests. It compares images pixel by pixel and if the root mean square value of the difference is larger than a defined tolerance level (which we can set to whatever we want), then the test fails. I had to learn a lot more about the pytest unit testing framework that Astropy uses, along with learning more about fixtures and decorators to make these image unit tests a bit easier for users and developers to work with. Also I've realized that I hate decorators, I really do. Using them is simple and great but trying to write one? Not so much. I tried to make my own decorator for one task, failed and then decided to use a fixture instead. And hey, the fixture works just as good so I'm happy.

More interesting things I've learned about? Travis. Ah yes, I love Travis, but it gave me some serious headaches for a couple of days. There were some image tests that I wrote that passed easily on my machine but would fail on the Travis CI build and I had no idea why. Eventually I took out some semi-obscure font and style settings taken from Matplotlib which Travis and my machine were interpreting differently (that's the only way I can describe it) and got the image tests to pass.

I haven't adhered very strictly to the proposed project timeline from my application. This week I worked on cleaning up code from my pull requests, getting them merged and updating the documentation. Things have been pretty fluid and I've been getting things done on more of a priority basis. We're almost at the point where we can release the first version of WCSAxes except I just need to finish up the documentation and fix/implement two bugs/features. Random things keep popping up that I need to work on before I can get to other things such as some little bit of code failing with Python 2.6 or the latest developer version of Astropy but hey, it keeps things interesting. I'm at that phase in the project where I care so much about it that I can't stop working on it. I pretty much spent the whole of last weekend working (yes, my social life is kind of sad at the moment) and I don't stop working until late at night. Even if I'm not actively coding, I read up on documentation of similar packages or read the last 50 commits on the Astropy Github repository. This project has officially taken over my life, and you know what, I'm having a pretty great time with it!

Sunday, June 1, 2014

Week Two is done!


The past two weeks have been a lot of fun! This will sound cliché, but man time flew by. For the first week, I was traveling back to Pakistan so I couldn't get a lot of work done during the first two days. Once I was back home, I kicked into working mode and had several tasks to get done. I mainly spent my first week familiarizing myself with the tools I will need for my project.

I first experimented with the existing WCSAxes code and plotted different images to see what features the package currently has. I also learned how to set up different environments so that I can work with different versions of Python and different Astropy versions, which will be really important when I have to check the compatibility of WCSAxes with different environments. I then started working on implementing a feature that will allow users to set the units of the axes on their image plots.

I haven't really talked about what WCSAxes does yet so I'll do that now. WCSAxes is a package that is intended to allow astronomers to produce high quality plots of astronomical images for publication purposes. Currently there are several packages in Python out there that do this, but as Astropy aims to produce a single core package in Python for Astronomy, we want to add this to Astropy as well. Generally, astronomical images are stored in FITS files containing other information such as the scientific coordinate systems. An example illustrating the initial implementation of WCSAxes is



This is an image of a data cube with the x-axis representing the velocity and the y-axis representing the coordinates. As seen, the x-axis has ticks labeled of 10,000 and 20,000 m/s and it would be useful to give the user flexible control over this. After implementing this feature, WCSAxes now allows users to produce an image like this
                                         

In this image, the x-axis now has ticks labeled 10 and 20 km/s!

Another issue that came up was that with the latest release of Astropy coming up soon, some of the code in WCSAxes which depended on the astropy coordinates package would stop working. I then had to identify what was causing WCSAxes to fail in a situation and use the new coordinates package accordingly.

My task for next week is writing unit tests for WCSAxes. As the code is largely based on matplotlib's plotting functionality, we might be able to reuse some of the functions from matplotlib.


So far I've really enjoyed working on my project! My mentors have been extremely encouraging and helpful so doing all the work has been a lot of fun! And since I'm a hopeful astronomer, I spend a good ten minutes every day thinking about how cool my project is and geek out. That's it for this blog post.