Why astronomers (and other scientists) should program in Python
bellm.org
bellm.org
Coming from a mixed particle physics and astronomy experiment, almost all our tools are written in Python for researchers, but usually with ROOT (C++, http://root.cern.ch/ ) underneath. ROOT is python friendly.
SciPy/NumPy, PyROOT, PyFITS are all unbeatable tools for anything in Physics or Astronomy as far as I'm concerned. Throw some knowledge of C in with that, and you can scale anything up to supercomputing clusters or back down to your laptop, and that's a very important, powerful thing for a scientist.
What occurred to me while reading this article though is that we should perhaps be using Python for our scripting needs. We have a number of scripts that we use regularly for querying databases and submitting jobs and most of them are written in Perl. I think that Python would be much easier to read and hack; especially because most of the physicists don't know Perl.
In my (anecdotal) experience, it seems that a number of astronomers would actually love to move to Python but I've only seen one actually make an effort to make the move. The primary reason cited has been that some particular library modules they use haven't been ported yet. Glancing around the links from the article, it definitely seems that the porting has come a long way, but that's not the same thing as completeness.
Now, obviously the best solution would be if these astronomers each took it upon themselves to translate their own necessary tools and contribute back to the Python community, but that's pretty unrealistic, I think. I write Python for at least a good 8-10 hours/day and my IDL was clean, tight, and well-documented and I'm still terrified of the thought of translating my project.
Of course, the other question I have (and would _love_ an answer to) is how well Python holds up performance-wise to well-crafted IDL astronomy code. We were working with a data set large enough that, even on a cluster, each step of the process took between several days and a couple weeks. If Python could improve that, it would have been amazing, but if it would only hurt then Python would basically be useless for that project.
And most engineers/scientists use it. If you know MATLAB, I don't see why you would even bother going to figure out the dozens of Python libraries available.
One major advantage python has over MATLAB that the author mentioned but didn't really emphasize is that python packages exist to interface with IRAF. Pretty much every astronomer who has to touch data uses IRAF to reduce the data and I can tell you from personal experience that IRAF is a horrible piece of software to work with directly. The python interface makes it much more tolerable, but I don't think there exists a comparable MATLAB version. Without a MATLAB interface to IRAF, python beats MATLAB for astronomical purposes hands down.
Not to mention the fact that the MATLAB language is extremely awkward anytime you want to work with something that isn't a matrix.
> MATLAB language is extremely awkward anytime you want to work with something that isn't a matrix.
From my limited experience, that's true but rarely of relevance. You can, and want to, use matrix operations all the way. Less bugs (simplier code), faster execution.
Is that infinite recursion or endless loop? Or is there an end to it, caused by quantum nature of work -- at some point the 90% becomes an undivisible unit? ;-)
((terribly sorry, couldn't help it))
At any rate, that sounds like you want to feed the input through a pipe of simple, programmable textual filters -- cue sed, awk etc. And then pipe into standard input of something -- I know Octave has standard input, MATLAB I wouldn't be so sure.
10 Reasons Python Rocks for Research (And a Few Reasons it Doesn’t) http://www.stat.washington.edu/~hoytak/blog/whypython.html
Should i switch to Python? http://stackoverflow.com/questions/5063037/should-i-switch-t...
I've looked at a bunch of students' resumes lately - every single one listed Matlab as one of the languages they know. Not seeing a lot of Python in the resumes I'm reviewing, which are mostly EE students. I think Matlab is becoming the de-facto standard for numerical analysis and there are some nice toolboxes.
Coming from a traditional SW background I find some of the Matlab syntax alien but fundamentally it's a great product.
python
>>> 2 * 3.1 6.2000000000000002
perl -e "print 2 * 3.1" 6.2
ruby -e "print 2 * 3.1" 6.2
For example, in MATLAB, Octave and JavaScript, a value is displayed (formatted) as an `integer' if it's very close to an integer (closer than certain epsilon -- and that's configurable in case of M & O). At all the time, what the variable holds -- and what undergoes computations -- is a purely float value, never an integer.
>>> from decimal import Decimal
>>> 2 * Decimal("3.1")
Decimal('6.2')Anyway, it's not only engineers that use MATLAB. It is quite popular in the sciences, and not just for plotting.
Maybe this is all just a big anecdote, but I also work in scientific computing as well, and this has been my experience.
This is more geared at the analyst level, which you could compare astronomers to, rather than the scientific programmer level (who have been writing C or C++ in the 1990s/2000s instead of Matlab). Python makes things neat because the same libraries (mentioned in the article) that the scientific programmers are using can now be used directly by the analysts/astronomers.