Astro-Catalog
view release on metacpan or search on metacpan
lib/Astro/Catalog/Item.pm view on Meta::CPAN
Returns undef if the coordinates have never been specified.
If the name() field is defined in the Astro::Coords object
the id() field is set in the current Star object. Similarly for
the comment field.
=cut
sub coords {
my $self = shift;
if (@_) {
my $c = shift;
croak "Coordinates must be an Astro::Coords object"
unless UNIVERSAL::isa($c, "Astro::Coords");
# force the ID and comment to match
$self->id($c->name) if defined $c->name;
$self->comment($c->comment) if $c->comment;
# Store the new coordinate object
# Storing it late stops looping from the id and comment methods
$self->{COORDS} = $c;
}
return $self->{COORDS};
}
=item B<ra>
Return (or set) the current object R.A. (J2000).
$ra = $star->ra();
If the Star is associated with a moving object such as a planet,
comet or asteroid this method will return the J2000 RA associated
with the time and observer position associated with the coordinate
object itself (by default current time, longitude of 0 degrees).
Returns undef if no coordinate has been associated with this star.
$star->ra($ra);
The RA can be changed using this method but only if the coordinate
object is associated with a fixed position. Attempting to change the
J2000 RA of a moving object will fail. If an attempt is made to
change the RA when no coordinate is associated with this object then
a new Astro::Coords object will be created (with a
Dec of 0.0).
RA accepted by this method must be in sexagesimal format, space or
colon-separated. Returns a space-separated sexagesimal number.
=cut
sub ra {
my $self = shift;
if (@_) {
my $ra = shift;
# Issue a warning specifically for this call
my @info = caller();
warnings::warnif("deprecated","Use of ra() method for setting RA now deprecated. Please use the coords() method instead, at $info[1] line $info[2]");
# Get the coordinate object
my $c = $self->coords;
if (defined $c) {
# Need to tweak RA?
croak "Can only adjust RA with Astro::Coords::Equatorial coordinates"
unless $c->isa("Astro::Coords::Equatorial");
# For now need to kluge since Astro::Coords does not allow
# you to change the position (it is an immutable object)
$c = $c->new(
type => 'J2000',
dec => $c->dec(format => 's'),
ra => $ra,
);
}
else {
$c = new Astro::Coords(
type => 'J2000',
ra => $ra,
dec => '0',
);
}
# Update the object
$self->coords($c);
}
my $outc = $self->coords;
return unless defined $outc;
# Astro::Coords inserts colons by default. Grab the old delimiter
# and number of decimal places if we're using a recent enough
# version of Astro::Coords.
my $ra = $outc->ra;
if (UNIVERSAL::isa($ra, "Astro::Coords::Angle")) {
$ra->str_delim(' ');
$ra->str_ndp(2);
return "$ra";
}
else {
my $outra = $outc->ra(format => 's');
$outra =~ s/:/ /g;
$outra =~ s/^\s*//;
return $outra;
}
}
=item B<dec>
Return (or set) the current object Dec (J2000).
$dec = $star->dec();
If the Star is associated with a moving object such as a planet,
comet or asteroid this method will return the J2000 Dec associated
with the time and observer position associated with the coordinate
object itself (by default current time, longitude of 0 degrees).
Returns undef if no coordinate has been associated with this star.
$star->dec( $dec );
The Dec can be changed using this method but only if the coordinate
object is associated with a fixed position. Attempting to change the
J2000 Dec of a moving object will fail. If an attempt is made to
change the Dec when no coordinate is associated with this object then
a new Astro::Coords object will be created (with a
Dec of 0.0).
Dec accepted by this method must be in sexagesimal format, space or
colon-separated. Returns a space-separated sexagesimal number
with a leading sign.
=cut
sub dec {
my $self = shift;
if (@_) {
my $dec = shift;
# Issue a warning specifically for this call
my @info = caller();
warnings::warnif("deprecated","Use of ra() method for setting RA now deprecated. Please use the coords() method instead, at $info[1] line $info[2]");
# Get the coordinate object
my $c = $self->coords;
if (defined $c) {
# Need to tweak RA?
croak "Can only adjust Dec with Astro::Coords::Equatorial coordinates"
unless $c->isa("Astro::Coords::Equatorial");
# For now need to kluge since Astro::Coords does not allow
# you to change the position (it is an immutable object)
$c = $c->new(
type => 'J2000',
ra => $c->ra(format => 's'),
dec => $dec,
);
}
else {
$c = new Astro::Coords(
type => 'J2000',
dec => $dec,
ra => 0,
);
}
# Update the object
$self->coords($c);
}
my $outc = $self->coords;
return unless defined $outc;
# Astro::Coords inserts colons by default. Grab the old delimiter
# and number of decimal places if we're using a recent enough
# version of Astro::Coords.
my $dec = $outc->dec;
if (UNIVERSAL::isa($dec, "Astro::Catalog::Angle")) {
$dec->str_delim(' ');
$dec->str_ndp(2);
$dec = "$dec";
$dec = (substr($dec, 0, 1) eq '-' ? '' : '+') . $dec;
return $dec;
}
else {
my $outdec = $outc->dec(format => 's');
$outdec =~ s/:/ /g;
$outdec =~ s/^\s*//;
# require leading sign for backwards compatibility
# Sign will be there for negative
$outdec = (substr($outdec, 0, 1) eq '-' ? '' : '+') . $outdec;
return $outdec;
}
}
=item B<fluxes>
Return or set the flux measurements of the star as an C<Astro::Fluxes>
( run in 1.576 second using v1.01-cache-2.11-cpan-5735350b133 )