I feel like writing again

It’s been some very busy months lately. Since I started my Master’s degree, I’ve been working hard on my research and on publications based on it. I am happy to announce that the first draft of my first first author paper is done, and now I wait for the comments of other authors. Also, in December I became a rotation author on Astrobites, which is pretty cool. I’m also working on an extra project (which I can’t talk much about right now) and doing other science stuff on the side when there’s free time.

So, as you can imagine, there hasn’t been much room for writing non-scientific articles. Even gaming (my cup of tea when it comes to cheap entertainment) is set to background lately. The posts here in this blog are actually a repost from my previous website, so that is why there is some weird stuff like missing images and so on. Additionally, they reflect opinions that I had at the time of writing, and they probably changed a lot since. I don’t wanna erase these posts though. In fact, I want to go back to writing again.

Since I stopped blogging, I feel like there’s this hairball of ideas inside my stomach that can’t find its way out. Things like the current state of science in Brazil, where things are going, the situation of diversity in all kinds of fields, personal life strife that’s been going on, and even some experiences that I think worth of writing about.

I’ve been actively tweeting these issues, but it just doesn’t feel the same. For instance, how is it possible to regurgitate all my opinions on, say, the directions that the skeptical and atheist movements are taking at the moment (which, by the way, are thoughtfully explored on the blog Skepchick) in just 140 characters? The answer is: it is not. Also, I feel that tweeting doesn’t click the same skill buttons as does full-fledged blogging: it seems like I’m rusty on the non-scientific writing, which is really bad.

In conclusion: yes, I do intend on getting back to writing again. I might as well start making this blog a bit more public if that happens, since I’ve kept it behind the curtains for too long of a time now. Posts will generally be shorter too, because that is in vogue at the moment. I think 500 words limit is a good choice. Don’t wanna ramble too much. Also, no more obligatory featured image: it just gets in the way of writing. No more eye-candy for the readers, I guess.

I feel like writing again

If you die in science, you die for real

In 2011, I made a choice that would completely change my life: I decided to become a scientist. It was a very weird period, I was doubtful and delusional. The thing that I didn’t realize, however, is that the feeling of doubt and delusion would never go away, the better I tried.

The change itself was actually reinvigorating. Since when I first had a talk with the like-minded, I felt an urge, an euphoria, that I still feel when I go up a mountain to work at an observatory. I absolutely love to observe the sky, and the sensation seems to become ever stronger the more I do. The twilight is the beginning of a new night, of new opportunities and a travel that might end at new discoveries and excitement. For the first time in my entire life, I really feel like I belong somewhere.

And this is why… I am afraid. Almost every day, while sailing through the internet or visiting Twitter, I end up reading a post about how academia is broken; that there are too many students or postdocs trying to get an academic job and there are not many being offered; that working in academia is frustrating and it pays badly. I am afraid I might end up leaving science, and coming back to the same frustrations I had when I was looking for a job in corporations.

Since I made the decision to become a scientist, I knew that it wouldn’t be easy. To be completely honest, I was in the “follow your passion” mindset. I had confidence that everything would be fine if I did my best. Some say that we are afraid of what we don’t know, so it could be that I’m afraid now because I don’t know the exact level of difficulty of being a scientist or just because my future is uncertain.

Money is not a bigdeal for me: I was born in a simple family, and I can live comfortably with just a couple of bucks to buy me food and pay for the internet. But I know that many people want to construct their families, and have a nice house to raise their kids, pay for good education for them. So it’s understandable why a career in academia is problematic on that point. A scientist will only be able to have these good things when they are on a professorship track, and it can take a couple of decades to achieve that.

One can argue that I can be an astronomer or a scientist, even without being in academia: I could, for example, be working on data science, since it is big thing right now with corporations; or I could be a writer, working in science outreach. So there is that: looking for something outside academia. Of course, the chances and opportunities would depend mostly on luck, but also on what you have “worked” on during your graduate courses (the quotation marks are there because some companies don’t consider research as “working”). And this is where all my frustrations with corporations come from: not seeing the value in science.

When I read these inspirational and informative posts about looking for jobs outside academia, it’s a bit unsettling to read about isolated cases. I mean, maybe John was lucky enough to find a position as data scientist in an awesome company, and maybe Mary hit the ballpark when she founded her own business; but what about all the other people who left academia and are stuck at uninteresting jobs, just as almost all of my friends who went straight from undergrad to corporations? What do they have to say? Do they exist? We don’t have numbers on it, or at least I never saw them. As an astronomer obsessed with statistics, I find it hard to believe that getting a satisfying job outside academia is an easier task. We should be honest about the issue.

Outside of academia, I know very few people who actually enjoy their jobs as much as I do with astronomy, and all of them have a larger income than I do. They have cars, live in nice places, post selfies on Facebook when they’re traveling, but they hate to wake up in the morning and having to go to work. For them, the weekend is a blessing, and the weekdays are a curse. This is exactly what I want to avoid. Finding a satisfying job is hard, anywhere; there is no magic pill that will solve this quest.

I was talking to a friend this week, who is a professor, and he said things were even worse, in Brazil, a few years ago (around the 90’s and 2000’s). When he was in my position, a graduate student, in the same institution, he had absolutely no prospects of finding a job. Research in our country was sparse and fellowships were rare. It is just now that we are getting on our feet with science. Additionally, most of Brazilian research is done exclusively in academia, far away from companies. So, as you can see, at the current generation of scientists, there are two prospects: 1) In public universities, there are many positions being created as the result of investments and outright retirement of the old professors; for instance, at IAG/USP, most professors are either very old or very young, because of the recession gap from the 90’s to the 2000’s. 2) As the local culture of scientific jobs changes, there will [hopefully] be a broader integration between research and companies, which will open up opportunities outside academia.

Sometimes I think that being a scientist is like being an artist: it’s a very elusive position, one that few can get into; one that not everyone recognizes its importance; one that is full of ups and downs; and most importantly: one that takes a lot from you, and it will probably not financially pay-off your efforts. But, damn, it’s awfully satisfying.

Maybe I should stop focusing too much on the objectives, it’s not like a “if you die in science, you die for real” kind of situation. Perhaps I should just enjoy the ride, whatever the destination. To be honest, it’s been like that since the beginning: for instance, I never chose my exact field of study (apart from focusing more on stellar astrophysics, which I find very enticing), and that’s the reason why I’ve wondered through stellar evolution, formation of stars, interstellar medium and now solar twins and spectroscopy. Also, if you asked me 5 years ago, I would never have said that I wanted to be an exchange student in Netherlands. Things just happen, and our inclinations change. Maybe the randomness of life is what makes it worth living.


Featured image: “Science by Jurne, Huer by Enron” by Steve Rotman

 

If you die in science, you die for real

A new chapter has just started

I like to see my life as a book. And I remember quite well the most recent chapters: the chain-reaction that led to my decision of studying astronomy, the first year as a student of physics, then the exchange period to Netherlands, the limbo-like period in which I dedicated to setting myself up to grad school… And now, I have just started it, so the last weeks have been quite hectic (reason why I haven’t written since the beginning of March). Two weeks ago, I moved to São Paulo, the biggest city of South America, so I could study astronomy at the Institute of Astronomy, Geophysics and Atmospheric Sciences at the University of São Paulo (USP).

By the way, people who don’t know Portuguese almost always pronounce “São Paulo” in a weird way (at least for us) – which is completely fine! I always mispronounce Groningen, the city where I lived for one year, since I left there (but when I was there, I was dedicated to say it correctly). If you’re curious about our language, the tilde over the letter A means a sound like the U in the word “dump”. So, the correct pronunciation of “São” uses that sound instead of “Sao”. And if you’re even more curious, São Paulo is the Portuguese name if a saint – more specifically Saint Paul, in English.

I’m not new here in this city. I know, maybe all to well, how it is to live here: the long trips to get around the city, being always cautious with your stuff, the huge quantities of people, planning your day carefully to make it as efficient as possible, and, of course, dealing with the inefficiencies of the systems. And this is what really gets me, because I’ve been spoiled: Netherlands was too efficient, at almost everything. I don’t want to blame this country that I love so much for my frustrations with São Paulo, but it is impossible to not miss how good NL was when everything here is so slow and bureaucratic. Just as an example, when I lived in NL, we could simply order a free pre-paid SIM card for a cellphone and we would get it delivered at home. This can’t be done in Brazil: you have to go to a store and buy it, and this can be a pain in the ass if you live in a city like São Paulo.

Okay, that might have been a dumb example, but there are some other ones, such as the process we have to go through to get a simple magnetic card to use the public transport system here. I don’t have much to complain about the transport itself, because SPTrans, the company responsible for it, has been doing a fairly good job, I think. But here is the thing: in order to enjoy free or discounted transfers between buses, subways and trains, you have to have the magnetic card, and it can only be bought at very few selected stores sprinkled though the metropolis. The ones that carry student discounts have to be ordered by the school, and to get it from SPTrans, you have to wait in a 1-hour long line under the scorching Sun.

But enough complaining. Dang it, I didn’t want this post to have so much rant, but I guess that’s where my thoughts wandered, and I needed to vent. It’s fine that the systems are inefficient, things will never be perfect, I’ll get used to them. What I also need to get used to is the new routine. Grad school is different, there are more responsibilities. There is also the need to show my work to the world. I’ve been doing research on my own pace for some time, but I don’t think there are many products to be shown. I need to get into the game. Once I’m done with moving and dealing with the initial bureaucracies and headaches, I’ll will dedicate 100% to research (or at least that’s the plan). Yes, I do not have a definitive place to live yet, so I’m staying at my brothers’.

If you’re a prospective graduate student for the University of São Paulo, here is a pro tip: you don’t need to live near the campus. In fact, I would recommend not living there, because housing price is bloated, and the region is not very safe – especially to the west and southwest of the campus, where there is a favela nearby. I hear that thieves specifically target students that live around that region, because they usually carry notebooks and expensive cellphones. What I recommend is to get a place near a subway or train station, or near a bus station on a bus-only lane, and preferably in a building with 24h security (which we call “condomínio”). If the trip is too long, I found that the best way to spend the time is with a good book – a paper one, because ebooks and tablets attract too much attention and you may end up being robbed. Well, sorry for these kind of somber notes, but I just felt it needed to be stated.

I have a lot of ideas in mind to write more blog posts (such as the observations I did, pictures I’ve taken, my research projects, the recent astronomical happenings etc.), but I just haven’t found the time to materialize them. It’s been such crazy weeks lately, and it makes me feel bad that I’m not writing or being more productive. Moving is hard, but eventually things will settle down. Until then, I’ll try to keep at least the one-blog-post-per-week pace.

A new chapter has just started

Guide to DSLR night sky imaging: part 1

DSLR have become very popular cameras, so much that I managed to get one in 2013, while I was an exchange student in Netherlands (these cameras are too expensive here in Brazil – more than double the price found in North America or Europe). DSLR stands for Digital Single-Lens Reflex, and these cameras have a CCD (Charge-Coupled device) sensor which captures the light and than the information can be translated into images. CCDs have long been used in astronomy and, in fact, there’s quite an amusing history behind it: it is because of astronomy that almost all portable electronic devices and digital cameras today use this technology; if it weren’t for the astronomers interest in making CCDs more efficient and less expensive, Bell Labs (who invented it) would have thrown it in the trash, because they didn’t find a purpose for it. Or so goes the story told among astronomers. In other words, astronomy made it possible for CCDs to become accessible and useful to the public!

Anyway, since DSLR cameras¹ carry in them the same sensor used in astronomy, it is quite possible to do night sky imaging in a similar way that professional astronomers do. And this is what I have been doing since I got my camera: it is a Nikon D3100, a very entry-level device, and I’m even using the stock lenses (18-55 mm). Taking picture of the night sky is a very satisfying hobby, but it can also be time-consuming and a bit frustrating at times, and the learning curve is steep. But you can always start small. In this tutorial, which is the part 1, I’ll guide you from the easiest and less painful way to do night sky imaging. In part 2 (still working on it), I’ll show you the way through the most advanced stage I’ve gotten so far, without a telescope². I’m also thinking about writing a part 3, which would be the processing of images obtained on telescopes, but I still need to acquire more experience on that, so let’s leave that on the bag of ideas.

Since I still consider myself a beginner, suggestions to this guide are always welcome, and I will keep this post updated from time to time. Without further ado, here we go:

Equipment needed

Here are the necessary equipment to do DSLR imaging. Keep in mind that the prices I list here are for new, entry-level devices, and are also approximate.

  • DSLR camera + stock lenses: € 300 or US$ 375.
  • Class 10 SD card: around € 50. Get the higher class you can! Otherwise you’ll suffer from slow data-writing.
  • A tripod: starting from € 50.
  • Your best computer: depending on the number of pixels your camera takes, dealing with various layers of images will take a HUGE toll on your computer’s processing power.

The following items are optional, but strongly recommended:

Setting up the camera options

First of all, get to know your camera, read the manual, become its very best friend. And then get out at night with it. I say this because: 1) you’ll be messing with it in the dark, so it is a must to know the controls very well; 2) night sky imaging cannot be done with a pre-built shooting mode: it has to be completely manual, there’s no auto-pilot! So the best you know how to adjust the shooting settings, the best results you’ll get. Also, it’s helpful to know the nomenclature and the jargons of photography.

If you know your camera well, it’s time to start imaging. The settings on the camera will basically depend on two factors: light-pollution level and phase of the Moon. If you live a very light-polluted place or if the Moon is close to the full phase, you might want to gather less light, otherwise you’ll end up with a picture that is too red (sign of light pollution) or one that looks like daytime (caused by Moon illumination – but some people like pictures that show this feature, maybe because it seems to be a bit surreal – it’s up to you in the end). There are three ways to control how much light the camera gathers:

  • ISO: controls the sensitivity of the CCD to light
  • Focal ratio (or F number): controls the aperture of the camera’s “pupil”
  • Exposure time: controls how much time the shutter of the camera stays open after you release it

For all of these, the higher, the more light you gather, but you’ll also get more noise if the ISO is high.

Focus at infinity

The auto-focus function that most DSLR have need a minimum level of contrast, and because the dark sky is not the queen of contrast, you’ll have to do it yourself. We need to find the focus at infinity. And there is a simple trick to do that. Find a very bright, very far source of light (maybe the tip of a radio antenna in the mountains, they usually have lights; or the light coming from the window of a very far house); then zoom it to the maximum and put it into live view (image on the LED screen), because we’re gonna use digital zoom – if your camera doesn’t have live view, well, just try to do the best you can in the eyepiece. Turn up that digital zoom at the light source, and focus the lenses manually until the source is as small as possible: that should be the focus at infinity. Don’t touch the focus knob after this, otherwise you’ll need to re-focus it. Also, do not mistakenly change it to auto-focus, otherwise the camera will try to do it when you press the shutter release and lose the focus at infinity.

Shooting

Before shooting, keep in mind that when the camera shutter opens, the smallest rumble will affect the picture, so in an ideal situation, you should not touch the camera, because our hands make it shake. That’s why I recommend using a remote controller. If you don’t have one, the best procedure is to set your camera to the delayed shooting mode. In this mode, after you press the shutter release button, the camera waits a few seconds before actually taking the picture. By doing that, you give some time for the camera to stabilize and stop shaking after you touch it.

For first time shooters, I’d say: pick a region of the sky that is close to the milky way, set your ISO to 800, maximum F number, and an exposure time of 10 seconds (needless to say, use a tripod) and see how things go. If the picture is too bright or too dark, tweak the exposure time and the ISO. Remember that you’ll get a bit of star trails because of the rotation of the Earth (unless you have a tracking tripod, but these babies are expensive as heck).

On the other hand, if you have really dark skies and no prospects of clouds, you can try your hands at getting some nice star trails. I do not have experience on that (I’ll update the guide when I do), but I would imagine that you have to set a very long exposure time (something like more than 30 minutes), set a lower ISO and/or smaller aperture (so it doesn’t get a crazy amount of sky glow in this long period of time), point the camera to a region near the pole of the sky and let it rip.

Post-processing

Post-processing this images shouldn’t be a big deal if there isn’t much light pollution (believe me, it is a pain in the butt trying to get rid from the reddish glow of the sky – but we’ll see how to do that in part 2). It consists of turning down the sky glow and enhancing contrast or colors: to do that, you change the curves or the levels of the picture. I use the open-source software GIMP to edit images, and the options to change curves and levels are inside the menu “Colors”. I’m not going to tell you how to change these, you basically just tweak them until you’re satisfied with it, there is no secret. The following pictures were taken with this basic imaging technique, and had only minor post-processing.

Can you see the scorpion?
Picture taken from a really dark place (Roque de los Muchachos Observatory, Canary Islands)
Southern Cross and friends over the Zeiss telescope dome
Picture taken under full Moon (Pico dos Dias Observatory, Brazil)
11893367373_b7ce4f82e5_z
Picture taken from a fairly light-polluted place (lake Hoornsemeer, the Netherlands)

 

 

 

 

 

 

 

 

 

 

 

And this is it, basically. That’s how I started taking pictures of the night sky. I think the most difficult part of it is getting acquainted with the camera, especially if you’re new into photography. The options are overwhelming, and to this day I am unsure about some of the settings of my camera, such as how the white balance affects the final images and if I should just leave it to auto to take night sky photos. I need to study those. I suggest you to watch some videos about photography on YouTube (I particularly like this channel), or check some other blogs by professional photographers, there are many things to be learned on the internet.

Clear skies, and see you on part 2 of the guide!

Things to add to this guide in the future: shooting lightnings through a thunderstorm, shooting star trails, shooting meteors.


¹ Why use DSLR cameras? Can’t we use a smartphone or one of those “plug and play” easy to use compact cameras? Short answer: you can try, but the results will probably be underwhelming. Long answer: the problem with these cameras is that you don’t have much control over their settings, such as the sensibility of the CCD or the aperture; some of them allow only short exposures, and others don’t even let you control the focus; night sky imaging demands very precise, user-defined settings; so, no.

² It is possible to do DSLR imaging with the camera attached to the prime focus of a telescope, but in principle the imaging process shouldn’t be very different, except that you wouldn’t use lenses. The biggest challenge with that is to set up a telescope and a mount.

Guide to DSLR night sky imaging: part 1

Uncertainties

It’s been quite a disheartening weekend so far. You see, I follow a bunch of astronomers (and other scientists) either on Twitter or on blogs, and sometimes I stumble upon a few vents and posts that make me a bit uneasy about the career of a scientist, especially if you’re a female or part of an ethnic minority. Today is one of these days.

I just read this article on Talebearing, which sums up the worries of graduate student who suddenly realizes that most PhDs in his area (biology) don’t make it into fully-fledged career as scientists, i.e. a tenure track professorship job, a teaching job, or a job as a staff scientist at an industrial corporation. The author argues that one of the biggest caveats of a career on science is that it doesn’t pay as well as “normal” job, e.g. a consultant, and that it is too time- and effort-consuming. Additionally, to make things worse, I just read the news that many Brazilian graduate students hadn’t received their scholarships from CAPES since last November.

Well, while all these things make my future very uncertain, should it really be cause for a tremendous concern or even dread? I don’t think this kind of problem is only limited to science. I have the impression that every career path someone chooses has its own risks and costs. So it all comes down to how much (time/money/effort) people are willing to invest in order to achieve a goal. Also, there is one very important factor that should be clear: randomness play a huge role. And I think that is the main cause of delusion with a career in science: most prospective students don’t take into account the fact that sometimes you just have to be lucky.

As for myself, I was always very aware of the relatively low income for scientists (when compared to other careers), and that isn’t a big source of concern to me, since I was born and raised in a low-income family. I don’t like to say that we were poor, because I know all too many people who are or were truly poor, and sometimes had to go to bed with an empty stomach. Most of these people don’t really have a choice: they embrace whatever opportunity appears in order make a living. I was lucky enough to be able to make a career choice, and that is astronomy. Since I don’t have wife and kids to support, nor do I have high living standards, I can afford to earn less than other career paths. However, I would depend solely on that income, so there is not much room to delays in payments, such as the one CAPES did with the graduate students’ scholarships (2 months). We have bills to pay!

What about the prospects of finding a job as a scientist? I think it really depends on too many factors, and most of these are random. We should be aware of this fact. We could rephrase the question: is it enough to just do your job really well? Or what else can we do to improve our chances of finding a job as a scientist? I think that’s a much more useful question, and also a more difficult one to answer. What if you start doing something that, in principle, should improve your chances, but ends up undermining your productivity as a scientist? That’s another risk to be accounted for.

I also see many successful scientists or former scientists that are currently successful at another job saying that the [academic] system is broken. Universities are relying too much on productivity and not quality. Or that the influx of prospective students is growing too much and that everything is going to break down soon. What they do not do is to propose a solution. I mean, it’s easy to point out the flaws when you’re at an advantage position, but what about us who are in the middle of the storm? What should we do? Simply abandon the dream to become a scientist and pursue an easier path?

Maybe we are creating too many role models, and are not being realistic with our future. Maybe the career path of a scientist requires an amount of effort that most prospective students are not willing to pay for. Maybe this is all too random for people who want a more secure future. Maybe, sooner or later, we are going to reach the point of embracing whatever opportunity appears in order to make a living. And why should that be a bad thing?


Featured image: “Life’s uncertainties” by Fadzly Mubin on Flickr

Uncertainties

CREPE: a global optimization tool

It’s summer. And in contrary to many people here in Brazil, I am spending time at beaches or beautiful places, for various reasons. On the other hand, I started an interesting coding project: it’s called CREPE, which stands for CRoss-Entropy Parameter Estimation. It is a code written in python designed specifically to be global optimization tool, which is something very handy for scientists. The program is freely available on GitHub. Please be aware that it is far from being a release version, there are still many things that I want to implement.

But what the heck is cross-entropy, global optimization or parameter estimation? – one might ask. Well, in science, many times we create hypotheses when trying to understand a system, a signal or just the mechanisms of how things work. And the most objective way of testing a hypothesis is formulating it mathematically: let’s call it a test function. The test function might be dependent of various variables. For instance, when studying how the temperature of a solid plate behaves when one of its tips is heated, we can observe that the temperature depends on the position of the analyzed point, the energy output of the heat source, the material, how the heat is exchanged, time, and so on. These are all variables, and in the most complex phenomena, we do not know exactly what are the values that these variables assume.

On that same example, we might not know some of these variables, let’s say: the energy output of the source. If we know the temperature of each point on the plate, the other variables and how the heat is changed, we can estimate the energy output of the source (or how it varies with time). There are many tools for that and it can be calculated analytically. However, in many problems we do not know every variable (let’s call them the parameters), the observations might be imbued in noise and uncertainties, our hypothesis is sometimes completely empirical (which means there isn’t a beautifully closed set of equations with well defined variables), and the calculation can be outright too difficult or time-consuming to solve analytically. And that’s when we go to computers and global optimization tools. Some scientists (especially purist physicists) say this is “playing dirty” or “an appeal to ignorance.”

Global optimization is a clever way applied mathematicians created to, well, optimize a function or set of functions in order for it to assume a form that reproduces what we observe (the data). Back to the previous example, a global optimization would take all the information that we know, including our test function, a reasonable guess and optimize the value of the energy output of the heat source, in other words, look for the value that best reproduces our measurements of temperature. Global optimization is so powerful, that it can, in theory, estimate as many variables as you wish. But how well it will estimate and how much time it will take strongly depends on the computation power, the initial guess of the user, how good is the hypothesis, and how good is the data. You know, when you have an equation like y = x + 2, and if y = 4, solve for x? When you solve for x, it’s basically doing an optimization, which is finding the best value of x that best reproduces y.

Now, for the concept of cross-entropy, this is actually very complicated, and to be honest I didn’t quite understand, but you’re welcome to see these Wikipedia pages. The creator of the cross-entropy (CE) method is Reuven Rubinstein, and there is an official webpage for it which contains a very handy tutorial about the method. But notice that this kind of tool isn’t something that we learn (neither are even mentioned) about in classrooms, which is somewhat sad, because global optimization is such a powerful tool, and not that difficult to program it yourself. But with great power come responsibilities.

CE converges to a solution extremely quickly. It’s crazy fast. The problem is that it converges so fast, that it might get stuck into a non-optimal solution (what we call a local minimum). It doesn’t mean that it is a hit and miss program, but the results must be checked very carefully. Also, CE does not guarantee that your test function or the hypotheses are good, neither does it for the data. So, the job of the user of CE is to benchmark the test function(s) and take into account the quality of the data during the analysis. A good way to avoid mishaps is to plot everything, it really help us to make a good initial guess and check the validity of the results.

CREPE is very simple at the moment. So far, it works with optimization of parameters with single-variate Gaussian uncertainties, and there’s still some tweaks I plan to do and many things to add. I’ve been basing the program on this paper.

Examples

Inside the codes that can be downloaded on GitHub, you’ll find a folder called examples. The first example I want to show is curve_fit.py. In astronomy and other fields of experimental physics, sometimes we measure extremely faint signals that are imbued in noise. curve_fit.py generates mock data, and you have control of what kind of signal (the function f(x)) it is and the noise sigma (which translates into the amount of noise). In that example I used a sinusoidal mock signal, which describes various phenomena, such as the movement of a spring after it is pressed or pulled, and the parameters that we have to find are a (the spring constant) and b (the phase – or initial position). Here is a plot of a mock data, with noise sigma = 1.0:

figure_1
Plot of a sinusoidal (y = sin(ax + b)) mock signal with noise generated by CREPE.

 

Now this is a very noisy data. In fact, by looking at the plot, we can see that the noise levels are approximately half of the amplitude of the signal! This is terrible data, but if that’s the only data available, the only thing we can do is trying to get the best out of it. Suppose we were given this data and we don’t know what are the true values of the parameters a and b. CREPE can estimate them for us, if we feed it with at least two very important items: a guess and a performance function. As the name implies, the guess is a set of intervals that we think a and b should be inside (or close by). The performance function has one job: to evaluate how well the guesses of a and b are able to reproduce the data. There are many ways to evaluate that, in fact, I plan on adding some “standard” performance functions to the program so that the user doesn’t need to bother with it. What CREPE does is to create many samples of a and b (based on the user’s initial guesses), and just trying them on the performance function. Depending how well a certain set of samples do, the program selects the best ones and generate new samples based on them. And then it iterates until the results can’t get any better. Basically, the program “learns” how to reproduce the data, and because of that, methods like these are called machine learning.

After a handful of iterations, CREPE spits out the values of a and b that it “thinks” are the best ones, along with their uncertainties (although I’m still working on how to define these uncertainties). Based on the previous mock data, these are the results I got: a = 2.027 ± 0.007, b = 3.711 ± 0.104.

figure_2
CREPE’s results in reproducing the data. The red curve corresponds to the signal without noise (true signal).

 

But how close are they to the true values of a and b? Well, a (the spring constant) get pretty close: a_true = 2.0. But b (the initial phase) doesn’t: b_true = 10.0. Why is that? Well, I think that the quality of the data was very influential. So, let’s try to find a and b using a signal with less noise, shall we? This time, noise sigma = 0.5:

figure_3
Mock signal with less noise (sigma = 0.5).

 

Looks a bit better than the previous signal! And now, using CREPE’s parameter estimation capabilities, we get a = 1.994 ± 0.002 and b = 10.061 ± 0.012, much closer to the true values of a and b.

figure_4
Fitted signal to the new data.

But scientists are not always just fitting curves and functions to data. Sometimes, there are more complex calculations involving empirical models of how we think the universe plays. The program model_fit.py is a very simple example of how to work with a model in CREPE. One of the biggest accomplishments in astronomy was decomposing the light coming from objects in the sky (a field of study known as spectroscopy), and discovering that they have “lines” in them. These lines are features generated by the emission or absorption of light by chemical elements in very specific wavelengths. In this example, we simulate a spectrum, with 3 emission lines. In reality, the spread and intensity of these lines depend on a number of variables, but in this example, we consider that only the abundance of the elements and the rotation of the object play a role in the observed spectrum.

If we were given the data (again, very noisy) and, from the literature, we have the empirical model of that region of the spectrum for that specific celestial object, we can use CREPE to estimate the elemental abundances and the rotation of the object. The next figure illustrates the results from the model fitting example:

figure_5
Final result of the spectrum modelling example.

And again, not a perfect fit, but it comes close. Right now, I’m working on improving CREPE in order for it to get better results even if you have noisy data. One of the biggest advantages of CE is that it can attain good results much faster than other methods (there are a number of them in python – pick your poison!), so I think there is some potential for this program. Also, I think it’s important for scientists to make public the tools that they create, so they can be checked and used by other scientists, and python is perfect for that. Many astronomers are stuck with tools created on IDL, a very expensive programming environment (although extremely well-developed), which makes collaboration and sharing much more difficult. Luckily, python has been growing in the scientific community (especially in astronomy), so we are heading to a bountiful future on that front.

Well, this post was longer than I expected, and I barely touched the potential that I envision for this project. If you have any ideas or want to make contributions to it, just drop me a message or a pull request on GitHub!

 

 

CREPE: a global optimization tool

Astronomy excuses for holidays feasting

Featured image: the Christmas Tree Cluster, or Cone Nebula, or NGC 2264. It is a cluster of young stars ionizing hydrogen gas towards the constellation of Monoceros. Credit: ESO.

Astronomers are known for usually not following strict religious traditions, even though some of them still do maintain a certain level of religious belief. Amidst all the frantic activities that the western peoples engage on during their calendar’s last weeks of the year, one might wonder what an astronomer usually do: do they follow the traditions of the holy-days, have their own scientific commemoration or adopt more of a neutral stance? I’m going to give my take on that. But let’s start with a bit of background.

There is an area of study in astronomy that is busy with the position of objects in the sky, and it is known as astrometry (which can be related to astrology – the belief that alignments and positions can either causally or directly affect our personal lives). This is probably the most ancient branch of astronomy, since the days when our ancestors started tracking the position of stars in order to predict the seasons, and consequently help them in the practice of agriculture. Based on the periodicity of the positioning of stars, people created calendars, and there is a plethora of them. The calendar used by the western peoples is Google Calendar the Gregorian Calendar, also known as the Christian Calendar. It is refined a version of the Julian Calendar, which is a refinement of the Roman Calendar, which may have been based on Greek lunar calendars. There is actually a very entertaining history behind all these calendar reformations, so I highly recommend reading about them.

And why does all that matter? Well, you see, the calendar we use today are based on two astronomical phenomena: the seasons and the Moon phases. The cycle of the seasons define the year, while the cycle of the Moon define a month. The week, on the other hand, is probably based on the “enigmatic” number seven, and the days are obviously derived from the cycle of night and day. More recently, we (the human civilizations) noticed that just the positioning of the Sun and the Moon can be a bit erratic in their periods (for a number of reasons), so astronomers defined what is called the sidereal time, which is based on the positioning of background stars in the sky. Now, it’s important to note that even the stars cannot be completely reliable on very long stretches of time (i.e. millions of years), because even they start to move around – our Galaxy is a pretty dynamic system. But in a human lifespan timescale, the background stars are reliable. The point is that the way we measure time and pace is heavily based on the science of positioning objects in the sky, so is there something that makes a day more scientifically “holy” than other?

A few ancient civilizations that kept astronomical records noticed that the Sun had a weird movement on the sky during the year. If one records the exact position of the Sun at the same time, every day, one would get what is known as anallema. This movement affected not only the position of the Sun, but also of the shadows (which are easier to measure and record). And by looking at the position and size of the shadows, our ancestors noticed there were special positions: the solstices (the highest and lowest points of the Sun in the anallema) and equinoxes (the crossing point in the anallema). These phenomena are due to the inclination of the Earth’s rotation axis in relation to the plane of rotation of the Earth around the Sun (but I’m getting a little bit ahead of history here), and the inclination is also the responsible for the seasons. For that reason, many cultures use the equinoxes and solstices to mark the beginning of a season (although the way they actually happen in practice can vary wildly – let’s leave that study for meteorology).

The solstices, or the way we experience them, are very different between the southern and northern hemispheres the farther we go from the equator. Around June 20, we have the northern solstice, or when the Sun is apparently the northern-most in the sky, which means it’s the longest day on the northern hemisphere (and also the official “on paper” beginning of its summer) and the shortest day for the southern hemisphere (also, the beginning of its winter). Around December 20, we have the southern solstice, and everything happens in an inverse fashion. The equinoxes (which happen around March/September 20) are the days when the Sun cross the exact East-West direction, and the duration of the day and night is exactly 12 hours. And here is a fun fact: at the exact time of northern solstice, there are no shadows cast on the tropic of Cancer, while that happens at the tropic of Capricorn for the southern solstice (that’s actually how we define the tropics – I live just one degree north of the tropic of Capricorn); during the equinoxes, that happens if you are on the equator. So this is how the shadows play during these special dates.

The configuration of the Earth and direction of Sun rays during the southern solstice. Credit: user Blueshade on Wikimedia Commons.
The configuration of the Earth and direction of Sun rays during the southern solstice. Credit: user Blueshade on Wikimedia Commons.

Cue renaissance, Nicolaus CopernicusGalileo Galilei and Johannes Kepler. Between centuries XV and XVII, we saw the birth of astronomy as we know today, completely separated from astrology (but not from astrometry – we still do that these days; heck, the mission Gaia recently launched by ESA is doing extremely high-precision astrometry on a 3D space), and the observations of the Solar System led us to construct the theory of heliocentrism, which stated that the planets revolve around the Sun instead of the Earth. Additionally, the observations suggested that the path the planets take are not circular, but rather elliptical, and the Sun stayed (roughly – it actually wobbles just a tiny bit due to the gravity of the planets) at one of the foci (plural of focus) of the ellipse. That means that the distances one planet assumes in relation to the Sun is not constant, they vary; in fact, they have minima and maxima. Which means there are special days during a planet’s year, besides solstices and equinoxes; these are the aphelion (farthest from the Sun) and perihelion (closest). However, the difference in distance between minima and maxima are so small, that they hardly affect the weather here on Earth – which means that they have nothing to do with the seasons – and, in fact, the orbit of the Earth is almost a perfect circle. Almost.

Well then, there you go: in astronomy terms, there are no holy-days, but special days, more specifically six of them: two equinoxes, two solstices, aphelion and perihelion. At the time I’m writing this post, it’s December 21, and the summer solstice (southern hemisphere) happens in just about 8 hours from now. While it marks the beginning of the summer, it’s been very hot since September (temperatures peaking around 30 °C) and, weirdly, it’s been extremely dry when it would normally be the rainy season around here. So I don’t know what summer is anymore, apart from the formal astronomical/calendar definition. Either way, I will be raising a glass of cold water (or whatever I have in my hands) tonight to celebrate this special moment. And this is what I usually do.

Merry southern solstice, and a happy semi-arbitrary turning point of the Earth’s orbit around the Sun for everyone. Enjoy the feasting.

Astronomy excuses for holidays feasting