File Coverage

blib/lib/Astro/FITS/HdrTrans/UKIRTOld.pm
Criterion Covered Total %
statement 60 65 92.3
branch 6 12 50.0
condition 1 3 33.3
subroutine 13 13 100.0
pod 7 7 100.0
total 87 100 87.0


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