Astro-Coords
view release on metacpan or search on metacpan
$c->telescope( $tel );
my $time = _gmstrptime("2002-03-21T03:16:36");
$c->datetime( $time);
print "#LST " . ($c->_lst * &Astro::PAL::DR2H). "\n";
is(sprintf("%.1f",$c->az(format => 'd')), '268.5');
is(sprintf("%.1f",$c->el(format => 'd')), '60.3');
# Done as planet now redo it as interpolated
$c = new Astro::Coords( mjd1 => 52354.13556712963,
mjd2 => 52354.1459837963,
ra1 => '02:44:26.06',
dec1 => '016:24:56.44',
ra2 => '+002:44:27.77',
dec2 => '+016:25:04.61',
);
$c->telescope( $tel );
$time = _gmstrptime("2002-03-21T03:16:36");
$c->datetime( $time);
print "#LST " . ($c->_lst * &Astro::PAL::DR2H). "\n";
is(sprintf("%.1f",$c->az(format => 'd')), '268.5');
is(sprintf("%.1f",$c->el(format => 'd')), '60.3');
$c = new Astro::Coords( ra => '04:42:53.60',
type => 'J2000',
dec => '36:06:53.65',
units => 'sexagesimal',
);
$c->telescope( $tel );
# Time is in UT not localtime
$time = _gmstrptime("2002-03-21T06:23:36");
$c->datetime( $time );
print "#LST " . ($c->_lst * &Astro::PAL::DR2H). "\n";
is(sprintf("%.1f",$c->az(format => 'd')), '301.7');
is(sprintf("%.1f",$c->el(format => 'd')), '44.9');
# Comet Hale Bopp
$c = new Astro::Coords( elements => {
# from JPL horizons
EPOCH => 52440.0000,
EPOCHPERIH => 50538.179590069,
ORBINC => 89.4475147* &Astro::PAL::DD2R,
ANODE => 282.218428* &Astro::PAL::DD2R,
PERIH => 130.7184477* &Astro::PAL::DD2R,
AORQ => 0.9226383480674554,
E => 0.9949722217794675,
},
name => "Hale-Bopp");
ok($c,"instantiate element object");
is($c->name, "Hale-Bopp","check name");
$c->telescope( $tel );
# Time is in UT not localtime
# Reference observation is 19971024_dem_0068
# Inaccuarcies in time of header make this difficult
# so test against horizons
#$time = _gmstrptime("1997-10-24T16:58:32");
# This is for Horizons testing. At this epoch
# we expect RA(2000) 08 09 07.70 DEC(2000) -47 25 27.5
$time = _gmstrptime("1997-10-24T17:00:00");
$c->datetime( $time );
print "# MJD: " . $c->datetime->mjd ."\n";
print "# LST " . ($c->_lst * &Astro::PAL::DR2H). "\n";
# Answer actually stored in the headers is 187.4az and 22.2el
is(sprintf("%.2f",$c->az(format => 'd')), '187.57',"Hale-Bopp azimuth");
is(sprintf("%.1f",$c->el(format => 'd')), '22.1',"Hale-Bopp elevation");
# Limit resolution for comparison
my ($ra_bopp, $dec_bopp) = $c->radec();
$ra_bopp->str_ndp( 0 );
$dec_bopp->str_ndp( 1 );
is($ra_bopp->string,"08:09:08","Hale-Bopp RA (J2000)");
is($dec_bopp->string,"-47:25:27.5","Hale-Bopp Dec (J2000)");
my $s = $c->status;
my @s = split /\n/,$s;
print join("\n", map { "# $_" } @s),"\n";
# and create a new elements object from the HaleBopp version
my $newbopp = new Astro::Coords( elements => [ $c->array ] );
if ($newbopp) {
$newbopp->datetime( $c->datetime );
$newbopp->telescope( $c->telescope );
is( $c->az, $newbopp->az,
"compare Azimuth from two (supposedly) identical elements");
} else {
ok(0, "Failed to create clone of elements object");
}
# Test parsing of date strings in for elements EPOCH.
$c = new Astro::Coords(
elements => {EPOCH => '2013 Dec 04.0',
ORBINC => 62.40397752235779 * &Astro::PAL::DD2R,
ANODE => 295.65203155196 * &Astro::PAL::DD2R,
PERIH => 345.5312406205832 * &Astro::PAL::DD2R,
AORQ => 0.01245259242960607,
E => 1.000201003833968,
EPOCHPERIH => '2013 Nov 28.7786582736',
},
name => 'ISON');
ok($c, 'Instantiate element object for ISON');
my %c_elements = $c->elements();
delta_ok($c_elements{'EPOCH'}, 56630.0,
'Compare parsed elements EPOCH');
delta_ok($c_elements{'EPOCHPERIH'}, 56624.7786582736,
'Compare parsed elements EPOCHPERIH');
# Make sure we can get a list of planet names
my @planets = Astro::Coords::Planet->planets();
my %pl = map { lc($_) => undef } @planets;
ok( exists $pl{jupiter}, "Jupiter in list of planets" );
ok( exists $pl{sun}, "Sun in list of planets" );
ok( exists $pl{moon}, "Moon in list of planets" );
is( scalar @planets, 9, "Count the number of planets" );
exit;
sub test_array_elem {
my $ansref = shift; # The answer you got
my $testref = shift; # The answer you should have got
# Compare sizes
is($#$ansref, $#$testref, "Compare number of elements in array");
for my $i (0..$#$testref) {
if (defined $ansref->[$i] && looks_like_number($ansref->[$i])) {
delta_ok($ansref->[$i], $testref->[$i], "Compare array element $i");
} else {
is($ansref->[$i], $testref->[$i], "Compare array element $i");
}
}
}
sub _gmstrptime {
# parse ISO date as UT
my $input = shift;
my $isoformat = "%Y-%m-%dT%T";
my $time = Time::Piece->strptime($input, $isoformat);
# At some point Time::Piece started assuming UT from strptime
# rather than localtime! Only add on the offset if we have a local
# time - look inside!
if ($time->[Time::Piece::c_islocal]) {
my $tzoffset = $time->tzoffset;
$time = gmtime($time->epoch() + $tzoffset->seconds);
}
return $time;
}
( run in 1.993 second using v1.01-cache-2.11-cpan-39bf76dae61 )