HdrTrans/UKIRT.pm

filter: Statementstmt 96.5% 56 / 58 Branchbran 81.2% 13 / 16 Conditioncond 83.3% 10 / 12 MC/DCmcdc 66.6% 4 / 6 Subroutinesub 100% 13 / 13 Podpod 100% 7 / 7 totaltotal 91.9% 103 / 112 CC 13 SCAR 10.5
CC
13
Cov
92%
can_translate
5.0
to_COORDINATE_TYPE
4.2
_parse_date_info
3.0
CRAP 2.9
« HdrTrans/SCUBA2.pm ↑ Summary HdrTrans/UKIRTOld.pm »
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 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 20 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 20 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 20 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 # inherit from the JAC translation class.
25 20 ▶use base qw/ Astro::FITS::HdrTrans::JAC /;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 20 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 20 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 20 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 20 __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 131 ▶sub can_translate {
Subroutine can_translate: called CC=5 SCAR=16.1
Pod documented
85 131 my $self = shift;
86 131 my $FITS_headers = shift;
87  
88 131 ▶ if ( exists $FITS_headers->{TELESCOP} &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $FITS_headers->{"TELESCOP"} and $FITS_headers->{"TELESCOP"} =~ /UKIRT/ and exists $FITS_headers->{"FILENAME"} and exists $FITS_headers->{"RAJ2000"}) 6 125 131
Condition88%8/9
exists $FITS_headers->{"TELESCOP"} and $FITS_headers->{"TELESCOP"} =~ /UKIRT/ and exists $FITS_headers->{"FILENAME"} and exists $FITS_headers->{"RAJ2000"}
!ll&&!rl&&r
12506
exists $FITS_headers->{"TELESCOP"} and $FITS_headers->{"TELESCOP"} =~ /UKIRT/ and exists $FITS_headers->{"FILENAME"}
!ll&&!rl&&r
65606
exists $FITS_headers->{"TELESCOP"} and $FITS_headers->{"TELESCOP"} =~ /UKIRT/
!ll&&!rl&&r
293666
MC/DC75%3/4
exists $FITS_headers->{"TELESCOP"} and $FITS_headers->{"TELESCOP"} =~ /UKIRT/ and exists $FITS_headers->{"FILENAME"} and exists $FITS_headers->{"RAJ2000"}
exists $FITS_headers->{"TELESCOP"} $FITS_headers->{"TELESCOP"} =~ /UKIRT/ exists $FITS_headers->{"FILENAME"} exists $FITS_headers->{"RAJ2000"}
Truth table80%4/5
A and B and C and D
A= exists $FITS_headers->{"TELESCOP"}B= $FITS_headers->{"TELESCOP"} =~ /UKIRT/C= exists $FITS_headers->{"FILENAME"}D= exists $FITS_headers->{"RAJ2000"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
89 $FITS_headers->{TELESCOP} =~ /UKIRT/ &&
90 exists $FITS_headers->{FILENAME} &&
91 exists $FITS_headers->{RAJ2000}) {
92 6 return 0;
93 }
94 125 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 12 ▶sub to_COORDINATE_TYPE {
Subroutine to_COORDINATE_TYPE: called CC=4 SCAR=14.2
Pod documented
120 12 my $self = shift;
121 12 my $FITS_headers = shift;
122 12 my $return;
123 12 ▶ if ( exists( $FITS_headers->{EQUINOX} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $FITS_headers->{"EQUINOX"}) 10 2 12
124 10 ▶ if ( $FITS_headers->{EQUINOX} =~ /1950/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($FITS_headers->{'EQUINOX'} =~ /1950/) { } 0 10 10
elsif ($FITS_headers->{'EQUINOX'} =~ /2000/) { } 10 0 10
125 0 $return = "B1950";
126 } elsif ( $FITS_headers->{EQUINOX} =~ /2000/ ) {
127 10 $return = "J2000";
128 }
129 }
130 12 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 12 ▶sub from_COORDINATE_TYPE {
Subroutine from_COORDINATE_TYPE: called CC=1 SCAR=0.0
Pod documented
140 12 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 10 ▶sub to_RA_BASE {
Subroutine to_RA_BASE: called CC=2 SCAR=6.9
Pod documented
155 10 my $self = shift;
156 10 my $FITS_headers = shift;
157 10 my $return;
158 10 ▶ if ( exists($FITS_headers->{RABASE} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $FITS_headers->{"RABASE"}) 8 2 10
159 8 $return = $FITS_headers->{RABASE} * 15;
160 }
161 10 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 11 ▶sub from_RA_BASE {
Subroutine from_RA_BASE: called CC=3 SCAR=11.0
Pod documented
174 11 my $self = shift;
175 11 my $generic_headers = shift;
176 11 my %return_hash;
177 11 ▶ if ( exists( $generic_headers->{RA_BASE} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $generic_headers->{"RA_BASE"} and defined $generic_headers->{"RA_BASE"}) 9 2 11
Condition66%2/3
exists $generic_headers->{"RA_BASE"} and defined $generic_headers->{"RA_BASE"}
!ll&&!rl&&r
209
MC/DC50%1/2
exists $generic_headers->{"RA_BASE"} and defined $generic_headers->{"RA_BASE"}
exists $generic_headers->{"RA_BASE"} defined $generic_headers->{"RA_BASE"}
Truth table66%2/3
A and B
A= exists $generic_headers->{"RA_BASE"}B= defined $generic_headers->{"RA_BASE"}
ABresult
0X0
100
111
178 defined( $generic_headers->{RA_BASE} ) ) {
179 9 $return_hash{'RABASE'} = $generic_headers->{RA_BASE} / 15;
180 }
181 11 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 12 ▶sub to_TELESCOPE {
Subroutine to_TELESCOPE: called CC=1 SCAR=0.0
Pod documented
192 12 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 5 ▶sub from_TELESCOPE {
Subroutine from_TELESCOPE: called CC=1 SCAR=0.0
Pod documented
203 5 my %return_hash = ( TELESCOP => 'UKIRT' );
204 5 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 33 ▶sub _parse_date_info {
Subroutine _parse_date_info: called CC=3 SCAR=11.1
227 33 my $self = shift;
228 33 my ($iso, $yyyymmdd, $utdechour) = @_;
229  
230 # If we do not have an ISO string, form one.
231 33 ▶ if ( !defined $iso ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $iso) 18 15 33
232  
233 # Convert the decimal hours to hms.
234 18 my $uthour = int( $utdechour );
235 18 my $utminute = int( ( $utdechour - $uthour ) * 60 );
236 18 my $utsecond = int( ( ( ( $utdechour - $uthour ) * 60 ) - $utminute ) * 60 );
237 18 ▶ if ( !defined( $yyyymmdd ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $yyyymmdd) 0 18 18
238 0 $yyyymmdd = 19700101;
239 }
240 18 $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 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 20 1;
« HdrTrans/SCUBA2.pm ↑ Summary HdrTrans/UKIRTOld.pm »