Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: perl in the stars

by Anonymous Monk
on Dec 20, 2022 at 16:13 UTC ( [id://11148995]=note: print w/replies, xml ) Need Help??


in reply to perl in the stars

Disclaimer: though I'm anonymous here, I'm the author of both Astro::Coord::ECI and Astro::SIMBAD::Client.

Astro::Coord::ECI and friends are a bit heavyweight if all you want to do is convert degrees to radians. The actual code to do this is two lines:

use constant PI => atan2 (0, -1);
sub deg2rad { return defined $_[0] ? $_[0] * PI / 180 : undef }

As for computing angles, I will not recommend a specific module. I will say the initial implementation of Astro::Coord::ECI->angle() naively used the law of cosines, but I had to switch to the law of haversines after trying to compute the closest passage of a satellite to a star and having the law of cosines blow up.

All I can say about Astro::SIMBAD::Client is that it is a mess. Sorry. There are a number of ways to get the data, the SIMBAD API changed over time, and, well, what can I say? It badly needs a simpler interface. It takes me 30-some lines of code just to get the position and proper motion of a star. If you decide you want to wrestle with it, you can contact me at wyant at cpan dot org.

Replies are listed 'Best First'.
Re^2: perl in the stars
by Anonymous Monk on Dec 23, 2022 at 16:50 UTC
    Thank you for all your good work for Perl on CPAN! I use your Astro modules constantly to power my planetariums and clocks. I'd like to see your 30 lines. Here is one that puts SIMBAD data in a perl hash:
    perl -MAstro::SIMBAD::Client -MData::Dumper -le '$s=Astro::SIMBAD::Cli +ent->new;@s=split/\n/,$s->url_query(id => Ident => "$ARGV[0]", NbIden +t => 1);splice(@s,0,7);splice(@s,20,$#s+1);%s=map{/([^:]+\S)\s?:\s+(\ +S.*)/;$1=>$2}@s;@s=grep/^Coord/,keys%s;print"$_: $s{$_}"for@s;print q +q[\n$s{"Proper motions"}\n];print Dumper\%s;' sirius
    Prints coordinates and proper motions and dumps the hash:
    Coordinates(Gal,ep=J2000,eq=2000): 227.23029126 -08.89028121 Coordinates(ICRS,ep=J2000,eq=2000): 06 45 08.91728 -16 42 58.0171 (Op +t ) A [11.70 10.90 90] 2007A&A...474..653V Coordinates(FK4,ep=B1950,eq=1950): 06 42 56.72452 -16 38 45.4080 -546.01 -1223.07 [1.33 1.24 0] A 2007A&A...474..653V $VAR1 = { 'Angular size' => '~ ~ ~ (~) ~ ~', 'Coordinates(Gal,ep=J2000,eq=2000)' => '227.23029126 -08.89 +028121 ', 'Spectral type' => 'A0mA1Va C 2003AJ....126.2048G', 'Parallax' => '379.21 [1.58] A 2007A&A...474..653V', 'Flux V' => '-1.46 [~] C 2002yCat.2237....0D', 'Flux I' => '-1.43 [~] C 2002yCat.2237....0D', 'Flux J' => '-1.36 [~] C 2002yCat.2237....0D', 'Flux R' => '-1.46 [~] C 2002yCat.2237....0D', 'Redshift' => '-0.000018 [0.000001] A 2006AstL...32..759G', 'Proper motions' => '-546.01 -1223.07 [1.33 1.24 0] A 2007A& +A...474..653V', 'Flux K' => '-1.35 [~] C 2002yCat.2237....0D', 'Morphological type' => '~ ~ ~', 'Flux H' => '-1.33 [~] C 2002yCat.2237....0D', 'cz' => '-5.50 [0.40] A 2006AstL...32..759G', 'Flux U' => '-1.51 [~] C 2002yCat.2237....0D', 'Radial Velocity' => '-5.50 [0.4] A 2006AstL...32..759G', 'Flux B' => '-1.46 [~] C 2002yCat.2237....0D', 'Coordinates(ICRS,ep=J2000,eq=2000)' => '06 45 08.91728 -16 + 42 58.0171 (Opt ) A [11.70 10.90 90] 2007A&A...474..653V', 'Coordinates(FK4,ep=B1950,eq=1950)' => '06 42 56.72452 -16 +38 45.4080', 'hierarchy counts' => '#parents=0, #children=0, #siblings=0' };
    PS - I think the easiest way to get deg2rad (and rad2deg) is a core module:
    use Math::Trig 'deg2rad';

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11148995]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-18 21:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found