File Coverage

blib/lib/Astro/FITS/HdrTrans/SCUBA2.pm
Criterion Covered Total %
statement 62 65 95.3
branch 15 26 57.6
condition 2 6 33.3
subroutine 14 14 100.0
pod 8 8 100.0
total 101 119 84.8


line stmt bran cond sub pod time code
1             package Astro::FITS::HdrTrans::SCUBA2;
2              
3             =head1 NAME
4              
5             Astro::FITS::HdrTrans::SCUBA2 - JCMT SCUBA-2 translations
6              
7             =head1 DESCRIPTION
8              
9             Converts information contained in SCUBA-2 FITS headers to and from
10             generic headers. See L<Astro::FITS::HdrTrans> for a list of generic
11             headers.
12              
13             =cut
14              
15 10     10   42221739 use 5.006;
  10         48  
16 10     10   102 use warnings;
  10         30  
  10         843  
17 10     10   92 use strict;
  10         25  
  10         269  
18 10     10   59 use Carp;
  10         20  
  10         1292  
19              
20 10     10   94 use base qw/ Astro::FITS::HdrTrans::JCMT /;
  10         39  
  10         10086  
21              
22             our $VERSION = "1.66";
23              
24             # For a constant mapping, there is no FITS header, just a generic
25             # header that is constant.
26             my %CONST_MAP = (
27             BACKEND => 'SCUBA-2',
28             DATA_UNITS => 'pW',
29             );
30              
31             # NULL mappings used to override base class implementations
32             my @NULL_MAP = ();
33              
34             # Unit mapping implies that the value propogates directly
35             # to the output with only a keyword name change.
36              
37             my %UNIT_MAP = (
38             FILTER => "FILTER",
39             INSTRUMENT => "INSTRUME",
40             DR_GROUP => "DRGROUP",
41             OBSERVATION_TYPE => "OBS_TYPE",
42             UTDATE => "UTDATE",
43             TELESCOPE => "TELESCOP",
44             AMBIENT_TEMPERATURE => 'ATSTART',
45             );
46              
47             # Values that are derived from the last subheader entry
48             my %ENDOBS_MAP = (
49             AIRMASS_END => 'AMEND',
50             AZIMUTH_END => 'AZEND',
51             ELEVATION_END => 'ELEND',
52             );
53              
54             # Create the translation methods
55             __PACKAGE__->_generate_lookup_methods( \%CONST_MAP, \%UNIT_MAP, \@NULL_MAP, \%ENDOBS_MAP );
56              
57             =head1 METHODS
58              
59             =over 4
60              
61             =item B<this_instrument>
62              
63             The name of the instrument required to match (case insensitively)
64             against the INSTRUME/INSTRUMENT keyword to allow this class to
65             translate the specified headers. Called by the default
66             C<can_translate> method.
67              
68             $inst = $class->this_instrument();
69              
70             Returns "SCUBA-2".
71              
72             =cut
73              
74             sub this_instrument {
75 21     21 1 66 return "SCUBA-2";
76             }
77              
78             =back
79              
80             =head1 COMPLEX CONVERSIONS
81              
82             These methods are more complicated than a simple mapping. We have to
83             provide both from- and to-FITS conversions All these routines are
84             methods and the to_ routines all take a reference to a hash and return
85             the translated value (a many-to-one mapping) The from_ methods take a
86             reference to a generic hash and return a translated hash (sometimes
87             these are many-to-many)
88              
89             =over 4
90              
91             =item B<to_OBSERVATION_MODE>
92              
93             If Observation type is SCIENCE, return the sample mode, else
94             return the sample mode and observation type. For example, "STARE",
95             "SCAN", "SCAN_POINTING".
96              
97             Do not currently take into account polarimeter or FTS.
98              
99             =cut
100              
101             sub to_OBSERVATION_MODE {
102 3     3 1 28 my $self = shift;
103 3         9 my $FITS_headers = shift;
104              
105 3         6 my $return;
106 3 50 33     16 if ( exists( $FITS_headers->{'SAM_MODE'} ) &&
107             exists( $FITS_headers->{'OBS_TYPE'} ) ) {
108 3         178 my $sam_mode = $FITS_headers->{'SAM_MODE'};
109 3         267 $sam_mode =~ s/\s//g;
110 3         14 my $obs_type = $FITS_headers->{'OBS_TYPE'};
111 3         229 $obs_type =~ s/\s//g;
112              
113 3         8 $return = $sam_mode;
114 3 100       17 if ($obs_type !~ /science/i) {
115 2 50       9 if ($obs_type =~ /(setup)/i) {
116 0         0 $return = lc($1);
117             } else {
118 2         5 $return .= "_$obs_type";
119             }
120             }
121             }
122 3         15 return $return;
123             }
124              
125             =item B<to_SUBSYSTEM_IDKEY>
126              
127             =cut
128              
129             sub to_SUBSYSTEM_IDKEY {
130 3     3 1 10 my $self = shift;
131 3         9 my $FITS_headers = shift;
132              
133             # Try the general headers first
134 3         49 my $general = $self->SUPER::to_SUBSYSTEM_IDKEY( $FITS_headers );
135 3 50       17 return ( defined $general ? $general : "FILTER" );
136             }
137              
138             =item B<to_DR_RECIPE>
139              
140             Fix up recipes that were incorrect in the early years of the
141             observing tool.
142              
143             Converts SASSy survey data to use the SASSy recipe.
144              
145             =cut
146              
147             sub to_DR_RECIPE {
148 3     3 1 10 my $class = shift;
149 3         8 my $FITS_headers = shift;
150 3         14 my $dr = $FITS_headers->{RECIPE};
151 3         252 my $survey = $FITS_headers->{SURVEY};
152              
153 3 50 33     224 if (defined $survey && $survey =~ /sassy/i) {
154 0 0       0 if ($dr !~ /sassy/i) {
155 0         0 $dr = "REDUCE_SASSY";
156             }
157             }
158 3         12 return $dr;
159             }
160              
161             =item B<to_POLARIMETER>
162              
163             Determine if POL-2 is in the beam, based on the INBEAM header.
164              
165             =cut
166              
167             sub to_POLARIMETER {
168 3     3 1 9 my $class = shift;
169 3         9 my $FITS_headers = shift;
170              
171 3         14 my $inbeam = $FITS_headers->{'INBEAM'};
172              
173 3 100       252 return 0 unless defined $inbeam;
174              
175 2 50       17 return ($inbeam =~ /\bpol/i) ? 1 : 0;
176             }
177              
178             =item B<from_POLARIMETER>
179              
180             Attempt to recreate the INBEAM header. Since this also
181             depends on FTS-2, use the _reconstruct_INBEAM method.
182              
183             =cut
184              
185             sub from_POLARIMETER {
186 1     1 1 2 my $class = shift;
187 1         1 my $generic_headers = shift;
188              
189 1         4 return $class->_reconstruct_INBEAM($generic_headers);
190             }
191              
192             =item B<to_FOURIER_TRANSFORM_SPECTROMETER>
193              
194             Determine if FTS-2 is in the beam, based on the INBEAM header.
195              
196             =cut
197              
198             sub to_FOURIER_TRANSFORM_SPECTROMETER {
199 3     3 1 9 my $class = shift;
200 3         8 my $FITS_headers = shift;
201              
202 3         13 my $inbeam = $FITS_headers->{'INBEAM'};
203              
204 3 100       225 return 0 unless defined $inbeam;
205              
206 2 50       14 return ($inbeam =~ /\bfts/i) ? 1 : 0;
207             }
208              
209             =item B<from_FOURIER_TRANSFORM_SPECTROMETER>
210              
211             Attempt to recreate the INBEAM header. Since this also
212             depends on POL-2, use the _reconstruct_INBEAM method.
213              
214             =cut
215              
216             sub from_FOURIER_TRANSFORM_SPECTROMETER {
217 1     1 1 2 my $class = shift;
218 1         1 my $generic_headers = shift;
219              
220 1         4 return $class->_reconstruct_INBEAM($generic_headers);
221             }
222              
223              
224             =item B<_reconstruct_INBEAM>
225              
226             Since the INBEAM header becomes multiple generic headers, we need to look at
227             them all to reconstruct it. In order to work within the confines of the
228             Astro::FITS::HdrTrans::Base::translate_to_FITS method, we need to work
229             on a per-generic header basis. This internal method can then be used for
230             the "from_" method for each of these. It will end up returning the same
231             INBEAM header each time -- the versions generated from different generic
232             headers will overwrite eachother in the Base translate_to_FITS method
233             but that shouldn't be a problem.
234              
235             Note that the INBEAM header may not be reconstructed exactly. For example
236             it will just include the short form "pol" even if it would originally have
237             included specific POL-2 components instead.
238              
239             =cut
240              
241             sub _reconstruct_INBEAM {
242 2     2   2 my $class = shift;
243 2         3 my $generic_headers = shift;
244              
245 2         4 my @components;
246              
247 2 50       5 push @components, 'fts2' if $generic_headers->{'FOURIER_TRANSFORM_SPECTROMETER'};
248              
249 2 50       5 push @components, 'pol' if $generic_headers->{'POLARIMETER'};
250              
251 2         2 my $inbeam = undef;
252              
253 2 50       7 $inbeam = join(' ', @components) if scalar @components;
254              
255 2         18 return (INBEAM => $inbeam);
256             }
257              
258             =back
259              
260             =head1 SEE ALSO
261              
262             C<Astro::FITS::HdrTrans>, C<Astro::FITS::HdrTrans::Base>
263              
264             =head1 AUTHOR
265              
266             Tim Jenness E<lt>t.jenness@jach.hawaii.eduE<gt>
267              
268             =head1 COPYRIGHT
269              
270             Copyright (C) 2007-2009,2011,2013 Science & Technology Facilities Council.
271             Copyright (C) 2003-2005 Particle Physics and Astronomy Research Council.
272             All Rights Reserved.
273              
274             This program is free software; you can redistribute it and/or modify it under
275             the terms of the GNU General Public License as published by the Free Software
276             Foundation; either Version 2 of the License, or (at your option) any later
277             version.
278              
279             This program is distributed in the hope that it will be useful,but WITHOUT ANY
280             WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
281             PARTICULAR PURPOSE. See the GNU General Public License for more details.
282              
283             You should have received a copy of the GNU General Public License along with
284             this program; if not, write to the Free Software Foundation, Inc., 59 Temple
285             Place, Suite 330, Boston, MA 02111-1307, USA.
286              
287             =cut
288              
289             1;