File Coverage

blib/lib/Astro/FITS/HdrTrans/CGS4New.pm
Criterion Covered Total %
statement 19 42 45.2
branch 1 16 6.2
condition 7 27 25.9
subroutine 6 8 75.0
pod 3 3 100.0
total 36 96 37.5


line stmt bran cond sub pod time code
1             package Astro::FITS::HdrTrans::CGS4New;
2              
3             =head1 NAME
4              
5             Astro::FITS::HdrTrans::CGS4New - UKIRT CGS4 translations for "new"
6             style CGS4 headers.
7              
8             =head1 SYNOPSIS
9              
10             use Astro::FITS::HdrTrans::CGS4New;
11              
12             %gen = Astro::FITS::HdrTrans::CGS4New->translate_from_FITS( %hdr );
13              
14             =head1 DESCRIPTION
15              
16             This class provides a generic set of translations that are specific to
17             the CGS4 spectrometer of the United Kingdom Infrared Telescope.
18              
19             =cut
20              
21 10     10   3476869 use 5.006;
  10         50  
22 10     10   71 use warnings;
  10         30  
  10         891  
23 10     10   97 use strict;
  10         23  
  10         353  
24 10     10   69 use Carp;
  10         27  
  10         1483  
25              
26             # Inherit from UIST
27 10     10   109 use base qw/ Astro::FITS::HdrTrans::UIST /;
  10         21  
  10         8167  
28              
29             our $VERSION = "1.66";
30              
31             my %CONST_MAP = ( OBSERVATION_MODE => 'spectroscopy',
32             );
33              
34             my %UNIT_MAP = ( DEC_BASE => "DECBASE",
35             DEC_SCALE => "CDELT3",
36             EXPOSURE_TIME => "DEXPTIME",
37             GRATING_DISPERSION => "GDISP",
38             GRATING_NAME => "GRATING",
39             GRATING_ORDER => "GORDER",
40             GRATING_WAVELENGTH => "GLAMBDA",
41             NSCAN_POSITIONS => "DETNINCR",
42             RA_BASE => "RABASE",
43             RA_SCALE => "CDELT2",
44             SCAN_INCREMENT => "DETINCR",
45             SLIT_ANGLE => "SANGLE",
46             SLIT_NAME => "SLIT",
47             SLIT_WIDTH => "SWIDTH",
48             X_BASE => "CRVAL2",
49             X_REFERENCE_PIXEL => "CRPIX2",
50             Y_BASE => "CRVAL3",
51             Y_REFERENCE_PIXEL => "CRPIX3",
52             );
53              
54             # Create the translation methods
55             __PACKAGE__->_generate_lookup_methods( \%CONST_MAP, \%UNIT_MAP );
56              
57             =head1 METHODS
58              
59             =over 4
60              
61             =item B<can_translate>
62              
63             Returns true if the supplied headers can be handled by this class.
64              
65             $cando = $class->can_translate( \%hdrs );
66              
67             This method returns tru if the INSTRUME header exists and is equal to
68             'CGS4', and if the DHSVER header exists and is equal to 'UKDHS 2008
69             Dec. 1'.
70              
71             =cut
72              
73             sub can_translate {
74 20     20 1 62 my $self = shift;
75 20         60 my $headers = shift;
76              
77 20 50 66     199 if ( exists( $headers->{INSTRUME} ) &&
      66        
      33        
78             uc( $headers->{INSTRUME} ) eq 'CGS4' &&
79             exists( $headers->{DHSVER} ) &&
80             uc( $headers->{DHSVER} ) eq 'UKDHS 2008 DEC. 1' ) {
81 0         0 return 1;
82             }
83              
84             # Handle the reverse case as well. This module can translate CGS4
85             # headers newer than 20081115.
86 20 0 33     2561 if ( exists $headers->{INSTRUMENT} &&
      33        
      0        
87             uc( $headers->{INSTRUMENT} ) eq 'CGS4' &&
88             exists $headers->{UTDATE} &&
89             $headers->{UTDATE} >= 20081115 ) {
90 0         0 return 1;
91             }
92              
93 20         502 return 0;
94             }
95              
96             =back
97              
98             =head1 COMPLEX CONVERSIONS
99              
100             =over 4
101              
102             =item B<to_ROTATION>
103              
104             This determines the angle, in decimal degrees, of the rotation of the
105             sky component of the WCS. It uses the standard transformation matrix
106             PCi_j as defined in the FITS WCS Standard. In the absence of a PCi_j
107             matrix, it looks for the CROTA2 keyword.
108              
109             For CGS4 the PCi_j matrix is obtained from i=[2,3] and j=[2,3].
110              
111             =cut
112              
113             sub to_ROTATION {
114 0     0 1   my $self = shift;
115 0           my $FITS_headers = shift;
116 0           my $rotation;
117              
118 0           my $rtod = 45 / atan2( 1, 1 );
119              
120 0 0 0       if ( defined( $FITS_headers->{PC2_2} ) || defined( $FITS_headers->{PC2_3} ) ||
    0 0        
      0        
121             defined( $FITS_headers->{PC3_2} ) || defined( $FITS_headers->{PC3_3} ) ) {
122 0 0         my $pc22 = defined( $FITS_headers->{PC2_2} ) ? $FITS_headers->{PC2_2} : 1.0;
123 0 0         my $pc32 = defined( $FITS_headers->{PC3_2} ) ? $FITS_headers->{PC3_2} : 0.0;
124 0 0         my $pc23 = defined( $FITS_headers->{PC2_3} ) ? $FITS_headers->{PC2_3} : 0.0;
125 0 0         my $pc33 = defined( $FITS_headers->{PC3_3} ) ? $FITS_headers->{PC3_3} : 1.0;
126              
127             # Average the estimates of the rotation converting from radians to
128             # degrees (rtod) as the matrix may not represent a pure rotation.
129 0           $rotation = $rtod * 0.5 * ( atan2( -$pc32 / $rtod, $pc22 / $rtod ) +
130             atan2( $pc23 / $rtod, $pc33 / $rtod ) );
131              
132             } elsif ( exists $FITS_headers->{CROTA2} ) {
133 0           $rotation = $FITS_headers->{CROTA2} + 90.0;
134             } else {
135 0           $rotation = 90.0;
136             }
137 0           return $rotation;
138             }
139              
140             =item B<to_UTDATE>
141              
142             Sets the YYYYMMDD-style UTDATE generic header based on the DATE-OBS
143             header.
144              
145             =cut
146              
147             sub to_UTDATE {
148 0     0 1   my $self = shift;
149 0           my $FITS_headers = shift;
150 0           my $utdate;
151              
152 0           my $dateobs = $FITS_headers->{'DATE-OBS'};
153 0           $dateobs =~ /^(\d{4}-\d\d-\d\d)/;
154 0           $utdate = $1;
155 0           $utdate =~ s/-//g;
156              
157 0           return $utdate;
158             }
159              
160             =back
161              
162             =head1 SEE ALSO
163              
164             C<Astro::FITS::HdrTrans>, C<Astro::FITS::HdrTrans::UKIRT>.
165              
166             =head1 AUTHOR
167              
168             Malcolm J. Currie E<lt>mjc@star.rl.ac.ukE<gt>
169             Brad Cavanagh E<lt>b.cavanagh@jach.hawaii.eduE<gt>,
170             Tim Jenness E<lt>t.jenness@jach.hawaii.eduE<gt>.
171              
172             =head1 COPYRIGHT
173              
174             Copyright (C) 2008 Science and Technology Facilities Council.
175             Copyright (C) 2003-2005 Particle Physics and Astronomy Research Council.
176             All Rights Reserved.
177              
178             This program is free software; you can redistribute it and/or modify it under
179             the terms of the GNU General Public License as published by the Free Software
180             Foundation; either Version 2 of the License, or (at your option) any later
181             version.
182              
183             This program is distributed in the hope that it will be useful,but WITHOUT ANY
184             WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
185             PARTICULAR PURPOSE. See the GNU General Public License for more details.
186              
187             You should have received a copy of the GNU General Public License along with
188             this program; if not, write to the Free Software Foundation, Inc., 59 Temple
189             Place, Suite 330, Boston, MA 02111-1307, USA.
190              
191             =cut
192              
193             1;