Astro-FITS-HdrTrans
view release on metacpan or search on metacpan
lib/Astro/FITS/HdrTrans/FITS.pm view on Meta::CPAN
to the (few) headers that are commonly standardised across most
FITS files.
Mainly deals with World Coordinate Systems and headers defined
in the FITS standards papers.
=cut
use 5.006;
use warnings;
use strict;
use Carp;
use base qw/ Astro::FITS::HdrTrans::Base /;
our $VERSION = "1.66";
# for a constant mapping, there is no FITS header, just a generic
# header that is constant
my %CONST_MAP = (
);
# unit mapping implies that the value propogates directly
# to the output with only a keyword name change
my %UNIT_MAP = (
DATA_UNITS => 'BUNIT',
DEC_SCALE => "CDELT2",
INSTRUMENT => 'INSTRUME',
RA_SCALE => "CDELT1",
TELESCOPE => 'TELESCOP',
X_BASE => "CRPIX1",
X_REFERENCE_PIXEL => "CRPIX1",
Y_BASE => "CRPIX2",
Y_REFERENCE_PIXEL => "CRPIX2",
);
# Create the translation methods
__PACKAGE__->_generate_lookup_methods( \%CONST_MAP, \%UNIT_MAP );
=head1 COMPLEX CONVERSIONS
These methods are more complicated than a simple mapping. We have to
provide both from- and to-FITS conversions All these routines are
methods and the to_ routines all take a reference to a hash and return
the translated value (a many-to-one mapping) The from_ methods take a
reference to a generic hash and return a translated hash (sometimes
these are many-to-many).
=over 4
=item B<to_ROTATION>
This determines the angle, in decimal degrees, of the declination or
latitude axis with respect to the second axis of the data array, measured
in the anticlockwise direction.
It first looks for the linear-transformation CD matrix, widely used
including by IRAF and the precursor to the PC matrix. If this is
absent, the routine attempts to find the standard transformation
matrix PC defined in the FITS WCS Standard. Either matrix is
converted into a single rotation angle.
In the absence of a PC matrix it looks for the CROTA2 keyword from the
AIPS convention.
The evaluation from the CD matrix is based upon Micah Johnson's
cdelrot.pl script supplied for use with XIMAGE, extended to average
the two estimates using FITS-WCS Paper II Section 6.2 prescription.
=cut
sub to_ROTATION {
my $self = shift;
my $FITS_headers = shift;
my $rotation;
my $rtod = 45 / atan2( 1, 1 );
# Try the IRAF-style headers. Use the defaults prescribed in WCS Paper I,
# Section 2.1.2.
if ( defined( $FITS_headers->{CD1_1} ) || defined( $FITS_headers->{CD1_2} ) ||
defined( $FITS_headers->{CD2_1} ) || defined( $FITS_headers->{CD2_2} ) ) {
my $cd11 = defined( $FITS_headers->{CD1_1} ) ? $FITS_headers->{CD1_1} : 0.0;
my $cd21 = defined( $FITS_headers->{CD2_1} ) ? $FITS_headers->{CD2_1} : 0.0;
my $cd12 = defined( $FITS_headers->{CD1_2} ) ? $FITS_headers->{CD1_2} : 0.0;
my $cd22 = defined( $FITS_headers->{CD2_2} ) ? $FITS_headers->{CD2_2} : 0.0;
# Determine the sense of the scales.
my $sgn1;
if ( $cd12 < 0 ) {
$sgn1 = -1;
} else {
$sgn1 = 1;
}
my $sgn2;
if ( $cd21 < 0 ) {
$sgn2 = -1;
} else {
$sgn2 = 1;
}
# Average the estimates of the rotation converting from radians to
# degrees (rtod).
$rotation = $rtod * 0.5 * ( atan2( $sgn1 * $cd21 / $rtod, $sgn1 * $cd11 / $rtod ) +
atan2( $sgn2 * $cd12 / $rtod, -$sgn2 * $cd22 / $rtod ) );
# Now try the FITS WCS PC matrix. Use the defaults prescribed in WCS Paper I,
# Section 2.1.2.
} elsif ( defined( $FITS_headers->{PC1_1} ) || defined( $FITS_headers->{PC1_2} ) ||
defined( $FITS_headers->{PC2_1} ) || defined( $FITS_headers->{PC2_2} ) ) {
my $pc11 = defined( $FITS_headers->{PC1_1} ) ? $FITS_headers->{PC1_1} : 1.0;
my $pc21 = defined( $FITS_headers->{PC2_1} ) ? $FITS_headers->{PC2_1} : 0.0;
my $pc12 = defined( $FITS_headers->{PC1_2} ) ? $FITS_headers->{PC1_2} : 0.0;
my $pc22 = defined( $FITS_headers->{PC2_2} ) ? $FITS_headers->{PC2_2} : 1.0;
# Average the estimates of the rotation converting from radians to
# degrees (rtod) as the matrix may not represent a pure rotation.
$rotation = $rtod * 0.5 * ( atan2( -$pc21 / $rtod, $pc11 / $rtod ) +
( run in 0.749 second using v1.01-cache-2.11-cpan-39bf76dae61 )