COSMΩRACLE: WEB APP TO CALCULATE DISTANCES IN COSMOLOGY

Motivation

If you work in cosmology or astronomy, chances are you needed to calculate at least one of the cosmological distances at one point. Or often. Now, there are multiple choices on how one can calculate the distances — by using a python library or by using one of the available online calculators. I personally felt like there was a lack and a need for a web app that would tick several boxes:

– had to be user friendly
– had to be fast and accessible
– had to work across devices (desktop, tablet, mobile)
– had the option to plot the calculated quantities
– had the option to download the calculated quantities
– had to be designed in a modern way
– had to be easy to upgrade and enhance
– had to be open source

The Initial Idea(s)

I have expressed my idea of starting such a project to my partner a long time ago but everyday life got in the way (what’s new?). At the beginning of 2021, my best friend showed me a project he started to work on using Streamlit – and I was immediately in love (and how wouldn’t anyone be?? It is simply gorgeous). I have since explored other app deployment options but the simplicity of Streamlit won. Fast forward to the last quarter of 2021, I finally started planning (mind-mapping) how I would do it. Since I am always more open to collaborating with others rather than doing stuff just by myself, I asked Marco Bonici (a cosmologist who I’ve met on Twitter and became instant-friends since the first time we talked) if he would join a project that has been brewing in my head forever. He asked which project and when I said “cosmo calculator” his response was “I was just thinking about that!” (I still keep the snapshot of the chat). My partner was interested in joining since the beginning so that was settled way back. Holidays 2021/2022 seemed like a good way to start coding as we all had spare time. The rest is history.

A Bit of BTS

Ok, the rest from “the rest” is history: I am not going to reveal every detail. No one wants to read a novel here and some things should remain between my collaborators and me. But a bit of BTS is always helpful, especially for young people who might want to work on a project. My advice would be: start somewhere (just start). We started by a brainstorm session and literally wrote things down in a Google doc. Decided what to start with, the first things we wanted to test/code, etc. Also distributed the tasks. Then, each of us worked on their own segment. After we had “something” we would converge by having a sprint meeting on zoom, discussed it, tested it, reviewed it and moved onto a next task. GH workflow is truly amazing for these sort of things. We did not have a clear task separation at first: all three of us were coding the functions for computing cosmology distances. Then, for example, when the need for plots arose, I would make the plot in a py code but would meet with others to debug it together within Streamlit. Matthijs is very knowledgable when it comes to website stuff or CI so he took over in those departments. Marco has the most experience with cosmology so he was double checking everything. I took over when it came to the visual features, logo or fighting the fight with the app appearance. If we were stuck, the usual googling or asking friends for tips (thanks to Robert and the amazing Knut who also helped name the app) was the way to go.
This worked pretty well for us. I cannot promise this will also work for your project as it depends on many factors (such as the project scope, people, infrastructure and who-knows-what-else). But the bottom line is: if people who get along well put their heads together, you can make something nice while having loads of fun. Hope this is somewhat inspiring (provided you are still here and still reading this).

Features

I am really proud of our work – I believe we managed to tick all the goals from the above list. The app is easy to use: two clicks (literally two clicks, I counted), press enter and the values of luminosity distance or angular diameter distance magically appear on your screen. It is accessible and functional: works smoothly on your laptop and on your phone (or tablet). Which is great as sometimes you just need the information on “what is the comoving distance at redshift 1.7?” without starting the whole python machinery. It has has several options (for now, :wink wink:): it will calculate the distances and, if you want, it will plot the calculated quantities as a function of redshift (in two scales even). If you further want to pay with the generated data – just name your file and download the dataset in the redshift range. I think it also looks great. This is totally a subjective thing, clearly but in my opinion – it is sleek and modern and simple color balanced. It is publicly open. And I do not mean it is just free to use: you can see the backbone of the app, you can check every line of code. You can clone the repo and play with it yourself. You can comment and report the bugs. You can suggest for a feature to be added. This sort of transparency should be the norm, if you ask me. And lastly, it is relatively easy for us to implement new ideas and expand the app. Maybe we are just working on it right now ;).

Thanks to all the great people behind the scenes at Numpy, SciPy, Streamlit, GitHub and everyone on StackOverflow. A special thanks to Matthijs and Marco for being just grand and a joy to work with.

Here is a demo of our app. Hope it will be useful for your research.