File Coverage

blib/lib/Astro/FITS/HdrTrans/CGS4Old.pm
Criterion Covered Total %
statement 77 89 86.5
branch 17 40 42.5
condition 34 70 48.5
subroutine 15 15 100.0
pod 9 9 100.0
total 152 223 68.1


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