File Coverage

blib/lib/Astro/FITS/HdrTrans/UKIRTOld.pm
Criterion Covered Total %
statement 57 62 91.9
branch 6 12 50.0
condition 1 3 33.3
subroutine 12 12 100.0
pod 7 7 100.0
total 83 96 86.4


line stmt bran cond sub pod time code
1             package Astro::FITS::HdrTrans::UKIRTOld;
2              
3             =head1 NAME
4              
5             Astro::FITS::HdrTrans::UKIRTOld - Base class for translation of old UKIRT instruments
6              
7             =head1 SYNOPSIS
8              
9             use Astro::FITS::HdrTrans::UKIRTOld;
10              
11             =head1 DESCRIPTION
12              
13             This class provides a generic set of translations that are common to
14             CGS4 and IRCAM from the United Kingdom Infrared Telescope. It should
15             not be used directly for translation of instrument FITS headers.
16              
17             =cut
18              
19 12     12   57380950 use 5.006;
  12         67  
20 12     12   140 use warnings;
  12         112  
  12         3318  
21 12     12   123 use strict;
  12         228  
  12         570  
22 12     12   133 use Carp;
  12         100  
  12         1785  
23              
24             # Inherit from UKIRT
25 12     12   135 use base qw/ Astro::FITS::HdrTrans::UKIRT /;
  12         41  
  12         9253  
26              
27             our $VERSION = "1.66";
28              
29             # For a constant mapping, there is no FITS header, just a generic
30             # header that is constant.
31             my %CONST_MAP = (
32              
33             );
34              
35             # Unit mapping implies that the value propogates directly
36             # to the output with only a keyword name change.
37             my %UNIT_MAP = (
38             DETECTOR_READ_TYPE => "MODE", # Also UFTI
39             DR_RECIPE => "DRRECIPE",
40             EXPOSURE_TIME => "DEXPTIME",
41             GAIN => "DEPERDN",
42             );
43              
44             # Create the translation methods.
45             __PACKAGE__->_generate_lookup_methods( \%CONST_MAP, \%UNIT_MAP );
46              
47             =head1 COMPLEX CONVERSIONS
48              
49             These methods are more complicated than a simple mapping. We have to
50             provide both from- and to-FITS conversions. All these routines are
51             methods and the to_ routines all take a reference to a hash and return
52             the translated value (a many-to-one mapping). The from_ methods take
53             a reference to a generic hash and return a translated hash (sometimes
54             these are many-to-many).
55              
56             =over 4
57              
58             =item B<to_UTDATE>
59              
60             Converts IDATE into UTDATE without any modification. Flattens
61             duplicate headers into a single header.
62              
63             =cut
64              
65             sub to_UTDATE {
66 36     36 1 85 my $self = shift;
67 36         67 my $FITS_headers = shift;
68 36         58 my $return;
69 36 50       134 my $utdate = ( exists $FITS_headers->{IDATE} ? $FITS_headers->{IDATE} : undef );
70 36 50 33     2244 if ( defined( $utdate ) && ref( $utdate ) eq 'ARRAY' ) {
71 0         0 $return = $utdate->[0];
72             } else {
73 36         72 $return = $utdate;
74             }
75 36         138 return $return;
76             }
77              
78             =item B<from_UTDATE>
79              
80             Converts UTDATE into IDATE without any modification.
81              
82             =cut
83              
84             sub from_UTDATE {
85 6     6 1 96 return ( "IDATE", $_[1]->{'UTDATE'} );
86             }
87              
88             =item B<to_UTSTART>
89              
90             Converts FITS header UT date/time values for the start of the observation
91             into a C<Time::Piece> object.
92              
93             =cut
94              
95             sub to_UTSTART {
96 12     12 1 25 my $self = shift;
97 12         43 my $FITS_headers = shift;
98              
99 12         70 my $utdate = $self->to_UTDATE( $FITS_headers );
100 12         49 my @rutstart = sort {$a<=>$b} $self->via_subheader( $FITS_headers, "RUTSTART" );
  0         0  
101 12         31 my $utdechour = $rutstart[0];
102              
103             # We do not have a DATE-OBS.
104 12         82 return $self->_parse_date_info( undef, $utdate, $utdechour );
105             }
106              
107             =item B<from_UTSTART>
108              
109             Converts a C<Time::Piece> object into two FITS headers for IRCAM: IDATE
110             (in the format YYYYMMDD) and RUTSTART (decimal hours).
111              
112             =cut
113              
114             sub from_UTSTART {
115 6     6 1 16 my $class = shift;
116 6         22 my $generic_headers = shift;
117 6         18 my %return_hash;
118 6 50       39 if ( exists($generic_headers->{UTSTART} ) ) {
119 6         19 my $date = $generic_headers->{UTSTART};
120 6 50       32 if ( ! UNIVERSAL::isa( $date, "Time::Piece" ) ) {
121 0         0 return;
122             }
123 6         24 $return_hash{IDATE} = sprintf( "%4d%02d%02d", $date->year, $date->mon, $date->mday );
124 6         103 $return_hash{RUTSTART} = $date->hour + ( $date->minute / 60 ) + ( $date->second / 3600 );
125             }
126 6         183 return %return_hash;
127             }
128              
129             =item B<to_UTEND>
130              
131             Converts FITS header UT date/time values for the end of the observation into
132             a C<Time::Piece> object.
133              
134             =cut
135              
136             sub to_UTEND {
137 6     6 1 16 my $self = shift;
138 6         15 my $FITS_headers = shift;
139 6         13 my $return;
140 6         22 my $utdate = $self->to_UTDATE( $FITS_headers );
141 6         32 my @rutend = sort {$a<=>$b} $self->via_subheader( $FITS_headers, "RUTEND" );
  0         0  
142 6         18 my $utdechour = $rutend[-1];
143              
144             # We do not have a DATE-END.
145 6         33 return $self->_parse_date_info( undef, $utdate, $utdechour );
146             }
147              
148             =item B<from_UTEND>
149              
150             Converts a C<Time::Piece> object into two FITS headers for IRCAM: IDATE
151             (in the format YYYYMMDD) and RUTEND (decimal hours).
152              
153             =cut
154              
155             sub from_UTEND {
156 6     6 1 18 my $class = shift;
157 6         15 my $generic_headers = shift;
158 6         12 my %return_hash;
159 6 50       28 if ( exists($generic_headers->{UTEND} ) ) {
160 6         17 my $date = $generic_headers->{UTEND};
161 6 50       38 if ( ! UNIVERSAL::isa( $date, "Time::Piece" ) ) {
162 0         0 return;
163             }
164 6         42 $return_hash{IDATE} = sprintf( "%4d%02d%02d", $date->year, $date->mon, $date->mday );
165 6         151 $return_hash{RUTEND} = $date->hour + ( $date->minute / 60 ) + ( $date->second / 3600 );
166             }
167 6         241 return %return_hash;
168             }
169              
170             =item B<to_INST_DHS>
171              
172             Sets the instrument data handling system header. Note that for old
173             instruments there is no DHSVER header so this simply returns
174             the name of the instrument and a UKDHS suffix.
175              
176             =cut
177              
178             sub to_INST_DHS {
179 6     6 1 20 my $self = shift;
180 6         25 my $FITS_headers = shift;
181 6         222 my $inst = $self->to_INSTRUMENT( $FITS_headers );
182 6         31 return $inst . '_UKDHS';
183             }
184              
185             =back
186              
187             =head1 SEE ALSO
188              
189             C<Astro::FITS::HdrTrans>, C<Astro::FITS::HdrTrans::UKIRT>
190              
191             =head1 AUTHOR
192              
193             Brad Cavanagh E<lt>b.cavanagh@jach.hawaii.eduE<gt>,
194             Tim Jenness E<lt>t.jenness@jach.hawaii.eduE<gt>.
195              
196             =head1 COPYRIGHT
197              
198             Copyright (C) 2007-2008 Science and Technology Facilities Council.
199             Copyright (C) 2003-2007 Particle Physics and Astronomy Research Council.
200             All Rights Reserved.
201              
202             This program is free software; you can redistribute it and/or modify it under
203             the terms of the GNU General Public License as published by the Free Software
204             Foundation; either Version 2 of the License, or (at your option) any later
205             version.
206              
207             This program is distributed in the hope that it will be useful,but WITHOUT ANY
208             WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
209             PARTICULAR PURPOSE. See the GNU General Public License for more details.
210              
211             You should have received a copy of the GNU General Public License along with
212             this program; if not, write to the Free Software Foundation, Inc., 59 Temple
213             Place, Suite 330, Boston, MA 02111-1307, USA.
214              
215             =cut
216              
217             1;