blib/lib/Astro/FITS/HdrTrans/UKIRT.pm

filter: Statementstmt 96.7% 59 / 61 Branchbran 81.2% 13 / 16 Conditioncond 83.3% 10 / 12 MC/DCmcdc 66.6% 4 / 6 Subroutinesub 100% 14 / 14 Podpod 100% 7 / 7 totaltotal 92.2% 107 / 116 CC 13 SCAR 10.3
CC
13
Cov
92%
can_translate
5.0
to_COORDINATE_TYPE
4.2
_parse_date_info
3.0
CRAP 2.8
« blib/lib/Astro/FITS/HdrTrans/SCUBA2.pm ↑ Summary blib/lib/Astro/FITS/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 ▶use vars qw/ $VERSION /;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 20 $VERSION = "1.65";
30  
31 # In each class we have three sets of data.
32 # - constant mappings
33 # - unit mappings
34 # - complex mappings
35  
36 # For a constant mapping, there is no FITS header, just a generic
37 # header that is constant.
38 20 my %CONST_MAP = (
39 COORDINATE_UNITS => 'degrees',
40 );
41  
42 # Unit mapping implies that the value propogates directly
43 # to the output with only a keyword name change.
44 20 my %UNIT_MAP = (
45 AIRMASS_END => "AMEND",
46 AIRMASS_START => "AMSTART",
47 DEC_BASE => "DECBASE",
48 DETECTOR_INDEX => "DINDEX", # Needs subheader
49 DR_GROUP => "GRPNUM",
50 EQUINOX => "EQUINOX",
51 FILTER => "FILTER",
52 INSTRUMENT => "INSTRUME",
53 NUMBER_OF_EXPOSURES => "NEXP",
54 NUMBER_OF_OFFSETS => "NOFFSETS",
55 OBJECT => "OBJECT",
56 OBSERVATION_NUMBER => "OBSNUM",
57 OBSERVATION_TYPE => "OBSTYPE",
58 PROJECT => "PROJECT",
59 STANDARD => "STANDARD",
60 WAVEPLATE_ANGLE => "WPLANGLE",
61 X_APERTURE => "APER_X",
62 X_DIM => "DCOLUMNS",
63 X_LOWER_BOUND => "RDOUT_X1",
64 X_UPPER_BOUND => "RDOUT_X2",
65 Y_APERTURE => "APER_Y",
66 Y_DIM => "DROWS",
67 Y_LOWER_BOUND => "RDOUT_Y1",
68 Y_UPPER_BOUND => "RDOUT_Y2"
69 );
70  
71 # Create the translation methods.
72 20 __PACKAGE__->_generate_lookup_methods( \%CONST_MAP, \%UNIT_MAP );
73  
74 =head1 METHODS
75  
76 =over 4
77  
78 =item B<can_translate>
79  
80 This implementation of C<can_translate> is used to filter out a
81 database row from an actual file header. The base-class
82 implementation is used if the filter passes.
83  
84 =cut
85  
86 sub can_translate {
87 131 ▶ my $self = shift;
Subroutine can_translate: called CC=5 SCAR=16.1
Pod documented
88 131 my $FITS_headers = shift;
89  
90 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
91 $FITS_headers->{TELESCOP} =~ /UKIRT/ &&
92 exists $FITS_headers->{FILENAME} &&
93 exists $FITS_headers->{RAJ2000}) {
94 6 return 0;
95 }
96 125 return $self->SUPER::can_translate( $FITS_headers );
97 }
98  
99 =back
100  
101 =head1 COMPLEX CONVERSIONS
102  
103 These methods are more complicated than a simple mapping. We have to
104 provide both from- and to-FITS conversions. All these routines are
105 methods and the to_ routines all take a reference to a hash and return
106 the translated value (a many-to-one mapping). The from_ methods take a
107 reference to a generic hash and return a translated hash (sometimes
108 these are many-to-many).
109  
110 =over 4
111  
112 =item B<to_COORDINATE_TYPE>
113  
114 Converts the C<EQUINOX> FITS header into B1950 or J2000, depending
115 on equinox value, and sets the C<COORDINATE_TYPE> generic header.
116  
117 $class->to_COORDINATE_TYPE( \%hdr );
118  
119 =cut
120  
121 sub to_COORDINATE_TYPE {
122 12 ▶ my $self = shift;
Subroutine to_COORDINATE_TYPE: called CC=4 SCAR=14.2
Pod documented
123 12 my $FITS_headers = shift;
124 12 my $return;
125 12 ▶ if ( exists( $FITS_headers->{EQUINOX} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $FITS_headers->{"EQUINOX"}) 10 2 12
126 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
127 0 $return = "B1950";
128 } elsif ( $FITS_headers->{EQUINOX} =~ /2000/ ) {
129 10 $return = "J2000";
130 }
131 }
132 12 return $return;
133 }
134  
135 =item B<from_COORDINATE_TYPE>
136  
137 A null translation since EQUINOX is translated separately.
138  
139 =cut
140  
141 sub from_COORDINATE_TYPE {
142 12 ▶ return ();
Subroutine from_COORDINATE_TYPE: called CC=1 SCAR=0.0
Pod documented
143 }
144  
145  
146 =item B<to_RA_BASE>
147  
148 Converts the decimal hours in the FITS header C<RABASE> into
149 decimal degrees for the generic header C<RA_BASE>.
150  
151 Note that this is different from the original translation within
152 ORAC-DR where it was to decimal hours.
153  
154 =cut
155  
156 sub to_RA_BASE {
157 10 ▶ my $self = shift;
Subroutine to_RA_BASE: called CC=2 SCAR=6.9
Pod documented
158 10 my $FITS_headers = shift;
159 10 my $return;
160 10 ▶ if ( exists($FITS_headers->{RABASE} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $FITS_headers->{"RABASE"}) 8 2 10
161 8 $return = $FITS_headers->{RABASE} * 15;
162 }
163 10 return $return;
164 }
165  
166 =item B<from_RA_BASE>
167  
168 Converts the decimal degrees in the generic header C<RA_BASE>
169 into decimal hours for the FITS header C<RABASE>.
170  
171 %fits = $class->from_RA_BASE( \%generic );
172  
173 =cut
174  
175 sub from_RA_BASE {
176 11 ▶ my $self = shift;
Subroutine from_RA_BASE: called CC=3 SCAR=11.0
Pod documented
177 11 my $generic_headers = shift;
178 11 my %return_hash;
179 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
180 defined( $generic_headers->{RA_BASE} ) ) {
181 9 $return_hash{'RABASE'} = $generic_headers->{RA_BASE} / 15;
182 }
183 11 return %return_hash;
184 }
185  
186 =item B<to_TELESCOPE>
187  
188 Sets the generic header C<TELESCOPE> to 'UKIRT', so that it is
189 SLALIB-compliant.
190  
191 =cut
192  
193 sub to_TELESCOPE {
194 12 ▶ return "UKIRT";
Subroutine to_TELESCOPE: called CC=1 SCAR=0.0
Pod documented
195 }
196  
197 =item B<from_TELESCOPE>
198  
199 Sets the specific header C<TELESCOP> to 'UKIRT'. Note that this will
200 probably be sub-classed.
201  
202 =cut
203  
204 sub from_TELESCOPE {
205 5 ▶ my %return_hash = ( TELESCOP => 'UKIRT' );
Subroutine from_TELESCOPE: called CC=1 SCAR=0.0
Pod documented
206 5 return %return_hash;
207 }
208  
209  
210 =back
211  
212 =head1 HELPER ROUTINES
213  
214 These are UKIRT-specific helper routines.
215  
216 =over 4
217  
218 =item B<_parse_date_info>
219  
220 Given either a ISO format date string or a UT date (YYYYMMDD) and
221 decimal hours UT, calculate the time and return it as an object.
222 Preference is given to the ISO version.
223  
224 $time = $trans->_parse_date_info($iso, $yyyymmdd, $uthr );
225  
226 =cut
227  
228 sub _parse_date_info {
229 33 ▶ my $self = shift;
Subroutine _parse_date_info: called CC=3 SCAR=11.1
230 33 my ($iso, $yyyymmdd, $utdechour) = @_;
231  
232 # If we do not have an ISO string, form one.
233 33 ▶ if ( !defined $iso ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $iso) 18 15 33
234  
235 # Convert the decimal hours to hms.
236 18 my $uthour = int( $utdechour );
237 18 my $utminute = int( ( $utdechour - $uthour ) * 60 );
238 18 my $utsecond = int( ( ( ( $utdechour - $uthour ) * 60 ) - $utminute ) * 60 );
239 18 ▶ if ( !defined( $yyyymmdd ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $yyyymmdd) 0 18 18
240 0 $yyyymmdd = 19700101;
241 }
242 18 $iso = sprintf( "%04d-%02d-%02dT%02d:%02d:%02s",
243 substr( $yyyymmdd, 0, 4 ),
244 substr( $yyyymmdd, 4, 2 ),
245 substr( $yyyymmdd, 6, 2 ),
246 $uthour, $utminute, $utsecond);
247 }
248 33 return $self->_parse_iso_date( $iso );
249 }
250  
251 =back
252  
253 =head1 SEE ALSO
254  
255 C<Astro::FITS::HdrTrans>, C<Astro::FITS::HdrTrans::Base>
256  
257 =head1 AUTHOR
258  
259 Brad Cavanagh E<lt>b.cavanagh@jach.hawaii.eduE<gt>,
260 Tim Jenness E<lt>t.jenness@jach.hawaii.eduE<gt>.
261 Malcolm J. Currie E<lt>mjc@star.rl.ac.ukE<gt>
262  
263 =head1 COPYRIGHT
264  
265 Copyright (C) 2007-2008 Science and Technology Facilities Council.
266 Copyright (C) 2003-2007 Particle Physics and Astronomy Research Council.
267 All Rights Reserved.
268  
269 This program is free software; you can redistribute it and/or modify it under
270 the terms of the GNU General Public License as published by the Free Software
271 Foundation; either version 2 of the License, or (at your option) any later
272 version.
273  
274 This program is distributed in the hope that it will be useful,but WITHOUT ANY
275 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
276 PARTICULAR PURPOSE. See the GNU General Public License for more details.
277  
278 You should have received a copy of the GNU General Public License along with
279 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
280 Place,Suite 330, Boston, MA 02111-1307, USA
281  
282 =cut
283  
284 20 1;
« blib/lib/Astro/FITS/HdrTrans/SCUBA2.pm ↑ Summary blib/lib/Astro/FITS/HdrTrans/UKIRTOld.pm »