Come for the quick hacks, stay for the epiphanies. PerlMonks

### Locationg celestial objects (using Astro::Coords, if need be)

by schweini (Friar)
 on Oct 25, 2012 at 18:19 UTC Need Help??

schweini has asked for the wisdom of the Perl Monks concerning the following question:

Hi!

I am trying to get perl to figure out where in the sky certain objects (Planets, spaceship, maybe stars) are, so i can point a servo-controlled laser pointer there.

I am completely ignorant of the finer things of astronomy, my problem might be that i simply didnt 'grok' some very basic issues.

Anyhow: I figure i need the Azimuth and Elevation of the object I want to point at, for my current location (San Jose, Costa Rica). There seems to be another more 'professional' coordinate system for these kind of things that gives me the position in Radians and Declination, which I dont quite understand, but AFAICT dont really need, because I want to point my laser using stuff like "point to 234 degrees North, and 45 degrees over the horizon".

My basic test code is the following:
```use Astro::Coords;
use Astro::Telescope;
use Time::Piece;

my \$time = new Time::Piece;

# \$time += 6*3600;

\$c = new Astro::Coords( planet => 'mars' );

# 9.956318, -83.995503, 1480m

\$c->telescope( new Astro::Telescope( Name => 'MvS', Long => -83.995503
+, Lat => 9.956318, Alt => 1480 ));

\$c->datetime( \$time );

\$az = \$c->az( format => 'd' );
\$el = \$c->el( format => 'd' );
\$ra = \$c->ra( format => 'd' );
\$dec = \$c->dec( format => 'd' );
print "az: \$az\nel: \$el\n\nra: \$ra\ndec: \$dec\n";
Which, at this very moment spits out:
```C:\Users\schweini\Dropbox\hacks>perl laserTelescope.pl
az: 64.4509897905136
el: 2.92864468337563

ra: 251.654925187611
dec: -23.3814670583575
Which, checking against Google Sky Map on my android phone, is completely off. (Mars seems to be quite high in the sky right now, here where I am located).

If I look it up using NASA's 'Horizon' webservice, I get:

```**********************************************************************
+*********************************************************************
+*******************************************************
Date__(UT)__HR:MN     R.A._(J2000.0)_DEC. X_(sat-primary)_Y SatPANG
+APmag  S-brt Ob-lon Ob-lat            delta      deldot   1-way_LT
+ S-O-T /r    S-T-O   PsAng   PsAMV N.Pole-RA  N.Pole-DC
**********************************************************************
+*********************************************************************
+*******************************************************
\$\$SOE
2012-Oct-25 00:00 Nm  251.06257 -23.30814 145863.8 -40206.8 111.721
+ 1.24   4.23 170.57   5.54 2.03255620848271   6.3552294  16.904255  4
+0.8647 /T  26.9310    n.a.    n.a. 317.66783   52.87870
2012-Oct-25 01:00  m  251.09522 -23.31220 145830.0 -40170.2 111.714
+ 1.24   4.23 185.16   5.53 2.03270971936605   6.3981098  16.905531  4
+0.8533 /T  26.9252    n.a.    n.a. 317.66783   52.87870
2012-Oct-25 02:00  m  251.12797 -23.31625 145795.9 -40133.5 111.706
+ 1.24   4.23 199.75   5.51 2.03286393613495   6.4135372  16.906814  4
+0.8419 /T  26.9193    n.a.    n.a. 317.66783   52.87870
2012-Oct-25 03:00  m  251.16081 -23.32029 145761.6 -40096.7 111.698
+ 1.24   4.23 214.35   5.50 2.03301818013345   6.4003399  16.908097  4
+0.8304 /T  26.9134    n.a.    n.a. 317.66783   52.87870
2012-Oct-25 04:00  m  251.19373 -23.32433 145727.3 -40059.8 111.691
+ 1.24   4.23 228.94   5.49 2.03317176798120   6.3592992  16.909374  4
+0.8189 /T  26.9074    n.a.    n.a. 317.66783   52.87870
2012-Oct-25 05:00  m  251.22674 -23.32838 145693.0 -40022.9 111.683
+ 1.24   4.23 243.53   5.47 2.03332405819567   6.2930959  16.910641  4
+0.8074 /T  26.9013    n.a.    n.a. 317.66783   52.87870
2012-Oct-25 06:00  m  251.25982 -23.33244 145658.8 -39985.9 111.675
+ 1.24   4.22 258.12   5.46 2.03347449495092   6.2061269  16.911892  4
+0.7959 /T  26.8951    n.a.    n.a. 317.66783   52.87870
2012-Oct-25 07:00  m  251.29295 -23.33653 145624.9 -39948.8 111.667
+ 1.24   4.22 272.72   5.45 2.03362264598894   6.1042058  16.913124  4
+0.7845 /T  26.8889    n.a.    n.a. 317.66783   52.87870
2012-Oct-25 08:00  m  251.32610 -23.34064 145591.3 -39911.8 111.660
+ 1.24   4.22 287.31   5.43 2.03376823209864   5.9941654  16.914335  4
+0.7731 /T  26.8827    n.a.    n.a. 317.66783   52.87870
2012-Oct-25 09:00     251.35927 -23.34478 145558.1 -39874.7 111.652
+ 1.24   4.23 301.90   5.42 2.03391114615311   5.8833922  16.915523  4
+0.7619 /T  26.8764    n.a.    n.a. 317.66783   52.87870
2012-Oct-25 10:00     251.39241 -23.34894 145525.2 -39837.7 111.644
+ 1.24   4.23 316.49   5.40 2.03405146040802   5.7793223  16.916690  4
+0.7508 /T  26.8702    n.a.    n.a. 317.66783   52.87870
2012-Oct-25 11:00 N   251.42552 -23.35312 145492.8 -39800.7 111.636
+ 1.24   4.23 331.09   5.39 2.03418942156454   5.6889341  16.917838  4
+0.7397 /T  26.8640    n.a.    n.a. 317.66783   52.87870
2012-Oct-25 12:00 *   251.45857 -23.35732 145460.8 -39763.8 111.628
+ 1.24   4.23 345.68   5.38 2.03432543393411   5.6182727  16.918969  4
+0.7288 /T  26.8578    n.a.    n.a. 317.66783   52.87870
2012-Oct-25 13:00 *   251.49155 -23.36153 145429.1 -39727.0 111.620
+ 1.24   4.23   0.27   5.36 2.03446003185360   5.5720371  16.920088  4
+0.7180 /T  26.8517    n.a.    n.a. 317.66783   52.87870
2012-Oct-25 14:00 *   251.52445 -23.36574 145397.6 -39690.3 111.612
+ 1.24   4.23  14.86   5.35 2.03459384323222   5.5532601  16.921201  4
+0.7073 /T  26.8457    n.a.    n.a. 317.66783   52.87870
2012-Oct-25 15:00 *   251.55727 -23.36994 145366.3 -39653.7 111.605
+ 1.24   4.23  29.46   5.34 2.03472754671638   5.5631014  16.922313  4
+0.6966 /T  26.8397    n.a.    n.a. 317.66783   52.87869
2012-Oct-25 16:00 *   251.59001 -23.37414 145335.1 -39617.1 111.597
+ 1.24   4.23  44.05   5.32 2.03486182539373   5.6007684  16.923430  4
+0.6859 /T  26.8339    n.a.    n.a. 317.66783   52.87869
2012-Oct-25 17:00 *   251.62267 -23.37831 145303.8 -39580.6 111.589
+ 1.24   4.22  58.64   5.31 2.03499732019437   5.6635701  16.924557  4
+0.6752 /T  26.8281    n.a.    n.a. 317.66783   52.87869
2012-Oct-25 18:00 *   251.65527 -23.38245 145272.4 -39544.2 111.581
+ 1.24   4.22  73.23   5.30 2.03513458616844   5.7471012  16.925698  4
+0.6645 /T  26.8223    n.a.    n.a. 317.66783   52.87869
2012-Oct-25 19:00 *   251.68784 -23.38655 145240.7 -39507.7 111.573
+ 1.24   4.22  87.83   5.28 2.03527405462362   5.8455422  16.926858  4
+0.6537 /T  26.8166    n.a.    n.a. 317.66783   52.87869

So, the results perl give me correspond to 18:00 UTC time (I am 6 timezones away from UTC), even though I am telling Astro::Coords where exactly I am located, so I figure that it should tell me where Mars is RIGHT NOW. (My locale seems to be set up correctly, too - so i would hope Time::Piece takes that into account?).

If i SUBTRACT(!??!) 6 hours (6*3600) of my Time::Piece, i get a location info for Mars that seems to roughly correspond to what Google Sky Map is telling me - but then Neptune is way off, so that crude correction-measure doesnt work. Adding 6 hours seems even worse.

Long story short: what am i doing wrong? How can i somehow look up the Azimuth and Elevation of celestial objects at my current position and time?

I was also thinking about hooking myself into that Horizons webservice and somehow (how??) convert those esoteric RaDec coordinates to simple earth-based AzEl coordinates, but i dont know how.

Thanks for any help,

M.

Replies are listed 'Best First'.
Re: Locationg celestial objects (using Astro::Coords, if need be)
by jandrew (Chaplain) on Oct 25, 2012 at 22:20 UTC

schweini Your variance sounds suspiciously like you have a floating timezone in your date object. DateTime defaults to a floating timezone. I don't have any experience with Time::Piece but the Astro::Coords documentation uses DateTime and explicitly sets the timezone on date object creation. Astro::Coords source appears to attempt to convert your time object to UTC prior to calculating celestial coordinates. Timezone conversion requires a defined timezone in the DateTime object (floating time zones don't convert).

Re: Locationg celestial objects (using Astro::Coords, if need be)
by Don Coyote (Hermit) on Oct 25, 2012 at 19:25 UTC

Hey Schweini, pretty cool use for perl I'd say :).

First thought, would be to ask you if you have taking daylight saving into consideration? Around this time of year servers can clash internationally on things like the time.

also consider are you seing 'Ra'dians, where the meaning is 'R'ight 'A'scencion, or vice versa, (if that is a thing!). just bouncing a couple of thoughts off the atmosphere.

Re: Locationg celestial objects (using Astro::Coords, if need be)
by Mr. Muskrat (Canon) on Oct 25, 2012 at 19:21 UTC

When you run the following do you see the correct local time? It sounds like you won't; in which case something is misconfigured in the OS.

perl -MTime::Piece -e 'my \$l = localtime; print "local time is \$l\n"'
Nope. The clock seem s to be ok:
```C:\Users\schweini\Dropbox\hacks>perl -MTime::Piece -e "my \$l = localti
+me; print qq|local time is \$l\n|"
local time is Thu Oct 25 13:29:00 2012
(which obviously is my localtime right now)
Re: Locationg celestial objects (using Astro::Coords, if need be)
by Laurent_R (Canon) on Oct 27, 2012 at 09:56 UTC

I don't know the Perl module you are using, and am not able to help, but maybe I can clarify a bit on the celestial coordinate systems.

Azimuth and elevation give the position at a given time of a celestial object compared to the local horizon of the place where the observer is located. The are called horizontal coordinates. Thus it depends on where the observer is located.

Right ascension and declination constitute the equatorial coordinates, which do not depend on the location of the observer, as they are measured against the celestial equator. Declination is the angle of a celestial object to the equator (it is sort of the latitude of the object). Right ascension is analogous to the longitude and is the angle between the vernal equinox point (a special point on the celestial equator) and the object. It is often measured in hours, minutes and seconds (in this case, it is usually called hour angle and it is analogous to the time zone of the celestial object), rather than degrees or radians.

There are other systems of coordinates used in astronomy but that would become off-topic.
Re: Locationg celestial objects (using Astro::Coords, if need be)
by eddor1614 (Beadle) on Oct 28, 2012 at 23:04 UTC
Hi
According to the Astro::Telescope manual:

Latitudes and longitudes must be given in radians, altitude and distance in metres, and the parallax constants in units of Earth radii.

are you using decimal degrees?
Duh! Duh! Duh! You were exactly right! I converted my degrees into radians, and now the script spits out the exact same values as the ones i can see in Stellarium! Thanks!

Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1000915]
Approved by Corion
Front-paged by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-03-02 20:14 GMT
Voting Booth?
My favourite way to spend a leap day ...

Results (29 votes). Check out past polls.