Is there a way in PyEphem to efficiently convert a large number of apparent coordinates to Equatorial Right Ascension/Declination without using a python loop? Any hint appreciated, thanks!
-
1Show what you've tried so far and we might provide help. Your field of interesset is ver specialized and there will be very few astronomical versed useres of pyephem. So show what you'r doing and you will get a proper solution from python programmers which are not astronoms. – Don Question Jan 21 '12 at 09:45
-
Ok, thanks, I've no example yet, I'll create and add one in the next days. However it is quite simple, I have an array of elevation and azimuths, and I want to convert all of them in ra/dec without looping. – Andrea Zonca Jan 21 '12 at 10:08
-
Basically you want a "vectorized" processing chain?! As long as you don't have enough vector-units you can't do without looping! And looping itself isn't that bad. for performance concerns you might consider the `map` function, which does the "looping" wightout a `for`-loop. – Don Question Jan 21 '12 at 10:20
1 Answers
You can hide the for
loop inside of a function so that you don't need to think about the loop out in your main code. Or you could use a list comprehension to move the loop inside of an expression so that the loop does not need to be out at the level of a statement, like changing:
a = [1,2,3]
b = []
for n in a:
b.append(n*n)
to an expression like:
a = [1,2,3]
b = [n*n for n in a]
But, no, PyEphem does not provide its own syntax — like a library like numpy provides — for doing vector operations (which are always, of course, loops underneath whatever pretty syntax is on top).
PyEphem would have to rebuild its calculations on top of numpy instead of implementing them in C for a true vector toolchain approach. That might be a good idea anyway, someday, because of how fast numpy is becoming when combined with pypy; but for now PyEphem is a wrapper around a C library "libastro" that continues to be maintained and improved, so PyEphem has not yet branched out into implementing many calculations itself.

- 83,755
- 16
- 106
- 147
-
Thanks Brandon, I am concerned about performance, so I was hoping PyEphem had any facility to have loops at C level instead of python level, with possibly notable gain in performance. – Andrea Zonca Jan 22 '12 at 15:45