File Coverage

blib/lib/Astro/FITS/HdrTrans/CGS4Old.pm
Criterion Covered Total %
statement 74 86 86.0
branch 17 40 42.5
condition 34 70 48.5
subroutine 14 14 100.0
pod 9 9 100.0
total 148 219 67.5


line stmt bran cond sub pod time code
1             package Astro::FITS::HdrTrans::CGS4Old;
2              
3             =head1 NAME
4              
5             Astro::FITS::HdrTrans::CGS4 - UKIRT CGS4 translations for "old" style
6             CGS4 headers.
7              
8             =head1 SYNOPSIS
9              
10             use Astro::FITS::HdrTrans::CGS4Old;
11              
12             %gen = Astro::FITS::HdrTrans::CGS4Old->translate_from_FITS( %hdr );
13              
14             =head1 DESCRIPTION
15              
16             This class provides a generic set of translations that are specific
17             to the CGS4 spectrometer of the United Kingdom Infrared Telescope.
18              
19             =cut
20              
21 10     10   5782316 use 5.006;
  10         63  
22 10     10   353 use warnings;
  10         26  
  10         1026  
23 10     10   413 use strict;
  10         161  
  10         361  
24 10     10   74 use Carp;
  10         22  
  10         1356  
25              
26             # Inherit from UKIRT "Old"
27 10     10   85 use base qw/ Astro::FITS::HdrTrans::UKIRTOld /;
  10         22  
  10         16318  
28              
29             our $VERSION = "1.66";
30              
31             # for a constant mapping, there is no FITS header, just a generic
32             # header that is constant
33             my %CONST_MAP = (
34              
35             );
36              
37             # unit mapping implies that the value propogates directly
38             # to the output with only a keyword name change
39              
40             my %UNIT_MAP = (
41             # CGS4 Specific
42             GRATING_DISPERSION => "GDISP",
43             GRATING_NAME => "GRATING",
44             GRATING_ORDER => "GORDER",
45             GRATING_WAVELENGTH => "GLAMBDA",
46             SLIT_ANGLE => "SANGLE",
47             SLIT_NAME => "SLIT",
48             SLIT_WIDTH => "SWIDTH",
49             # MICHELLE compatible
50             NSCAN_POSITIONS => "DETNINCR",
51             SCAN_INCREMENT => "DETINCR",
52             # MICHELLE + UIST + WFCAM
53             CONFIGURATION_INDEX => 'CNFINDEX',
54             );
55              
56              
57             # Create the translation methods
58             __PACKAGE__->_generate_lookup_methods( \%CONST_MAP, \%UNIT_MAP );
59              
60             # Im
61              
62             =head1 METHODS
63              
64             =over 4
65              
66             =item B<can_translate>
67              
68             Returns true if the supplied headers can be handled by this class.
69              
70             $cando = $class->can_translate( \%hdrs );
71              
72             This method returns true if the INSTRUME header exists and is equal to
73             'CGS4', and if the IDATE header exists, matches the regular
74             expression '\d{8}', and is less than 20081115.
75              
76             It also handles the reverse (to FITS) case where the INSTRUMENT header
77             replaces INSTRUME, and UTDATE replaces IDATE in the above tests.
78              
79             =cut
80              
81             sub can_translate {
82 22     22 1 70 my $self = shift;
83 22         50 my $headers = shift;
84              
85 22 100 66     197 if ( exists $headers->{IDATE} &&
      66        
      33        
      33        
      33        
      33        
      66        
86             defined $headers->{IDATE} &&
87             $headers->{IDATE} =~ /\d{8}/ &&
88             $headers->{IDATE} < 20081115 &&
89             exists $headers->{INSTRUME} &&
90             defined $headers->{INSTRUME} &&
91             ! exists $headers->{RAJ2000} &&
92             uc( $headers->{INSTRUME} ) eq 'CGS4' ) {
93 2         1204 return 1;
94             }
95              
96             # Need to handle the reverse case as well. This module can translate
97             # CGS4 headers older than 20081115. Note that the translations mean
98             # different header names are tested.
99 20 50 66     1471 if ( exists $headers->{UTDATE} &&
      100        
      100        
      100        
      66        
      66        
100             defined $headers->{UTDATE} &&
101             $headers->{UTDATE} =~ /\d{8}/ &&
102             $headers->{UTDATE} < 20081115 &&
103             exists $headers->{INSTRUMENT} &&
104             defined $headers->{INSTRUMENT} &&
105             uc( $headers->{INSTRUMENT} ) eq 'CGS4' ) {
106 2         14 return 1;
107             }
108              
109 18         3638 return 0;
110             }
111              
112             =back
113              
114             =head1 COMPLEX CONVERSIONS
115              
116             These methods are more complicated than a simple mapping. We have to
117             provide both from- and to-FITS conversions All these routines are
118             methods and the to_ routines all take a reference to a hash and return
119             the translated value (a many-to-one mapping) The from_ methods take a
120             reference to a generic hash and return a translated hash (sometimes
121             these are many-to-many)
122              
123             =over 4
124              
125             =item B<to_POLARIMETRY>
126              
127             Checks the C<FILTER> FITS header keyword for the existance of
128             'prism'. If 'prism' is found, then the C<POLARIMETRY> generic
129             header is set to 1, otherwise 0.
130              
131             =cut
132              
133             sub to_POLARIMETRY {
134 2     2 1 5 my $self = shift;
135 2         6 my $FITS_headers = shift;
136 2         4 my $return;
137 2 50       11 if (exists($FITS_headers->{FILTER})) {
138 2 50       64 $return = ( $FITS_headers->{FILTER} =~ /prism/i ? 1 : 0);
139             }
140 2         148 return $return;
141             }
142              
143             =item B<to_DEC_TELESCOPE_OFFSET>
144              
145             The header keyword for the Dec telescope offset changed from DECOFF to
146             TDECOFF on 20050315, so switch on this date to use the proper header.
147              
148             =cut
149              
150             sub to_DEC_TELESCOPE_OFFSET {
151 2     2 1 7 my $self = shift;
152 2         4 my $FITS_headers = shift;
153 2         6 my $return;
154 2 50 33     11 if ( exists( $FITS_headers->{IDATE} ) && defined( $FITS_headers->{IDATE} ) ) {
155 2 50       272 if ( $FITS_headers->{IDATE} < 20050315 ) {
156 2         175 $return = $FITS_headers->{DECOFF};
157             } else {
158 0         0 $return = $FITS_headers->{TDECOFF};
159             }
160             }
161 2         196 return $return;
162             }
163              
164             =item B<from_DEC_TELESCOPE_OFFSET>
165              
166             The header keyword for the Dec telescope offset changed from DECOFF to
167             TDECOFF on 20050315, so return the proper keyword depending on observation
168             date.
169              
170             =cut
171              
172             sub from_DEC_TELESCOPE_OFFSET {
173 2     2 1 5 my $self = shift;
174 2         6 my $generic_headers = shift;
175 2         3 my %return;
176 2 50 33     19 if ( exists( $generic_headers->{UTDATE} ) &&
177             defined( $generic_headers->{UTDATE} ) ) {
178 2         6 my $ut = $generic_headers->{UTDATE};
179 2 50 33     18 if ( exists( $generic_headers->{DEC_TELESCOPE_OFFSET} ) &&
180             defined( $generic_headers->{DEC_TELESCOPE_OFFSET} ) ) {
181 2 50       6 if ( $ut < 20050315 ) {
182 2         9 $return{'DECOFF'} = $generic_headers->{DEC_TELESCOPE_OFFSET};
183             } else {
184 0         0 $return{'TDECOFF'} = $generic_headers->{DEC_TELESCOPE_OFFSET};
185             }
186             }
187             } else {
188 0 0 0     0 if ( exists( $generic_headers->{DEC_TELESCOPE_OFFSET} ) &&
189             defined( $generic_headers->{DEC_TELESCOPE_OFFSET} ) ) {
190 0         0 $return{'TDECOFF'} = $generic_headers->{DEC_TELESCOPE_OFFSET};
191             }
192             }
193 2         13 return %return;
194             }
195              
196             =item B<to_RA_TELESCOPE_OFFSET>
197              
198             The header keyword for the RA telescope offset changed from RAOFF to
199             TRAOFF on 20050315, so switch on this date to use the proper header.
200              
201             =cut
202              
203             sub to_RA_TELESCOPE_OFFSET {
204 2     2 1 6 my $self = shift;
205 2         4 my $FITS_headers = shift;
206 2         3 my $return;
207 2 50 33     7 if ( exists( $FITS_headers->{IDATE} ) && defined( $FITS_headers->{IDATE} ) ) {
208 2 50       211 if ( $FITS_headers->{IDATE} < 20050315 ) {
209 2         132 $return = $FITS_headers->{RAOFF};
210             } else {
211 0         0 $return = $FITS_headers->{TRAOFF};
212             }
213             }
214 2         170 return $return;
215             }
216              
217             =item B<from_RA_TELESCOPE_OFFSET>
218              
219             The header keyword for the RA telescope offset changed from RAOFF to
220             TRAOFF on 20050315, so return the proper keyword depending on observation
221             date.
222              
223             =cut
224              
225             sub from_RA_TELESCOPE_OFFSET {
226 2     2 1 5 my $self = shift;
227 2         5 my $generic_headers = shift;
228 2         4 my %return;
229 2 50 33     14 if ( exists( $generic_headers->{UTDATE} ) &&
230             defined( $generic_headers->{UTDATE} ) ) {
231 2         5 my $ut = $generic_headers->{UTDATE};
232 2 50 33     24 if ( exists( $generic_headers->{RA_TELESCOPE_OFFSET} ) &&
233             defined( $generic_headers->{RA_TELESCOPE_OFFSET} ) ) {
234 2 50       6 if ( $ut < 20050315 ) {
235 2         7 $return{'RAOFF'} = $generic_headers->{RA_TELESCOPE_OFFSET};
236             } else {
237 0         0 $return{'TRAOFF'} = $generic_headers->{RA_TELESCOPE_OFFSET};
238             }
239             }
240             } else {
241 0 0 0     0 if ( exists( $generic_headers->{RA_TELESCOPE_OFFSET} ) &&
242             defined( $generic_headers->{RA_TELESCOPE_OFFSET} ) ) {
243 0         0 $return{'TRAOFF'} = $generic_headers->{RA_TELESCOPE_OFFSET};
244             }
245             }
246 2         33 return %return;
247             }
248              
249             =item B<to_DETECTOR_READ_TYPE>
250              
251             Should be the "MODE" header but if this is missing we can look
252             at INTTYPE instead.
253              
254             =cut
255              
256             sub to_DETECTOR_READ_TYPE {
257 2     2 1 7 my $self = shift;
258 2         6 my $FITS_headers = shift;
259              
260 2         14 my %mode = (
261             CHOP => 'CHOP',
262             'STARE+NDR' => 'ND_STARE',
263             STARE => 'STARE',
264             );
265              
266 2 50       12 if (exists $FITS_headers->{'MODE'}) {
    0          
267 2         105 return $FITS_headers->{'MODE'};
268             }
269             elsif (exists $FITS_headers->{'INTTYPE'}) {
270 0         0 my $inttype = $FITS_headers->{'INTTYPE'};
271 0 0       0 if (exists $mode{$inttype}) {
272 0         0 return $mode{$inttype};
273             }
274             }
275              
276 0         0 return undef;
277             }
278              
279             =item B<to_SAMPLING>
280              
281             Converts FITS header values in C<DETINCR> and C<DETNINCR> to a single
282             descriptive string.
283              
284             =cut
285              
286             sub to_SAMPLING {
287 2     2 1 6 my $self = shift;
288 2         4 my $FITS_headers = shift;
289 2         5 my $return;
290 2 50 33     9 if (exists($FITS_headers->{DETINCR}) && exists($FITS_headers->{DETNINCR})) {
291 2   50     109 my $detincr = $FITS_headers->{DETINCR} || 1;
292 2   50     157 my $detnincr = $FITS_headers->{DETNINCR} || 1;
293 2         173 $return = int ( 1 / $detincr ) . 'x' . int ( $detincr * $detnincr );
294             }
295 2         10 return $return;
296             }
297              
298             =item B<from_TELESCOPE>
299              
300             Returns 'UKIRT, Mauna Kea, HI' for the C<TELESCOP> FITS header.
301              
302             =cut
303              
304             sub from_TELESCOPE {
305 2     2 1 8 my %return = ( "TELESCOP", "UKIRT, Mauna Kea, HI" );
306 2         48 return %return;
307             }
308              
309             =back
310              
311             =head1 SEE ALSO
312              
313             C<Astro::FITS::HdrTrans>, C<Astro::FITS::HdrTrans::UKIRT>.
314              
315             =head1 AUTHOR
316              
317             Brad Cavanagh E<lt>b.cavanagh@jach.hawaii.eduE<gt>,
318             Tim Jenness E<lt>t.jenness@jach.hawaii.eduE<gt>.
319              
320             =head1 COPYRIGHT
321              
322             Copyright (C) 2003-2005 Particle Physics and Astronomy Research Council.
323             All Rights Reserved.
324              
325             This program is free software; you can redistribute it and/or modify it under
326             the terms of the GNU General Public License as published by the Free Software
327             Foundation; either version 2 of the License, or (at your option) any later
328             version.
329              
330             This program is distributed in the hope that it will be useful,but WITHOUT ANY
331             WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
332             PARTICULAR PURPOSE. See the GNU General Public License for more details.
333              
334             You should have received a copy of the GNU General Public License along with
335             this program; if not, write to the Free Software Foundation, Inc., 59 Temple
336             Place,Suite 330, Boston, MA 02111-1307, USA
337              
338             =cut
339              
340             1;