File Coverage

blib/lib/Astro/FITS/HdrTrans/UKIRT.pm
Criterion Covered Total %
statement 54 56 96.4
branch 12 16 75.0
condition 10 12 83.3
subroutine 14 14 100.0
pod 7 7 100.0
total 97 105 92.3


line stmt bran cond sub pod time code
1             package Astro::FITS::HdrTrans::UKIRT;
2              
3             =head1 NAME
4              
5             Astro::FITS::HdrTrans::UKIRT - Base class for translation of UKIRT instruments
6              
7             =head1 SYNOPSIS
8              
9             use Astro::FITS::HdrTrans::UKIRT;
10              
11             =head1 DESCRIPTION
12              
13             This class provides a generic set of translations that are common to
14             instrumentation from the United Kingdom Infrared Telescope. It should
15             not be used directly for translation of instrument FITS headers.
16              
17             =cut
18              
19 20     20   24957064 use 5.006;
  20         148  
20 20     20   136 use warnings;
  20         59  
  20         742  
21 20     20   146 use strict;
  20         53  
  20         526  
22 20     20   112 use Carp;
  20         56  
  20         1529  
23              
24             # inherit from the JAC translation class.
25 20     20   139 use base qw/ Astro::FITS::HdrTrans::JAC /;
  20         95  
  20         7400  
26              
27 20     20   134 use vars qw/ $VERSION /;
  20         41  
  20         13854  
28              
29             $VERSION = "1.64";
30              
31             # In each class we have three sets of data.
32             # - constant mappings
33             # - unit mappings
34             # - complex mappings
35              
36             # For a constant mapping, there is no FITS header, just a generic
37             # header that is constant.
38             my %CONST_MAP = (
39             COORDINATE_UNITS => 'degrees',
40             );
41              
42             # Unit mapping implies that the value propogates directly
43             # to the output with only a keyword name change.
44             my %UNIT_MAP = (
45             AIRMASS_END => "AMEND",
46             AIRMASS_START => "AMSTART",
47             DEC_BASE => "DECBASE",
48             DETECTOR_INDEX => "DINDEX", # Needs subheader
49             DR_GROUP => "GRPNUM",
50             EQUINOX => "EQUINOX",
51             FILTER => "FILTER",
52             INSTRUMENT => "INSTRUME",
53             NUMBER_OF_EXPOSURES => "NEXP",
54             NUMBER_OF_OFFSETS => "NOFFSETS",
55             OBJECT => "OBJECT",
56             OBSERVATION_NUMBER => "OBSNUM",
57             OBSERVATION_TYPE => "OBSTYPE",
58             PROJECT => "PROJECT",
59             STANDARD => "STANDARD",
60             WAVEPLATE_ANGLE => "WPLANGLE",
61             X_APERTURE => "APER_X",
62             X_DIM => "DCOLUMNS",
63             X_LOWER_BOUND => "RDOUT_X1",
64             X_UPPER_BOUND => "RDOUT_X2",
65             Y_APERTURE => "APER_Y",
66             Y_DIM => "DROWS",
67             Y_LOWER_BOUND => "RDOUT_Y1",
68             Y_UPPER_BOUND => "RDOUT_Y2"
69             );
70              
71             # Create the translation methods.
72             __PACKAGE__->_generate_lookup_methods( \%CONST_MAP, \%UNIT_MAP );
73              
74             =head1 METHODS
75              
76             =over 4
77              
78             =item B<can_translate>
79              
80             This implementation of C<can_translate> is used to filter out a
81             database row from an actual file header. The base-class
82             implementation is used if the filter passes.
83              
84             =cut
85              
86             sub can_translate {
87 131     131 1 333 my $self = shift;
88 131         272 my $FITS_headers = shift;
89              
90 131 50 100     647 if ( exists $FITS_headers->{TELESCOP} &&
      100        
      66        
91             $FITS_headers->{TELESCOP} =~ /UKIRT/ &&
92             exists $FITS_headers->{FILENAME} &&
93             exists $FITS_headers->{RAJ2000}) {
94 6         28 return 0;
95             }
96 125         12537 return $self->SUPER::can_translate( $FITS_headers );
97             }
98              
99             =back
100              
101             =head1 COMPLEX CONVERSIONS
102              
103             These methods are more complicated than a simple mapping. We have to
104             provide both from- and to-FITS conversions. All these routines are
105             methods and the to_ routines all take a reference to a hash and return
106             the translated value (a many-to-one mapping). The from_ methods take a
107             reference to a generic hash and return a translated hash (sometimes
108             these are many-to-many).
109              
110             =over 4
111              
112             =item B<to_COORDINATE_TYPE>
113              
114             Converts the C<EQUINOX> FITS header into B1950 or J2000, depending
115             on equinox value, and sets the C<COORDINATE_TYPE> generic header.
116              
117             $class->to_COORDINATE_TYPE( \%hdr );
118              
119             =cut
120              
121             sub to_COORDINATE_TYPE {
122 12     12 1 32 my $self = shift;
123 12         29 my $FITS_headers = shift;
124 12         24 my $return;
125 12 100       51 if ( exists( $FITS_headers->{EQUINOX} ) ) {
126 10 50       301 if ( $FITS_headers->{EQUINOX} =~ /1950/ ) {
    50          
127 0         0 $return = "B1950";
128             } elsif ( $FITS_headers->{EQUINOX} =~ /2000/ ) {
129 10         1347 $return = "J2000";
130             }
131             }
132 12         53 return $return;
133             }
134              
135             =item B<from_COORDINATE_TYPE>
136              
137             A null translation since EQUINOX is translated separately.
138              
139             =cut
140              
141             sub from_COORDINATE_TYPE {
142 12     12 1 71 return ();
143             }
144              
145              
146             =item B<to_RA_BASE>
147              
148             Converts the decimal hours in the FITS header C<RABASE> into
149             decimal degrees for the generic header C<RA_BASE>.
150              
151             Note that this is different from the original translation within
152             ORAC-DR where it was to decimal hours.
153              
154             =cut
155              
156             sub to_RA_BASE {
157 10     10 1 28 my $self = shift;
158 10         28 my $FITS_headers = shift;
159 10         24 my $return;
160 10 100       34 if ( exists($FITS_headers->{RABASE} ) ) {
161 8         225 $return = $FITS_headers->{RABASE} * 15;
162             }
163 10         581 return $return;
164             }
165              
166             =item B<from_RA_BASE>
167              
168             Converts the decimal degrees in the generic header C<RA_BASE>
169             into decimal hours for the FITS header C<RABASE>.
170              
171             %fits = $class->from_RA_BASE( \%generic );
172              
173             =cut
174              
175             sub from_RA_BASE {
176 11     11 1 28 my $self = shift;
177 11         21 my $generic_headers = shift;
178 11         26 my %return_hash;
179 11 100 66     91 if ( exists( $generic_headers->{RA_BASE} ) &&
180             defined( $generic_headers->{RA_BASE} ) ) {
181 9         38 $return_hash{'RABASE'} = $generic_headers->{RA_BASE} / 15;
182             }
183 11         153 return %return_hash;
184             }
185              
186             =item B<to_TELESCOPE>
187              
188             Sets the generic header C<TELESCOPE> to 'UKIRT', so that it is
189             SLALIB-compliant.
190              
191             =cut
192              
193             sub to_TELESCOPE {
194 12     12 1 46 return "UKIRT";
195             }
196              
197             =item B<from_TELESCOPE>
198              
199             Sets the specific header C<TELESCOP> to 'UKIRT'. Note that this will
200             probably be sub-classed.
201              
202             =cut
203              
204             sub from_TELESCOPE {
205 5     5 1 21 my %return_hash = ( TELESCOP => 'UKIRT' );
206 5         86 return %return_hash;
207             }
208              
209              
210             =back
211              
212             =head1 HELPER ROUTINES
213              
214             These are UKIRT-specific helper routines.
215              
216             =over 4
217              
218             =item B<_parse_date_info>
219              
220             Given either a ISO format date string or a UT date (YYYYMMDD) and
221             decimal hours UT, calculate the time and return it as an object.
222             Preference is given to the ISO version.
223              
224             $time = $trans->_parse_date_info($iso, $yyyymmdd, $uthr );
225              
226             =cut
227              
228             sub _parse_date_info {
229 33     33   99 my $self = shift;
230 33         87 my ($iso, $yyyymmdd, $utdechour) = @_;
231              
232             # If we do not have an ISO string, form one.
233 33 100       93 if ( !defined $iso ) {
234              
235             # Convert the decimal hours to hms.
236 18         66 my $uthour = int( $utdechour );
237 18         56 my $utminute = int( ( $utdechour - $uthour ) * 60 );
238 18         48 my $utsecond = int( ( ( ( $utdechour - $uthour ) * 60 ) - $utminute ) * 60 );
239 18 50       53 if ( !defined( $yyyymmdd ) ) {
240 0         0 $yyyymmdd = 19700101;
241             }
242 18         197 $iso = sprintf( "%04d-%02d-%02dT%02d:%02d:%02s",
243             substr( $yyyymmdd, 0, 4 ),
244             substr( $yyyymmdd, 4, 2 ),
245             substr( $yyyymmdd, 6, 2 ),
246             $uthour, $utminute, $utsecond);
247             }
248 33         179 return $self->_parse_iso_date( $iso );
249             }
250              
251             =back
252              
253             =head1 SEE ALSO
254              
255             C<Astro::FITS::HdrTrans>, C<Astro::FITS::HdrTrans::Base>
256              
257             =head1 AUTHOR
258              
259             Brad Cavanagh E<lt>b.cavanagh@jach.hawaii.eduE<gt>,
260             Tim Jenness E<lt>t.jenness@jach.hawaii.eduE<gt>.
261             Malcolm J. Currie E<lt>mjc@star.rl.ac.ukE<gt>
262              
263             =head1 COPYRIGHT
264              
265             Copyright (C) 2007-2008 Science and Technology Facilities Council.
266             Copyright (C) 2003-2007 Particle Physics and Astronomy Research Council.
267             All Rights Reserved.
268              
269             This program is free software; you can redistribute it and/or modify it under
270             the terms of the GNU General Public License as published by the Free Software
271             Foundation; either version 2 of the License, or (at your option) any later
272             version.
273              
274             This program is distributed in the hope that it will be useful,but WITHOUT ANY
275             WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
276             PARTICULAR PURPOSE. See the GNU General Public License for more details.
277              
278             You should have received a copy of the GNU General Public License along with
279             this program; if not, write to the Free Software Foundation, Inc., 59 Temple
280             Place,Suite 330, Boston, MA 02111-1307, USA
281              
282             =cut
283              
284             1;