Finally figuring out how to measure bumps

Introducing Galaxy bumps

So one of the astronomy problems I worked on as an undergraduate involved measuring the bumps of a galaxy. Now you might ask "What is a galaxy bump and why measure it?". Well to give a quick example, take whatever screen you are reading this blog and stick your face close to it. If you get close enough, have decent vision, and the screen isn't extremely high resolution, you should be able to make out individual pixels (the lights that make up your screen). Now if you sit back, all those pixel will start to blend together and you will no longer be able to see individual pixels. The same thing happens with galaxies and the stars that make up galaxies. The closer a galaxy is to earth, the more detail and 'bumpier' a galaxy will appear in a digital image. As the galaxy gets farther away, that detail is harder to see as all the stars start to blend together. If we can measure how 'bumpy' a galaxy appears then we can tell how far away it is. Now I'm not going to go into much more detail here but if you want to know more, you can go to the kids article I published in the Frontiers journal here.

Measuring Galaxy Bumps is Really Hard

Now what I really want to talk about is what I had to do in order to measure these bumps. The concept is pretty simple, the smaller the bumps, the farther away the galaxy is. However, even though the concept is simple, measuring the bumps is where it gets really complicated.

In order to measure how big a galaxy's bumps are, you need to know what it would look like if there were no bumps at all. This means that you have to have what is called a model galaxy, or a simulated galaxy which matches the one you want to measure.

A simple way to do this is to use a Sersic Profile. It's basically a piece of math that if you implement in a computer program, you can create super smooth, model 2D galaxy. If you can fit your Sersic galaxy to your actual picture of a galaxy and subtract the model from the picture, boom! All you will be left with is the bumps.

However, there is a problem. A Sersic Profile can only really work on a galaxy that look kind of like Messier 49 shown below

Messier 49. So nice. So round. It's beauty is in it's simplicity! If you desire, can read the NASA press release on this picture here

This galaxy works with Sersic profiles because it's simple. The biggest thing you have to worry about is simply how the light gets dimmer the farther you get from the center, which for this galaxy, it doesn't matter which direction you choose, the galaxy looks basically the same (meaning if you go left of center, it would look the same if you went right/down/above the center), or in other words the galaxy is symmetric. Since the galaxy changes so predictably as you get farther from the center, it's easier to create a perfectly smooth, model galaxy. Once you have that perfectly smooth model galaxy, all you need to do is subtract the perfectly smooth galaxy from the original image and all you will be left with is the bumps.

But now lets look at NGC1015
This is a picture of NGC1015 taken by the Hubble Space Telescope. It's a pretty crazy galaxy with so many unique features. Like the spirals, the bright horizontal bar, even the core which kind of looks like a poke ball. You can find the full resolution image on the Hubble here.

This galaxy is beautiful. It's also a nightmare for measuring bumps. You could call it a beautiful nightmare. Why is it a nightmare you ask? Well, well, well I'm glad you asked.

If you were to try to measure the bumps of this galaxy, you would first have to create a perfectly smooth model of it. But honestly, what does that even mean for this galaxy? Does that mean taking the spirals out? What about the core? Which parts should be modeled? The core honestly looks kind of like a poke ball. Can you even find a mathematical equation that would create a galaxy with a poke ball core?

The answer is no, there really is no simple, computationally usable, mathematical equation that accurately models this galaxy. You would have to model it in pieces if you were to try. Generally, even though these are the coolest galaxies to look at, we can't measure the bumps because there is no reliable way to predict (or extract) what those bumps are going to look like in such messy galaxies.

In fact even with elliptical galaxies it can get pretty hard. There are more football shaped ellipticals that have tons of contaminating stars and other crap in their picture
This is NGC1132. I got this image from the European Space Agency here. This is difficult because you would have to remove all of the extra stuff in this picture.

Elliptical galaxies that are full of dust

This is NGC1316. Dust means the galaxy can't work as dust has nothing to do with distance and blocks all the bumps. You can read more by going to NASA's website here.



Hybrid spiral-elliptical galaxies called lenticular galaxies

A hybrid elliptical-spiral galaxy. It's super cool to look at, but I would not even attempt to model this one. You can find out more about it here.
Credit:ESA/Hubble & NASA, Acknowledgement: Judy Schmidt 


Anyway, there are countless examples of galaxies which just aren't very good for measuring bumps. Basically the more boring a galaxy is, the more likely it can be used.

The Problem I Wanted to Solve

Because galaxies are so variable, even with the regular, boring, elliptical ones, current methods to measure galaxy bumps basically use a tuning by hand process. This process doesn't take super long, but it does take hours. There are bunch of telescopes upcoming that are going to be taking way, way, more data then we could ever handle if we have to use the by hand, manual tuning process of making galaxy models. One of these telescopes is the Large Synoptic Survey Telescope (LSST). 

A picture of part of the LSST which is currently under construction which I took while visiting the site in Chile. I honestly don't remember exactly what this particular piece does, but I can tell you that it was absolutely huge. This telescope will be taking super high res pictures of the sky with thousands of pictures of galaxies that will be good for what I do. You can go here to learn more.

The LSST will be taking thousands of pictures of tens of thousands of galaxies. There just is no way to feasibly go through all those galaxies pictures by hand using current methods.

What I've been researching is into how to automate the process. This is really hard, to say the least. As you can see from all of the previous examples, galaxies often don't fit into nice categories. We can't even properly label some of them. Some of them are simply classified as 'irregular' and 'peculiar' because they literally are just a huge mess of stars clumping together. 

This is IC3583. It is literally just a disorganized, clump of stars. Regardless, there is still beauty in its irregularity. You can go to NASA's website here to learn more about it

How I solved It

I tried so many things to automate the bumpiness measurements. I tried fitting the image line by line. I tried fitting circles to the image. I tried so many different models. I tried astropy, a python package that was developed by astronomers to help with astronomy. Accidentally, I even made some images that would make great throw rug patterns (honestly, I wish I still had them).

Eventually, I was trying this mathematical approximation thing called a Savitzky-Golay smoothing filter. I had used it before, but only in one dimensional problems. I thought that since the Savitzky-Golay filter was made to smooth data, it should work for my problem since it would approximate the smooth galaxy and I could extract the bumps. Luckily, there was some random stranger on the internet that wrote the code I needed for me! I simply took what this person wrote, modified it, and it almost worked. Sadly, if only it were that simple. I kept on trying different things. I even got it to work on simulated galaxies (galaxies that I created using a Sersic model and then used what's called a Poisson filter to give it model bumps) but I just couldn't get it to work completely in a consistent manner. 

I was in despair. No matter what I tried I just couldn't replicate what had been done with the manual method. If I couldn't replicate the manual method, then there was no way we could use it for real research. I then put it out of my mind for awhile. My professor wasn't too confident that it would end up working and no matter how hard I tried, I just couldn't get it to work on real images.

Several months later I ended up getting rejected from all the grad schools I had applied to. After I graduated from UVU, I didn't have anything I could do. I was lost, in limbo. I had failed, I didn't get into grad school, the teaching job I had at UVU was filled as the department expected I would be getting into grad school, two other people that had promised me astronomy jobs ended up not being able to help me.

It was almost comical how sad my situation was and how everything seemed to fall apart all at once. Everything that I had done up to that point and dreamed about seemed like it was all for naught. I failed at my research, I had failed getting into grad school, I had failed to achieve the goal that I had been working towards during the past 5 years and I seemed to be entirely left on my own, alone. It was such a complete and total failure at everything I had attempted with every opportunity suddenly evaporating, it was almost beautiful. It was like I was in some soap opera or something. It felt unreal. I thought that maybe this is how dreams die.

Because I literally had nothing else to do, I went back to trying to solve how to automate the galaxy measurements. While going through my own code I often thought,

"This is a mess, just like my life."

and simultaneously

"Man this is a clever way to do things, did I actually write this?"

It was an interesting internal dialogue

Eventually I came along a line of code and noticed something. I noticed that the real galaxy images had pixels that had been 'masked' or set to 0. I thought to myself

"I don't set any of my pixels equal to zero when making my measurements."

So I decided to add two lines of code

hand_zero_vals = np.where(hand_image_resid == 0)
my_approx_resid[hand_zero_vals]=0

All that these two lines of code say is that wherever the by hand model galaxy image (the thing I called hand_image_resid) equals zero, set the same exact same pixels in my automated model image (the thing I called my_approx_resid) equal to zero. In other words, make sure the by-hand model and automated model are modified the same way.

I did not expect what happened next when I ran the program again. It was like I said the magic word, or that I suddenly guessed the right password, because literally all of my measurements started making sense all at once.

After nearly 1.5 years of work writing thousands of lines of code, throwing out more code than I actually ended up keeping, and nearly giving up after being perplexed for months, with a tiny and simple modification I discovered how to reproduce measurements that took hours of fine tuning when done by hand in seconds! 

What all this Means

TBH, the discovery I made is really cool but not world changing. It proves that automating the problem of measuring galaxy bumps is possible, even though it's unreasonable difficult. 

I ended up publishing an entire paper on it with my professor who of course also now believes it's possible. If you are at all interested in reading a really technical piece of literature, you can find it here. You can view all the sexy graphs I made and can see on page 15 the beauty of the measurements I made. Out of everything I did as an undergraduate, I'm most proud of this paper.

Even though it doesn't change the world, more importantly for me, it was personally uplifting. It was a ray of sunshine in a valley of cloudy despair. It gave me hope at a time that I really needed it, giving me the determination to keep on going even if my future was uncertain. It made me feel that maybe my dreams weren't all the way dead, but maybe just mostly dead and just needed some CPR.

Anyway, I needed to write this down. Because I didn't give up I was to able to find success. Thus far, my story seems to been having a happier end. I will eventually write more about that, but for now I hope that if you're reading this don't give up on your dreams, they are worth fighting for. Even if you might have to shift the focus of your dreams, that doesn't mean that you should give up on them. You never know when you'll find the metaphorical magic two lines of code that will end up solving a bunch of problems. 

Thanks for reading.

Comments