Monday, August 18, 2014

And GSoC is over..

This has been a really hard blog post to write for me because every time I would sit down to write something, I'd feel sad about my Summer of Code ending. I've had a such great time working on my project for the summer! It was different from anything I'd ever worked on before, it was challenging but not so much that I'd want to pull my hair out in frustration and on top of that, it was relevant to my own academic interests.

Overall, I've pretty much finished what I'd said in my proposal. Though there was one thing which I never got to, working with NDData, an Astropy class sort of similar to Numpy arrays but since NDData is still under development, we decided to not focus on it. Other than that, I worked on adding a lot of other features and fixed bugs as we discovered them, something which I didn't anticipate in the beginning but took up a significant bit of my summer (in a good way of course). WCSAxes is now in a pretty good place - we did our first release in early July and I just released a second version last week with some bug fixes and new features. I also have write access to the repository now! :D Integration of WCSAxes into APLpy is also pretty much finished. There is one non-trivial issue we need to find a solution to but it's of a low priority so it's fine.

There have been some roadblocks along the way, but nothing too unmanageable. If I did get stuck, my mentor was there to help me figure things out. This is where I should thank my mentor, Tom, for always being available and supportive, explaining things clearly and just being great to work with! :) 

I'm also planning to continue working on WCSAxes once GSoC is over or maybe see if I can contribute to something else for Astropy or an Astropy affiliated package, but that also depends on how much work there is for me to do and if it fits me. I really hope I do find things to work on because I've learned so much about the tools available in Python for astronomers by working with Astropy. 

Well that's it, I guess. I hope you've enjoyed reading about my summer!

Monday, July 28, 2014

Note to self: testing is really important

It's been an interesting couple of weeks. As I mentioned in my last blog post, I've been working on integrating WCSAxes into APLpy. It was going pretty well in the beginning but now things are starting to get complicated (just to be clear, I'm not complaining!). APLpy isn't a very big package but it still has a lot of features which I need to make sure work as I integrate WCSAxes into it. *THAT* is the tricky part. This means extensive testing after small re-writes of code to make sure new features work and I haven't broken something that was working previously. Well, that's the ideal workflow - I should have been doing extensive testing this way but sigh, I didn't. I've almost (I feel like the coyote who's *almost* caught the roadrunner as I say this) made most of the new code work but over the past few days I got so wrapped up in cleaning bits of code which I didn't test out fully that I broke a pretty important part of APLpy, plotting data cubes. I'm not sure where I broke it and my commit history is a mess (because I kept committing changes without testing them out fully again) so git bisect didn't help me identify where the problem started either.

This week is Eid, an Islamic holiday (Eid Mubarak to any Muslims reading this!!) so I won't have that much time to figure out where I introduced this bug, but once I do, I'll probably stock up on Pepsi, blare loud music in the background and carefully comb through my branch to examine all the code changes. That's it for now! :)


Sunday, July 13, 2014

Weeks 7-8

I just counted and so far I have 14 merged pull requests which makes me really happy! Not all of them are huge PRs, a few of them are minor documentation changes but some of them took a bit more time to work on as I was implementing some new feature in WCSAxes or fixing some bug.

The latest thing I've been working on is integrating WCSAxes into APLpy. So APLpy is an Astropy affiliated package that also plots astronomical images and uses matplotlib for all the plotting tasks. My current task is to make changes to APLpy so that it uses WCSAxes to locate and plot all the ticks, labels, grids etc instead. So far things have been going pretty smoothly. Most of the functionality of APLpy is in place - there are a few small things here and there but I'm not too worried now that it's mostly working. Things have been going so smoothly in fact that I started to get a little bored with the work and consequently, my productivity decreased significantly.

Tom, my mentor, was at a conference this week so I haven't had a Hangout with him and discuss my latest work, which might also be why I haven't been very productive this week. I think my brain perceives our weekly Hangouts as deadlines where I have to report on my progress and that keeps me motivated. I like deadlines - there I said it! Well maybe having stressful deadlines all the time wouldn't be very pleasant but deadlines are kind of fun. They keep you focused and there's that edgy feeling you get close to the deadline 'can I finish this in time?!' Usually I just set my own personal deadlines like 'I have to get this thing done in two days, maximum four days' etc and that keeps me happy but like I said, I got a little bored.

Towards the end of the week, Tom said I could try implementing another feature in WCSAxes if I wanted so I decided to focus on that instead. Currently WCSAxes only plots major ticks but it would be useful if it could plot minor ticks as well.


(In case someone doesn't know about major and minor ticks from matplotlib, the red ticks are minor ticks and the black ones are major ticks. Also this is just an image produced with matplotlib, not WCSAxes)


This is a bit tricky because so far I haven't had to actually understand the math behind WCSAxes' calculations but now might be the right time to understand how it works. I currently have a very faulty implementation of minor ticks but it's fun to work on and hopefully I'll figure it out! :)

Tuesday, July 1, 2014

Weeks 5+6

You know that feeling when you think a task is going to be super hard but once you get to it, it turns out to be easier than you expected? And once you've finished it, you feel like you're the best programmer ever? I've been on that high for the past few days so I think I'll make a blog post while the feeling lasts.

Over the past two weeks or so I've been working on three tasks. The first thing I worked on was to implement different coordinate systems into WCSAxes. Previously, WCSAxes only allowed users to convert coordinates to the systems FK5 and Galactic but since there are a lot more coordinate systems out there, WCSAxes should be able to handle them. Like I said, this turned out to be pretty easy. The hardest part was probably refactoring the code to make it clean and efficient, but other than that I just had to use the Astropy method 'lookup_name' method to look up the correct coordinate class. Although, since this method is only available for Astropy 0.4, someone using WCSAxes with older versions of Astropy is limited to the old coordinate systems.

The second thing I worked on was a bug with the way axis labels were positioned on images. Previously, WCSAxes always tried to place axis labels as close as possible to the axis without intersecting with the tick labels.

but if the tick labels are in the way, it pushes the axis label further away
This could get annoying in certain situations and people preferred that axis labels always be positioned below the tick labels, whether or not they intersect. I had to read up on matplotlib's code to figure out how they position labels and tried to implement a similar way. It was a bit tricky since Matplotlib and WCSAxes handle ticks, labels and axes very different but luckily I was able to figure it out! And the results are

See? The axis label is now below the tick label by default! Users now also have the ability to adjust the padding of the axis label so they can move it as close or far away from the axis as they wish :)

The third thing that I've been working on is writing a wrapper for the package APLpy that uses WCSAxes. There are several packages out there that are used to plot astronomical images and one of them is APLpy, a package that my mentor helped write. The way APLpy does the actual plotting of images isn't all that great so we're trying to write a wrapper for it that uses WCSAxes to do the actual plotting, which will allow people to still use the package. So far work on the wrapper has been going good and I haven't hit any major roadblocks. Hopefully it'll continue to be this straightforward - or maybe not, things get interesting when they don't go the way you expected them to.

Now what I'm really excited about is the first release of WCSAxes! The package is almost ready for release except for one tiny feature I have to add. The sooner I finish this post, get to actual work and finish my task, the sooner we can do our first release! 

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. 

Friday, May 16, 2014

Phase 0

Finding out I got into Summer of Code 2014 was a huge surprise. Seriously, I was not expecting it. I just thought the entire program was simply too awesome for me and there was little chance that the mentors of Astropy would 'deem me worthy' to write code for them. A large part of the community bonding period has been spent with my coming to terms with the fact that I got in and that people think that I can do this. I'm not saying I suffer from under-confidence in general, but when it comes to computer science and programming, I naturally assume so many people are better and deserving than me. I might have a case of the imposter syndrome and I haven't been very sure on how to fix it.

Yes, I'm a woman in Computer Science and a lot of the time I feel like I don't belong. I'm not sure why in my situation it's confined to my programming abilities either. I'm a Physics and Computer Science double major and I've never, ever felt out of place in any of my Physics or Math classes - it's only when I think about my place in the programming world that I feel like I don't belong.  So I'm trying to change this attitude about myself and finding out I got into GSoC has been crucial to the process. I've almost convinced myself that hey, there isn't just one kind of programmer - there IS a place for me in the community. I won't say that I'm over my doubts yet but I do think I'll be a stronger and more confident programmer by the end of the summer.

Now moving on to happier, more GSoC/technical thoughts - I am ridiculously excited for this summer! So my project involves working on the WCS Axes framework for plotting astronomical images (possibly too many technical sounding terms?) of which a basic implementation already exists. My role basically involves writing documentation and tests and once that's done, adding extra features to it. So far I feel like my project is on track. I did a Google Hangout with my project mentors on Wednesday to discuss what I should be doing before May 19th and adjusting the project timeline for the first two weeks. I have some tasks lined up to do from now until next week, such as explore the existing WCS Axes code, learn how to use Sphinx to build docs and try to set up different Python environments. I've already experimented with iPython notebooks, (which I knew nothing about before this project) and they are a lot of fun to work with!

That's all I have to say for now. Let the coding begin!