File Coverage

blib/lib/Astro/FITS/HdrTrans/UKIRT.pm
Criterion Covered Total %
statement 51 53 96.2
branch 12 16 75.0
condition 10 12 83.3
subroutine 13 13 100.0
pod 7 7 100.0
total 93 101 92.0


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