Astro-satpass

 view release on metacpan or  search on metacpan

t/tle_pass.t  view on Meta::CPAN

use warnings;

use Test::More 0.88;

BEGIN {

    eval {
	require Time::Local;
	Time::Local->import();
	1;
    } or do {
	plan skip_all => 'Can not load Time::Local';
	exit;
    };

    eval {
	use lib qw{ inc };
	require My::Module::Test;
	My::Module::Test->import( qw{ format_pass magnitude } );
	1;
    } or do {
	plan skip_all => 'Can not load My::Module::Test from inc';
	exit;
    };
}

use Astro::Coord::ECI;
use Astro::Coord::ECI::Moon;
use Astro::Coord::ECI::Star;
use Astro::Coord::ECI::Sun;
use Astro::Coord::ECI::TLE qw{ :constants };
use Astro::Coord::ECI::TLE::Set;
use Astro::Coord::ECI::Utils qw{ deg2rad PARSEC SECSPERDAY };

my $sta = Astro::Coord::ECI->new(
    name => 'Greenwich Observatory',
)->geodetic(
    deg2rad( 51.4772 ),
    0,
    2 / 1000,
);

use constant SPY2DPS => 3600 * 365.24219 * SECSPERDAY;

my $star = do {
    my $ra = deg2rad( 146.4625 );
    Astro::Coord::ECI::Star->new(
	name	=> 'Epsilon Leonis',
    )->position(
	$ra,
	deg2rad( 23.774 ),
	76.86 * PARSEC,
	deg2rad( -0.0461 * 24 / 360 / cos( $ra ) / SPY2DPS ),
	deg2rad( -0.00957 / SPY2DPS ),
	4.3,
    );
};

# The following TLE is from
#
# SPACETRACK REPORT NO. 3
#
# Models for Propagation of
# NORAD Element Sets
#
# Felix R. Hoots
# Ronald L. Roerich
#
# December 1980
#
# Package Compiled by
# TS Kelso
#
# 31 December 1988
#
# obtained from http://celestrak.org/

# There is no need to call Astro::Coord::ECI::TLE::Set->aggregate()
# because we know we have exactly one data set.

my ( $tle ) = Astro::Coord::ECI::TLE->parse( <<'EOD' );
1 88888U          80275.98708465  .00073094  13844-3  66816-4 0    8
2 88888  72.8435 115.9689 0086731  52.6988 110.5714 16.05824518  105
EOD
$tle->set(
    geometric	=> 1,
    intrinsic_magnitude	=> 3.0,
);

my @pass;

if (
    eval {
	@pass = $tle->pass(
	    $sta,
	    timegm( 0, 0, 0, 12, 9, 80 ),
	    timegm( 0, 0, 0, 19, 9, 80 ),
	    [ $star ],
	);
	1;
    }
) {
    ok @pass == 6, 'Found 6 passes over Greenwich'
	or diag "Found @{[ scalar @pass ]} passes over Greenwich";
} else {
    fail "Error in pass() method: $@";
}

is format_pass( $pass[0] ), <<'EOD', 'Pass 1';
1980/10/13 05:39:02   0.0 199.0  1687.8 lit   rise
1980/10/13 05:42:42  55.8 119.1   255.7 lit   apls
                     49.6 118.3     6.2 Epsilon Leonis
1980/10/13 05:42:43  55.9 115.6   255.5 lit   max
1980/10/13 05:46:37   0.0  29.7  1778.5 lit   set
EOD

note <<'EOD';
The following magnitude test is really only a regression test, since I
have no idea what the correct magnitude is.
EOD



( run in 0.815 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )