blib/lib/Astro/WaveBand.pm

filter: Statementstmt 96.0% 270 / 281 Branchbran 76.8% 126 / 164 Conditioncond 66.6% 28 / 42 MC/DCmcdc 48.1% 13 / 27 Subroutinesub 100% 34 / 34 Podpod 100% 17 / 17 totaltotal 86.3% 488 / 565 CC 111 SCAR 19.4
CC
111
Cov
87%
waveband
13.0
new
12.3
_convert_to
11.1
CRAP 7.0
↑ Summary
1 package Astro::WaveBand;
2  
3 =head1 NAME
4  
5 Astro::WaveBand - Transparently work in waveband, wavelength or filter
6  
7 =head1 SYNOPSIS
8  
9 use Astro::WaveBand;
10  
11 $w = Astro::WaveBand->new(Filter => $filter);
12 $w = Astro::WaveBand->new(Wavelength => $wavelength);
13  
14 $w = Astro::WaveBand->new(
15 Wavelength => $wavelength,
16 Instrument => 'CGS4');
17  
18 $filter = $w->filter;
19 $wave = $w->wavelength;
20 $band = $w->waveband; # radio, xray, submm
21 $freq = $w->frequency;
22 $wnum = $w->wavenumber;
23  
24 $natural = $w->natural;
25 $natural = "$w";
26  
27 $w->natural_unit("wavelength");
28  
29 if ($w1 > $w2) {...}
30 if ($w1 == $w2) {...}
31  
32 =head1 DESCRIPTION
33  
34 Class to transparently deal with the conversion between filters,
35 wavelength, frequency and other methods of specifying a location
36 in the electro-magentic spectrum.
37  
38 The class tries to determine the natural form of the numbers such that
39 a request for a summary of the object when it contains 2.2 microns
40 would return the filter name but would return the wavelength if it was
41 not a standard filter. In ambiguous cases an instrument name is
42 required to decide what to return. In really ambiguous cases the user
43 can specify the unit in which to display the numbers on
44 stringification.
45  
46 Used mainly as a way of storing a single number in a database table
47 but using logic to determine the number that an observer is most likely
48 to understand.
49  
50 Numerical comparison operators can be used to compare two C<Astro::WaveBand>
51 objects. When checking equality, the "natural" and "instrument" methods are
52 used, so if two C<Astro::WaveBand> objects return the same value from those
53 methods, they are considered to be equal. When checking other comparisons
54 such as greater than, the wavelength is used.
55  
56 =cut
57  
58 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
59 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
60 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
61 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
62  
63 # Register an Astro::WaveBand warning category
64 1 ▶use warnings::register;
Subroutine BEGIN: called CC=1 SCAR=0.0
65  
66 # CVS version: $Revision$
67 1 our $VERSION = '0.12';
68  
69 # Overloading
70 use overload
71 1 ▶ '""' => "natural",
Subroutine BEGIN: called CC=1 SCAR=0.0
72 '==' => "equals",
73 '!=' => "not_equals",
74 '<=>' => "compare",
75 1 'fallback' => 1;
76  
77 # Constants
78  
79 # Speed of light in m/s
80 1 ▶use constant CLIGHT => 299792458;
Subroutine BEGIN: called CC=1 SCAR=0.0
81  
82 # list of instruments specific to a telescope
83 1 my %TELESCOPE = (
84 UKIRT => [
85 qw/CGS4 IRCAM UFTI UIST MICHELLE WFCAM/],
86 JCMT => [
87 qw/SCUBA SCUBA-2 RXA3 RXA3M RXB3 RXW RXH3
88 ACSIS DAS HARP ALAIHI UU AWEOWEO
89 KUNTUR/
90 ],
91 );
92  
93 # Continuum Filters are keyed by instrument
94 # although if an instrument is not specified the filters
95 # hash will be searched for a match if none is available in
96 # GENERIC
97 1 my %FILTERS = (
98 GENERIC => {
99 U => 0.365,
100 B => 0.44,
101 V => 0.55,
102 R => 0.70,
103 I => 0.90,
104 J => 1.25,
105 H => 1.65,
106 K => 2.2,
107 L => 3.45,
108 M => 4.7,
109 N => 10.2,
110 Q => 20.0,
111 up => 0.355,
112 gp => 0.470,
113 rp => 0.620,
114 ip => 0.750,
115 zp => 0.880,
116 Pu => 0.355,
117 Pg => 0.470,
118 Pr => 0.620,
119 Pi => 0.750,
120 Pz => 0.880,
121 Y => 1.020, # this will get incorrectly classed as infrared
122 w => 0.608,
123 SO => 0.600,
124 },
125 WFCAM => {
126 "Z" => 0.83,
127 "Y" => 0.97,
128 "J" => 1.17,
129 "H" => 1.49,
130 "K" => 2.03,
131 "1-0S1" => 2.111,
132 "BGamma" => 2.155,
133 "1.205nbJ" => 1.205,
134 "1.619nbH" => 1.619,
135 "1.644FeII" => 1.631,
136 "Blank" => 0,
137 },
138 IRCAM => {
139 "J98" => "1.250",
140 "H98" => "1.635",
141 "K98" => "2.150",
142 "Lp98" => "3.6",
143 "Mp98" => "4.800",
144 "2.1c" => "2.100",
145 "2.122S1" => "2.122",
146 "BrG" => "2.0",
147 "2.2c" => "2.200",
148 "2.248S1" => "2.248",
149 "3.6nbLp" => "3.6",
150 "4.0c" => "4.000",
151 "BrA" => "4.0",
152 "Ice" => "3.1",
153 "Dust" => "3.28",
154 "3.4nbL" => "3.4",
155 "3.5mbL" => "3.5",
156 },
157 UFTI => {
158 "Y_MK" => "1.022",
159 "I" => "0.9",
160 "Z" => "1.033",
161 "J98" => "1.250",
162 "H98" => "1.635",
163 "K98" => "2.150",
164 "Kprime" => "2.120",
165 "1.644" => "1.644",
166 '1.69CH4_l' => '1.690',
167 "1.57" => "1.57",
168 "2.122" => "2.122",
169 "2.122MK" => "2.122",
170 "BrG" => "2.166",
171 "BrGz" => "2.173",
172 "2.248S(1)" => "2.248",
173 "2.27" => "2.270",
174 "Blank" => "-2.222", # -ve version of OT wavelength
175 "Mask" => "-2.32", # ditto
176 },
177 UIST => {
178 # "K-target" => 1.64, # old
179 "Y_MK" => 1.022,
180 "ZMK" => 1.033,
181 "Hartmann" => 1.64,
182 "J98" => 1.25,
183 "H98" => 1.64,
184 "1.57" => 1.573,
185 "1.66" => 1.664, # old
186 "1.58CH4_s" => 1.604,
187 "1.69CH4_l" => 1.674,
188 "1.644Fe" => 1.643,
189 "K98" => 2.20,
190 "Kshort" => 2.159,
191 "Klong" => 2.227,
192 "2.122S(1)" => 2.121,
193 "2.122MK" => 2.127,
194 "2.248S(1)" => 2.248,
195 "2.248MK" => 2.263,
196 "BrG" => 2.166,
197 "2.27" => 2.274,
198 "2.32CO" => 2.324, # old
199 "2.42CO" => 2.425,
200 "3.05ice" => 3.048,
201 "Dust" => 3.278,
202 "3.30PAH" => 3.286,
203 "3.4nbL" => 3.415,
204 "3.5mbL" => 3.489,
205 "3.6nbLp" => 3.593,
206 "3.99" => 3.990,
207 "BrA" => 4.053,
208 "Lp98" => 3.77,
209 "Mp98" => 4.69,
210 },
211 MICHELLE => {
212 "F105B53" => 10.5,
213 "F79B10" => 7.9,
214 "F88B10" => 8.8,
215 "F97B10" => 9.7,
216 "F103B10" => 10.3,
217 "F116B9" => 11.6,
218 "F125B9" => 12.5,
219 "F107B4" => 10.7,
220 "F122B3" => 12.2,
221 "F128B2" => 12.8,
222 "F209B42" => 20.9,
223 "F185B9" => 18.5,
224 "NBlock" => 10.6,
225 "QBlock" => 20.9,
226 "F22B15" => 2.2,
227 "F34B9" => 3.4,
228 "F47B5" => 4.7,
229 },
230 SCUBA => {
231 "850W" => 863,
232 "450W" => 443,
233 "450N" => 442,
234 "850N" => 862,
235 "750N" => 741,
236 "350N" => 344,
237 "P2000" => 2000,
238 "P1350" => 1350,
239 "P1100" => 1100,
240 # This is a kluge until the class can
241 # be extended to support multiple wavelength
242 # instruments.
243 "850S:PHOT" => 1100,
244 "450W:850W" => 443,
245 "450N:850N" => 442,
246 "350N:750N" => 344,
247 },
248 'SCUBA-2' => {
249 850 => 863, # guesses
250 450 => 445,
251 },
252 );
253  
254 # Instruments that have natural units
255 1 my %NATURAL = (
256 WFCAM => 'filter',
257 CGS4 => 'wavelength',
258 SCUBA => 'filter',
259 'SCUBA-2' => 'filter',
260 UFTI => 'filter',
261 IRCAM => 'filter',
262 MICHELLE => 'filter',
263 ACSIS => 'frequency',
264 DAS => 'frequency',
265 RXA3 => 'frequency',
266 RXA3M => 'frequency',
267 RXB3 => 'frequency',
268 RXW => 'frequency',
269 RXWB => 'frequency',
270 RXWC => 'frequency',
271 RXWD => 'frequency',
272 RXWD2 => 'frequency',
273 RXH3 => 'frequency',
274 HARP => 'frequency',
275 ALAIHI => 'frequency',
276 UU => 'frequency',
277 AWEOWEO => 'frequency',
278 KUNTUR => 'frequency',
279 UIST => 'filter',
280 );
281  
282 # Unit prefixes, in descending size order.
283 1 my @PREFIXES = (
284 [Q => 30],
285 [R => 27],
286 [Y => 24],
287 [Z => 21],
288 [E => 18],
289 [P => 15],
290 [T => 12],
291 [G => 9],
292 [M => 6],
293 [k => 3],
294 ['' => 0],
295 [m => -3],
296 [mu => -6],
297 [n => -9],
298 [p => -12],
299 [f => -15],
300 [a => -18],
301 [z => -21],
302 [y => -24],
303 [r => -27],
304 [q => -30],
305 );
306  
307 =head1 METHODS
308  
309 =head2 Constructor
310  
311 =over 4
312  
313 =item B<new>
314  
315 Create a new instance of an C<Astro::WaveBand> object.
316  
317 $w = Astro::WaveBand->new(Filter => $filter);
318  
319 Allowed keys for constructor are one of:
320  
321 Filter - filter name
322 Wavelength - wavelength in microns
323 Frequency - frequency in Hertz
324 Wavenumber - wavenumber in cm^-1
325  
326 plus optionally:
327  
328 Instrument - name of associated instrument
329  
330 In the future there may be a C<Units> key to allow the units to be
331 supplied in alternative forms.
332  
333 If a mandatory key is missing or there is more than one
334 mandatory key the constructor will fail and return C<undef>.
335 Additionally a warning (of class C<Astro::WaveBand>) will
336 be issued.
337  
338 =cut
339  
340 29 ▶sub new {
Subroutine new: called CC=12 SCAR=25.1
Pod documented
341 29 my $proto = shift;
342 29 ▶ my $class = ref($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
0290
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
343  
344 29 my %args = @_;
345  
346 # Check the hash contains one of the following
347 29 my @keys = qw/Filter Wavelength Frequency Wavenumber/;
348 29 my $found = 0;
349 29 for my $key (@keys) {
350 116 ▶ $found++ if exists $args{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{$key} 28 88 116
351 }
352  
353 29 ▶ if ($found == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($found == 0) { } 2 27 29
elsif ($found > 1) { } 1 26 27
354 2 ▶ warnings::warn("Missing a mandatory key")
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 2 2
355 if warnings::enabled();
356 2 return undef;
357 }
358 elsif ($found > 1) {
359 1 ▶ warnings::warn("More than one mandatory key")
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 1 1
360 if warnings::enabled();
361 1 return undef;
362 }
363  
364 26 my $w = bless {Cache => {}}, $class;
365  
366 # Now insert the information into the object
367 # Do Instrument first since we may need it to convert
368 # filter to wavelength
369 26 ▶ if (exists $args{Instrument}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"Instrument"}) 19 7 26
370 19 $w->instrument($args{Instrument});
371 }
372  
373 26 for my $key (keys %args) {
374 47 my $method = lc($key);
375 47 ▶ next if $method eq 'instrument';
Branch: 1 branch
BranchTrueFalseTotal
if $method eq "instrument" 19 28 47
376 28 ▶ if ($w->can($method)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($w->can($method)) 28 0 28
377 28 $w->$method($args{$key});
378 }
379 }
380  
381 # We are now done so just return the object
382 26 return $w;
383 }
384  
385 =back
386  
387 =head2 Accessor methods
388  
389 All the accessor methods associated with conversions will
390 automatically convert to the correct format on demand and will cache
391 it for later. If a new value is provided all caches will be cleared.
392  
393 All input values are converted to microns internally (since a
394 single base unit should be chosen to simplify internal conversions).
395  
396 If a numeric accessor (wavelength, frequency, wavenumber) is called
397 with a hash reference as the first argument then it is interpreted
398 as a set of options. (The filter accessor also accepts an initial
399 hash reference for consistency.) Options can include:
400  
401 =over 4
402  
403 =item format
404  
405 If returning a value, construct a formatted string including the units.
406  
407 =item ndp
408  
409 When returning a string (C<format> is true), round the value to this number
410 of decimal places. If not specified, 3 is used.
411  
412 =back
413  
414 For example:
415  
416 $w->frequency({format => 1})
417  
418 Could return a string such as "345.796 GHz".
419  
420 =over 4
421  
422 =item B<wavelength>
423  
424 Wavelength in microns.
425  
426 $wav = $w->wavelength;
427 $w->wavelength(450.0);
428  
429 =cut
430  
431 55 ▶sub wavelength {
Subroutine wavelength: called CC=6 SCAR=17.9
Pod documented
432 55 my $self = shift;
433 55 ▶ my %opt = %{@_ && 'HASH' eq ref $_[0] ? shift : {}};
Branch: 1 branch
BranchTrueFalseTotal
@_ && 'HASH' eq ref $_[0] ? : 5 50 55
Condition100%3/3
@_ and "HASH" eq ref $_[0]
!ll&&!rl&&r
4285
MC/DC100%2/2
@_ and "HASH" eq ref $_[0]
@_ "HASH" eq ref $_[0]
Truth table100%3/3
A and B
A= @_B= "HASH" eq ref $_[0]
ABresult
0X0
100
111
434  
435 55 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 8 47 55
436 8 my $value = shift;
437 8 $self->_store_in_cache('wavelength' => $value);
438 }
439 else {
440 47 my $value = $self->_fetch_from_cache('wavelength');
441 47 ▶ return $self->_format_with_unit($value * 1e-6, 'm', $opt{'ndp'} // 3) if $opt{'format'};
Branch: 1 branch
BranchTrueFalseTotal
if $opt{"format"} 1 46 47
Condition50%1/2
$opt{"ndp"} // 3
l!l
01
MC/DC0%0/1
$opt{"ndp"} // 3
$opt{"ndp"}
Truth table50%1/2
A
A= $opt{"ndp"}
Aresult
11
00
442 46 return $value;
443 }
444 8 return;
445 }
446  
447 =item B<frequency>
448  
449 Frequency in Hertz.
450  
451 $frequency = $w->frequency;
452 $w->frequency(345E9);
453  
454 =cut
455  
456 13 ▶sub frequency {
Subroutine frequency: called CC=6 SCAR=17.9
Pod documented
457 13 my $self = shift;
458 13 ▶ my %opt = %{@_ && 'HASH' eq ref $_[0] ? shift : {}};
Branch: 1 branch
BranchTrueFalseTotal
@_ && 'HASH' eq ref $_[0] ? : 5 8 13
Condition100%3/3
@_ and "HASH" eq ref $_[0]
!ll&&!rl&&r
355
MC/DC100%2/2
@_ and "HASH" eq ref $_[0]
@_ "HASH" eq ref $_[0]
Truth table100%3/3
A and B
A= @_B= "HASH" eq ref $_[0]
ABresult
0X0
100
111
459  
460 13 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 5 8 13
461 5 my $value = shift;
462  
463 # store value and wavelength in cache
464 5 $self->_cache_value_and_wav('frequency', $value);
465 }
466 else {
467 # Read value from the cache
468 8 my $value = $self->_read_value_with_convert("frequency");
469 8 ▶ return $self->_format_with_unit($value, 'Hz', $opt{'ndp'} // 3) if $opt{'format'};
Branch: 1 branch
BranchTrueFalseTotal
if $opt{"format"} 3 5 8
Condition100%2/2
$opt{"ndp"} // 3
l!l
21
MC/DC100%1/1
$opt{"ndp"} // 3
$opt{"ndp"}
Truth table100%2/2
A
A= $opt{"ndp"}
Aresult
11
00
470 5 return $value;
471 }
472  
473 5 return;
474 }
475  
476 =item B<wavenumber>
477  
478 Wavenumber (reciprocal of wavelength) in inverse centimetres.
479  
480 $value = $w->wavenumber;
481 $w->wavenumber(1500);
482  
483 =cut
484  
485 12 ▶sub wavenumber {
Subroutine wavenumber: called CC=6 SCAR=17.9
Pod documented
486 12 my $self = shift;
487 12 ▶ my %opt = %{@_ && 'HASH' eq ref $_[0] ? shift : {}};
Branch: 1 branch
BranchTrueFalseTotal
@_ && 'HASH' eq ref $_[0] ? : 1 11 12
Condition100%3/3
@_ and "HASH" eq ref $_[0]
!ll&&!rl&&r
1011
MC/DC100%2/2
@_ and "HASH" eq ref $_[0]
@_ "HASH" eq ref $_[0]
Truth table100%3/3
A and B
A= @_B= "HASH" eq ref $_[0]
ABresult
0X0
100
111
488  
489 12 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 1 11 12
490 1 my $value = shift;
491  
492 # store value and wavelength in cache
493 1 $self->_cache_value_and_wav('wavenumber', $value);
494 }
495 else {
496 # Read value from the cache
497 11 my $value = $self->_read_value_with_convert("wavenumber");
498 11 ▶ return $self->_format_fixed_unit($value, '/cm', $opt{'ndp'} // 3) if $opt{'format'};
Branch: 1 branch
BranchTrueFalseTotal
if $opt{"format"} 1 10 11
Condition50%1/2
$opt{"ndp"} // 3
l!l
01
MC/DC0%0/1
$opt{"ndp"} // 3
$opt{"ndp"}
Truth table50%1/2
A
A= $opt{"ndp"}
Aresult
11
00
499 10 return $value;
500 }
501  
502 1 return;
503 }
504  
505 =item B<filter>
506  
507 Set or retrieve filter name.
508  
509 Returns C<undef> if the filter can not be determined. If the filter
510 name can not be translated to a wavelength it will not be possible
511 to do any conversions to other forms.
512  
513 =cut
514  
515 55 ▶sub filter {
Subroutine filter: called CC=4 SCAR=13.9
Pod documented
516 55 my $self = shift;
517 55 ▶ my %opt = %{@_ && 'HASH' eq ref $_[0] ? shift : {}};
Branch: 1 branch
BranchTrueFalseTotal
@_ && 'HASH' eq ref $_[0] ? : 23 32 55
Condition100%3/3
@_ and "HASH" eq ref $_[0]
!ll&&!rl&&r
191323
MC/DC100%2/2
@_ and "HASH" eq ref $_[0]
@_ "HASH" eq ref $_[0]
Truth table100%3/3
A and B
A= @_B= "HASH" eq ref $_[0]
ABresult
0X0
100
111
518  
519 55 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 13 42 55
520 13 my $value = shift;
521  
522 # store value and wavelength in cache
523 13 $self->_cache_value_and_wav('filter', $value);
524 }
525 else {
526 # Read value from the cache
527 42 return $self->_read_value_with_convert("filter");
528 }
529  
530 13 return;
531 }
532  
533 =item B<instrument>
534  
535 Name of associated instrument.
536  
537 $inst = $w->instrument;
538 $w->instrument('SCUBA');
539  
540 Used to aid in the choice of natural unit.
541  
542 =cut
543  
544 83 ▶sub instrument {
Subroutine instrument: called CC=2 SCAR=6.9
Pod documented
545 83 my $self = shift;
546 83 ▶ if (@_) {$self->{Instrument} = uc(shift);}
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 19 64 83
547 83 return $self->{Instrument};
548 }
549  
550 =item B<natural_unit>
551  
552 Override the natural unit to be used for stringification. If this
553 value is not set the class will determine the unit of choice by
554 looking at the instrument name and then by taking an informed guess.
555  
556 $w->natural_unit('filter');
557  
558 =cut
559  
560 27 ▶sub natural_unit {
Subroutine natural_unit: called CC=2 SCAR=7.6
Pod documented
561 27 my $self = shift;
562 0 ▶ if (@_) {$self->{NaturalUnit} = shift;}
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 27 27
563 27 return $self->{NaturalUnit};
564 }
565  
566 =item B<species>
567  
568 Name of species involved in an emission line.
569  
570 =cut
571  
572 4 ▶sub species {
Subroutine species: called CC=2 SCAR=6.9
Pod documented
573 4 my $self = shift;
574 4 ▶ if (@_) {$self->{'Species'} = shift;}
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2 2 4
575 4 return $self->{'Species'};
576 }
577  
578 =item B<transition>
579  
580 Transition giving rise to line emission.
581  
582 =cut
583  
584 4 ▶sub transition {
Subroutine transition: called CC=2 SCAR=6.9
Pod documented
585 4 my $self = shift;
586 4 ▶ if (@_) {$self->{'Transition'} = shift;}
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2 2 4
587 4 return $self->{'Transition'};
588 }
589  
590 =back
591  
592 =head2 General Methods
593  
594 =over 4
595  
596 =item B<waveband>
597  
598 Return the name of the waveband associated with the object.
599  
600 Returns C<undef> if none can be determined.
601  
602 $band = $w->waveband;
603  
604 =cut
605  
606 19 ▶sub waveband {
Subroutine waveband: called CC=9 SCAR=25.6
Pod documented
607 19 my $self = shift;
608  
609 19 my $lambda = $self->wavelength;
610 19 ▶ return undef unless defined $lambda;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $lambda 0 19 19
611  
612 19 my $band;
613 19 ▶ if ($lambda >= 10000) { # > 1cm
Branch: 7 branches
BranchTrueFalseTotal
if ($lambda >= 10000) { } 1 18 19
elsif ($lambda >= 1000) { } 0 18 18
elsif ($lambda >= 100) { } 3 15 18
elsif ($lambda >= 1) { } 11 4 15
elsif ($lambda >= 0.3) { } 4 0 4
elsif ($lambda >= 0.01) { } 0 0 0
elsif ($lambda >= 1e-05) { } 0 0 0
614 1 $band = 'radio';
615 }
616 elsif ($lambda >= 1000) {
617 0 $band = 'mm';
618 }
619 elsif ($lambda >= 100) {
620 3 $band = 'submm';
621 }
622 elsif ($lambda >= 1) {
623 11 $band = 'infrared';
624 }
625 elsif ($lambda >= 0.3) {
626 4 $band = 'optical';
627 }
628 elsif ($lambda >= 0.01) {
629 0 $band = 'ultraviolet';
630 }
631 elsif ($lambda >= 0.00001) {
632 0 $band = 'x-ray';
633 }
634 else {
635 0 $band = 'gamma-ray';
636 }
637  
638 19 return $band;
639 }
640  
641 =item B<natural>
642  
643 Return the contents of the object in its most natural form. For
644 example, with UFTI the filter name will be returned whereas with ACSIS
645 the frequency will be returned. The choice of unit is chosen using
646 the supplied default unit (see C<natural_unit>) or the instrument name.
647 If none of these is specified filter will be used and if no match is
648 present wavelength in microns.
649  
650 $value = $w->natural;
651  
652 Returns C<undef> if the value can not be determined.
653  
654 This method is called automatically when the object is stringified.
655 Note that you will not know the unit that was chosen a priori.
656  
657 If a hash reference (containing formatting options) is given
658 then it is passed to the relevant accessor method.
659  
660 =cut
661  
662 27 ▶sub natural {
Subroutine natural: called CC=9 SCAR=22.1
Pod documented
663 27 my $self = shift;
664 27 ▶ my %opt = %{@_ && 'HASH' eq ref $_[0] ? shift : {}};
Branch: 1 branch
BranchTrueFalseTotal
@_ && 'HASH' eq ref $_[0] ? : 1 26 27
Condition66%2/3
@_ and "HASH" eq ref $_[0]
!ll&&!rl&&r
2601
MC/DC50%1/2
@_ and "HASH" eq ref $_[0]
@_ "HASH" eq ref $_[0]
Truth table66%2/3
A and B
A= @_B= "HASH" eq ref $_[0]
ABresult
0X0
100
111
665  
666 # First see if the default unit is set
667 27 my $unit = $self->natural_unit;
668  
669 27 ▶ unless (defined $unit) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $unit) 27 0 27
670 # Check the instrument
671 27 my $inst = $self->instrument;
672 27 ▶ if ($inst and exists $NATURAL{$inst}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inst and exists $NATURAL{$inst}) 19 8 27
Condition66%2/3
$inst and exists $NATURAL{$inst}
!ll&&!rl&&r
8019
MC/DC50%1/2
$inst and exists $NATURAL{$inst}
$inst exists $NATURAL{$inst}
Truth table66%2/3
A and B
A= $instB= exists $NATURAL{$inst}
ABresult
0X0
100
111
673 19 $unit = $NATURAL{$inst};
674 }
675 }
676  
677 # Guess at filter if we have no choice
678 27 ▶ $unit = 'filter' unless defined $unit;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $unit 8 19 27
679  
680 # retrieve the value
681 27 my $value;
682 27 ▶ if ($self->can($unit)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can($unit)) 27 0 27
683 27 $value = $self->$unit(\%opt);
684 }
685  
686 # All else fails... try wavelength
687 27 ▶ $value = $self->wavelength(\%opt) unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 3 24 27
688  
689 27 return $value;
690 }
691  
692 =item B<compare>
693  
694 Compares two C<Astro::WaveBand> objects.
695  
696 if ($wb1->compare($wb2)) {...}
697  
698 This method will return -1 if, in the above example, $wb1 is of
699 a shorter wavelength than $wb2, 0 if the wavelengths are equal,
700 and +1 if $wb1 is of a longer wavelength than $wb2. Please note
701 that for strict waveband equality the C<equals> method should be
702 used, as that method uses the C<natural> method to check if two
703 wavebands are identical.
704  
705 This method is overloaded with the standard numerical comparison
706 operators, so to check if one waveband is shorter than another
707 you would do
708  
709 if ($wb1 < $wb2) {...}
710  
711 and it will work as you expect. This method does not overload
712 the == operator; see the C<equals> method for that.
713  
714 =cut
715  
716 2 ▶sub compare {
Subroutine compare: called CC=2 SCAR=7.1
Pod documented
717 2 my ($object1, $object2, $was_reversed) = @_;
718 2 ▶ ($object1, $object2) = ($object2, $object1) if $was_reversed;
Branch: 1 branch
BranchTrueFalseTotal
if $was_reversed 0 2 2
719  
720 2 return $object1->wavelength <=> $object2->wavelength;
721 }
722  
723 =item B<equals>
724  
725 Compares two C<Astro::WaveBand> objects for equality.
726  
727 if ($wb1->equals($wb2)) {...}
728  
729 This method will return 1 if, in the above example, both
730 C<Astro::WaveBand> objects return the same value from the
731 C<natural> method AND for the C<instrument> method (if it
732 is defined for both objects) , and 0 of they return different values.
733  
734 This method is overloaded using the == operator, so
735  
736 if ($wb1 == $wb2) {...}
737  
738 is functionally the same as the first example.
739  
740 =cut
741  
742 3 ▶sub equals {
Subroutine equals: called CC=4 SCAR=14.3
Pod documented
743 3 my $self = shift;
744 3 my $comp = shift;
745  
746 3 ▶ if (defined($self->instrument) && defined($comp->instrument)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->instrument and defined $comp->instrument) { } 1 2 3
Condition66%2/3
defined $self->instrument and defined $comp->instrument
!ll&&!rl&&r
201
MC/DC50%1/2
defined $self->instrument and defined $comp->instrument
defined $self->instrument defined $comp->instrument
Truth table66%2/3
A and B
A= defined $self->instrumentB= defined $comp->instrument
ABresult
0X0
100
111
747 1 ▶ return (($self->natural eq $comp->natural)
Condition33%1/3
$self->natural eq $comp->natural && $self->instrument eq $comp->instrument
!ll&&!rl&&r
010
MC/DC0%0/2
$self->natural eq $comp->natural && $self->instrument eq $comp->instrument
$self->natural eq $comp->natural $self->instrument eq $comp->instrument
Truth table33%1/3
A && B
A= $self->natural eq $comp->naturalB= $self->instrument eq $comp->instrument
ABresult
0X0
100
111
748 && ($self->instrument eq $comp->instrument));
749 }
750 else {
751 2 return ($self->natural eq $comp->natural);
752 }
753 }
754  
755 =item B<not_equals>
756  
757 Compares two C<Astro::WaveBand> objects for inequality.
758  
759 if ($wb1->not_equals($wb2)) {...}
760  
761 This method will return 1 if, in the above example, either the
762 C<natural> method or the C<instrument> method return different
763 values. If the instrument is undefined for either object, then
764 the C<natural> method will be used.
765  
766 This method is overloaded using the != operator, so
767  
768 if ($wb1 != $wb2) {...}
769  
770 is functionally the same as the first example.
771  
772 =cut
773  
774 1 ▶sub not_equals {
Subroutine not_equals: called CC=4 SCAR=17.2
Pod documented
775 1 my $self = shift;
776 1 my $comp = shift;
777  
778 1 ▶ if (!defined($self->instrument) || !defined($comp->instrument)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->instrument && defined $comp->instrument) { } 0 1 1
Condition33%1/3
defined $self->instrument && defined $comp->instrument
!ll&&!rl&&r
001
MC/DC0%0/2
defined $self->instrument && defined $comp->instrument
defined $self->instrument defined $comp->instrument
Truth table33%1/3
A && B
A= defined $self->instrumentB= defined $comp->instrument
ABresult
0X0
100
111
779 0 return ($self->natural ne $comp->natural);
780 }
781 else {
782 1 ▶ return (($self->natural ne $comp->natural)
Condition33%1/3
$self->natural ne $comp->natural || $self->instrument ne $comp->instrument
l!l&&r!l&&!r
010
MC/DC0%0/2
$self->natural ne $comp->natural || $self->instrument ne $comp->instrument
$self->natural ne $comp->natural $self->instrument ne $comp->instrument
Truth table33%1/3
A || B
A= $self->natural ne $comp->naturalB= $self->instrument ne $comp->instrument
ABresult
1X1
011
000
783 || ($self->instrument ne $comp->instrument));
784 }
785 }
786  
787 =back
788  
789 =begin __PRIVATE_METHODS__
790  
791 =head2 Private Methods
792  
793 =over 4
794  
795 =item B<_cache>
796  
797 Retrieve the hash reference associated with the cache (in a scalar
798 context) or the contents of the hash (in a list context).
799  
800 $ref = $w->cache;
801 %cache = $w->cache;
802  
803 =cut
804  
805 179 ▶sub _cache {
Subroutine _cache: called CC=2 SCAR=8.4
806 179 my $self = shift;
807 179 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 179 179
808 0 return %{$self->{Cache}};
809 }
810 else {
811 179 return $self->{Cache};
812 }
813 }
814  
815 =item B<_store_in_cache>
816  
817 Store values in the cache associated with particular types.
818  
819 $w->_store_in_cache(
820 "filter" => "K",
821 "frequency" => 1.4E14);
822  
823 If the cache already contains a value for this entry the cache
824 is cleared prior to storing it (unless it contains the same value)
825 on the assumption that the cache is no longer consistent.
826  
827 More than one key can be supplied. All keys are tested for prior
828 existence before inserting the new ones.
829  
830 =cut
831  
832 44 ▶sub _store_in_cache {
Subroutine _store_in_cache: called CC=7 SCAR=20.4
833 44 my $self = shift;
834 44 my %entries = @_;
835  
836 # Get the cache
837 44 my $cache = $self->_cache;
838  
839 # First check to see whether we have any entries in the
840 # cache that clash
841 44 for my $key (keys %entries) {
842 # No worries if it is not there
843 62 ▶ next unless exists $cache->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $cache->{$key} 61 1 62
844  
845 # Check to see if the value is the same as is already present
846 # Use a string comparison for filter
847 1 ▶ if ($key eq 'filter') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq 'filter') { } 0 1 1
848 0 ▶ next if $cache->{$key} eq $entries{$key};
Branch: 1 branch
BranchTrueFalseTotal
if $cache->{$key} eq $entries{$key} 0 0 0
849 }
850 else {
851 # Number
852 1 ▶ next if $cache->{$key} == $entries{$key};
Branch: 1 branch
BranchTrueFalseTotal
if $cache->{$key} == $entries{$key} 0 1 1
853 }
854  
855 # Now we have a key that exists but its value is
856 # different. Clear the cache and exit the loop.
857 # This means the loop never really reaches the end
858 # of the block...
859 1 $self->_clear_cache;
860  
861 1 last;
862 }
863  
864 # Now insert the values
865 44 for my $key (keys %entries) {
866 63 $cache->{$key} = $entries{$key};
867 }
868  
869 # finished
870 44 return;
871 }
872  
873 =item B<_clear_cache>
874  
875 Empty the cache.
876  
877 =cut
878  
879 1 ▶sub _clear_cache {
Subroutine _clear_cache: called CC=1 SCAR=0.0
880 1 my $self = shift;
881 1 %{$self->_cache} = ();
882 1 return;
883 }
884  
885 =item B<_fetch_from_cache>
886  
887 Retrieve an item from the cache. Returns C<undef> if the item is
888 not stored in the cache.
889  
890 $filter = $w->_fetch_from_cache("filter");
891  
892 Could be combined into a single method with C<_store_in_cache> but
893 separated for simplicity.
894  
895 =cut
896  
897 134 ▶sub _fetch_from_cache {
Subroutine _fetch_from_cache: called CC=4 SCAR=14.0
898 134 my $self = shift;
899 134 ▶ return undef unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 134 134
900  
901 134 my $key = shift;
902 134 ▶ return undef unless $key;
Branch: 1 branch
BranchTrueFalseTotal
unless $key 0 134 134
903 134 $key = lc($key); # level playing field
904  
905 # Return the value from the cache if it exists
906 134 my $cache = $self->_cache;
907 134 ▶ return $cache->{$key} if exists $cache->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $cache->{$key} 108 26 134
908  
909 26 return undef;
910 }
911  
912 =item B<_cache_value_and_wav>
913  
914 Cache the supplied value, converting it to the internal format
915 if necessary.
916  
917 $w->_cache_value_and_wav('frequency', $frequency);
918  
919 If the wavelength can not be determind the cache is cleared
920 and the supplied value is inserted (but without wavelength
921 information)..
922  
923 =cut
924  
925 19 ▶sub _cache_value_and_wav {
Subroutine _cache_value_and_wav: called CC=4 SCAR=14.1
926 19 my $self = shift;
927  
928 19 my $category = shift;
929 19 my $value = shift;
930 19 ▶ return unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 19 19
931  
932 # Convert to the internal format (wavelength)
933 19 my $internal = $self->_convert_from($category, $value);
934  
935 # Store all defined values into cache
936 19 my %store;
937 19 $store{$category} = $value;
938 19 ▶ $store{wavelength} = $internal if defined $internal;
Branch: 1 branch
BranchTrueFalseTotal
if defined $internal 19 0 19
939  
940 # Clear cache if wavelength is not to be supplied
941 19 ▶ $self->_clear_cache() unless defined $internal;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $internal 0 19 19
942  
943 19 $self->_store_in_cache(%store);
944  
945 19 return;
946 }
947  
948 =item B<_read_value_with_convert>
949  
950 Read a value from the cache, converting it to the required units
951 as necessary.
952  
953 $value = $w->_read_value_with_convert('frequency');
954  
955 Returns C<undef> if no value has been stored in the object.
956  
957 =cut
958  
959 61 ▶sub _read_value_with_convert {
Subroutine _read_value_with_convert: called CC=3 SCAR=11.0
960 61 my $self = shift;
961 61 my $category = lc(shift);
962  
963 61 my $value = $self->_fetch_from_cache($category);
964  
965 # Convert it if necessary
966 61 ▶ unless ($value) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($value) 26 35 61
967 # Convert it from the default value (if set)
968 26 $value = $self->_convert_to($category);
969  
970 # Cache it if necessary
971 26 ▶ $self->_store_in_cache($category => $value)
Branch: 1 branch
BranchTrueFalseTotal
if $value 17 9 26
972 if $value;
973 }
974  
975 61 return $value;
976 }
977  
978 =item B<_convert_to>
979  
980 Convert the value stored internally as the default format to the
981 required format. This simplifies the conversion routines since
982 there is only a single format to convert from and to.
983  
984 $value = $w->_convert_to('frequency');
985  
986 Returns the converted value or undef on error. The internal format
987 (wavelength) is read directly from the cache.
988  
989 =cut
990  
991 26 ▶sub _convert_to {
Subroutine _convert_to: called CC=11 SCAR=24.1
992 26 my $self = shift;
993 26 my $category = shift;
994  
995 26 my $lambda = $self->_fetch_from_cache('wavelength');
996 26 ▶ return undef unless defined $lambda;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $lambda 0 26 26
997  
998 # Check all types
999 26 my $output;
1000 26 ▶ if ($category eq 'wavelength') {
Branch: 4 branches
BranchTrueFalseTotal
if ($category eq 'wavelength') { } 0 26 26
elsif ($category eq 'frequency') { } 2 24 26
elsif ($category eq 'wavenumber') { } 10 14 24
elsif ($category eq 'filter') { } 14 0 14
1001 0 $output = $lambda;
1002 }
1003 elsif ($category eq 'frequency') {
1004 # Microns
1005 2 $output = CLIGHT / ($lambda * 1.0E-6);
1006 }
1007 elsif ($category eq 'wavenumber') {
1008 # Inverse cm
1009 10 $output = 1.0 / ($lambda / 10_000);
1010 }
1011 elsif ($category eq 'filter') {
1012 # This is slightly harder since we know the value but
1013 # not the key. Go through each hash looking for a matching
1014 # key. If we know the instrument we start looking there
1015 # Else we have to look through GENERIC followed by all the
1016 # remaining instruments
1017  
1018 14 my $instrument = $self->instrument;
1019 14 my @search = ('GENERIC', keys %FILTERS);
1020 14 ▶ unshift(@search, $instrument) if defined $instrument;
Branch: 1 branch
BranchTrueFalseTotal
if defined $instrument 9 5 14
1021  
1022 # There will be a precision issue here so we convert
1023 # the base wavelegnth to use 8 significant figures
1024 14 $lambda = sprintf("%8e", $lambda);
1025  
1026 14 OUTER: foreach my $inst (@search) {
1027 91 ▶ next unless exists $FILTERS{$inst};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $FILTERS{$inst} 3 88 91
1028 88 my $hash = $FILTERS{$inst};
1029 88 for my $key (keys %{$hash}) {
1030 # Make sure we use the same rounding scheme on the values
1031 # returned from the hash, so we don't have to worry about
1032 # rounding issues fouling things up (like saying 8.3e-1 !=
1033 # 0.83).
1034 1503 ▶ if (sprintf("%8e", $hash->{$key}) eq $lambda) {
Branch: 1 branch
BranchTrueFalseTotal
if (sprintf("%8e", $hash->{$key}) eq $lambda) 5 1498 1503
1035 5 $output = $key;
1036 5 last OUTER;
1037 }
1038 }
1039 }
1040 }
1041  
1042 26 return $output;
1043 }
1044  
1045 =item B<_convert_from>
1046  
1047 Convert from the supplied values to the internal format (wavelength).
1048  
1049 $value = $w->_convert_from('frequency', $frequency);
1050  
1051 Returns the converted value. Returns C<undef> if the conversion
1052 is not possible.
1053  
1054 =cut
1055  
1056 19 ▶sub _convert_from {
Subroutine _convert_from: called CC=10 SCAR=23.6
1057 19 my $self = shift;
1058  
1059 19 my $category = lc(shift);
1060 19 my $value = shift;
1061 19 ▶ return undef unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 19 19
1062  
1063 # Go through each type
1064 19 my $output;
1065 19 ▶ if ($category eq 'wavelength') {
Branch: 4 branches
BranchTrueFalseTotal
if ($category eq 'wavelength') { } 0 19 19
elsif ($category eq 'frequency') { } 5 14 19
elsif ($category eq 'wavenumber') { } 1 13 14
elsif ($category eq 'filter') { } 13 0 13
1066 0 $output = $value;
1067 }
1068 elsif ($category eq 'frequency') {
1069 # Convert frequency to wavelength
1070 # converting from metres to microns
1071 5 $output = CLIGHT / ($value * 1.0E-6);
1072  
1073 }
1074 elsif ($category eq 'wavenumber') {
1075 # 1 / cm then convert cm to microns
1076 1 $output = (1.0 / $value) * 10_000;
1077 }
1078 elsif ($category eq 'filter') {
1079 # Convert filter to wavelength
1080 # Need to walk through %FILTERS first for a
1081 # instrument match and then for a generic match
1082 13 my $instrument = $self->instrument;
1083 13 my @search = ('GENERIC');
1084 13 ▶ unshift(@search, $instrument) if defined $instrument;
Branch: 1 branch
BranchTrueFalseTotal
if defined $instrument 9 4 13
1085  
1086 13 foreach my $name (@search) {
1087 # First look for a match in %FILTERS
1088 13 ▶ if (exists $FILTERS{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $FILTERS{$name}) 13 0 13
1089 # Now look for the filter itself
1090 13 ▶ if (exists $FILTERS{$name}{$value}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $FILTERS{$name}{$value}) 13 0 13
1091 13 $output = $FILTERS{$name}{$value};
1092 13 last;
1093 }
1094 }
1095 }
1096 }
1097  
1098 19 return $output;
1099 }
1100  
1101 =item B<_format_with_unit>
1102  
1103 Format a numeric value by selecting an appropriate unit
1104 prefix. The number is then returned formatted to the given
1105 number of decimal places followed by a space and then
1106 the combined unit string.
1107  
1108 =cut
1109  
1110 4 ▶sub _format_with_unit {
Subroutine _format_with_unit: called CC=6 SCAR=18.0
1111 4 my $self = shift;
1112 4 my $value = shift;
1113 4 my $baseunit = shift;
1114 4 my $ndp = shift;
1115  
1116 4 ▶ return '' unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 4 4
1117  
1118 4 my $range = log($value) / log(10);
1119 4 my ($unit, $prefrange);
1120 4 foreach my $pr (@PREFIXES) {
1121 37 ($unit, $prefrange) = @$pr;
1122 37 ▶ if ($range >= $prefrange) {
Branch: 1 branch
BranchTrueFalseTotal
if ($range >= $prefrange) 4 33 37
1123 4 last;
1124 }
1125 }
1126  
1127 # Special case: show microns as just "mu"?
1128 4 ▶ $unit .= $baseunit unless $unit eq 'mu' and $baseunit eq 'm';
Branch: 1 branch
BranchTrueFalseTotal
unless $unit eq "mu" and $baseunit eq "m" 3 1 4
Condition66%2/3
$unit eq "mu" and $baseunit eq "m"
!ll&&!rl&&r
301
MC/DC50%1/2
$unit eq "mu" and $baseunit eq "m"
$unit eq "mu" $baseunit eq "m"
Truth table66%2/3
A and B
A= $unit eq "mu"B= $baseunit eq "m"
ABresult
0X0
100
111
1129  
1130 4 return sprintf '%.*f %s', $ndp, ($value / 10 ** $prefrange), $unit;
1131 }
1132  
1133 =item B<_format_fixed_unit>
1134  
1135 Method to format a value in the same way as C<_format_with_unit>
1136 but applying a fixed unit string. (I.e. no automatic prefix.)
1137  
1138 Note: since this is currently only used with '/cm' for wavenumber,
1139 no space is included between the value and unit string.
1140  
1141 =cut
1142  
1143 1 ▶sub _format_fixed_unit {
Subroutine _format_fixed_unit: called CC=2 SCAR=7.0
1144 1 my $self = shift;
1145 1 my $value = shift;
1146 1 my $unit = shift;
1147 1 my $ndp = shift;
1148  
1149 1 ▶ return '' unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 1 1
1150  
1151 1 return sprintf '%.*f%s', $ndp, $value, $unit;
1152 }
1153  
1154 =back
1155  
1156 =end __PRIVATE_METHODS__
1157  
1158 =head2 Static functions
1159  
1160 These functions enable the user to obtain an overview of
1161 the supported filter, instrument and telescope combinations.
1162  
1163 =over 4
1164  
1165 =item B<has_filter>
1166  
1167 Returns true if the a particular instrument has a particular filter,
1168 otherwise returns C<undef>, e.g.
1169  
1170 if (Astro::WaveBand::has_filter(UIST => "Kprime")) {
1171 ...
1172 }
1173  
1174 if you pass a hash containing multiple instrument combinations,
1175 all must be valid or the method will return undef.
1176  
1177 =cut
1178  
1179 4 ▶sub has_filter {
Subroutine has_filter: called CC=5 SCAR=16.1
Pod documented
1180 4 ▶ return undef unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 4 4
1181  
1182 # grab instrument and filter list
1183 4 my %list = @_;
1184  
1185 4 my $counter = 0;
1186 4 foreach my $key (sort keys %list) {
1187 # if the filter exists in the filter list for that instrument,
1188 # increment the counter
1189 6 ▶ $counter++ if exists $FILTERS{$key}{$list{$key}};
Branch: 1 branch
BranchTrueFalseTotal
if exists $FILTERS{$key}{$list{$key}} 4 2 6
1190 }
1191  
1192 # if the counter is the same size as the input list then all conditons
1193 # have been proved to be true...
1194 4 ▶ return undef unless scalar(keys %list) == $counter;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar keys %list == $counter 2 2 4
1195 2 return 1;
1196 }
1197  
1198 =item B<has_instrument>
1199  
1200 Returns true if the a particular instrument exists for a particular
1201 telescope, otherwise returns C<undef>, e.g.
1202  
1203 if (Astro::WaveBand::has_instrument(UKIRT => "UIST")) {
1204 ...
1205 }
1206  
1207 if you pass a hash containing multiple instrument combinations,
1208 all must be valid or the method will return undef.
1209  
1210 =cut
1211  
1212 2 ▶sub has_instrument {
Subroutine has_instrument: called CC=6 SCAR=17.9
Pod documented
1213 2 ▶ return undef unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 2 2
1214  
1215 # grab instrument and filter list
1216 2 my %list = @_;
1217  
1218 2 my $counter = 0;
1219 2 foreach my $key (sort keys %list) {
1220 # if the filter exists in the filter list for that instrument,
1221 # increment the counter
1222 2 for my $i (0 ... $#{$TELESCOPE{$key}}) {
1223 10 ▶ if ($TELESCOPE{$key}->[$i] eq $list{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($TELESCOPE{$key}[$i] eq $list{$key}) 1 9 10
1224 1 $counter++;
1225 1 last;
1226 }
1227 }
1228 }
1229  
1230 # if the counter is the same size as the input list then all conditons
1231 # have been proved to be true...
1232 2 ▶ return undef unless scalar(keys %list) == $counter;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar keys %list == $counter 1 1 2
1233 1 return 1;
1234 }
1235  
1236  
1237 =item B<is_observable>
1238  
1239 Returns true if the a particular telescope and filter combination is
1240 avaialable, otherwise returns C<undef>, e.g.
1241  
1242 if (Astro::WaveBand::is_observable(UKIRT => 'Kprime')) {
1243 ...
1244 }
1245  
1246 =cut
1247  
1248 3 ▶sub is_observable {
Subroutine is_observable: called CC=6 SCAR=17.9
Pod documented
1249  
1250 #my $self = shift;
1251 3 ▶ return undef unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 3 3
1252  
1253 # grab instrument and filter list
1254 3 my %list = @_;
1255  
1256 3 my $counter = 0;
1257 3 foreach my $key (sort keys %list) {
1258 # if the filter exists in the filter list for that instrument,
1259 # increment the counter
1260 #print "TELESCOPE $key\n";
1261 3 for my $i (0 ... $#{$TELESCOPE{$key}}) {
1262 #print " INSTRUMENT ${$TELESCOPE{$key}}[$i]\n";
1263 #print " \$list{\$key} = $list{$key}\n";
1264 10 my $instrument = ${$TELESCOPE{$key}}[$i];
1265  
1266 10 ▶ if (${$FILTERS{$instrument}}{$list{$key}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (${$FILTERS{$instrument};}{$list{$key}}) 2 8 10
1267 2 $counter++;
1268 #print "$counter: $key\n";
1269 #print " $list{$key}, $instrument, $list{$key}, ".
1270 # "${$FILTERS{${$TELESCOPE{$key}}[$i]}}{$list{$key}}\n";
1271 2 last;
1272 }
1273 }
1274 }
1275  
1276 # if the counter is the same size as the input list then all conditons
1277 # have been proved to be true...
1278 3 ▶ return undef unless scalar(keys %list) == $counter;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar keys %list == $counter 1 2 3
1279 2 return 1;
1280 }
1281  
1282 =back
1283  
1284 =head1 BUGS
1285  
1286 Does not automatically convert metres to microns and GHz to Hz etc.
1287  
1288 Can not handle filters that correspond to multiple wavelengths.
1289 Currently SCUBA is the main issue. With a 450:850 filter this class
1290 always returns the shortest wavelength (since that is the wavelength
1291 that affects scheduling the most).
1292  
1293 Should handle velocities and redshifts in order to disambiguate rest
1294 frequencies and observed frequencies. Would also be nice if the class
1295 used the species and transition to allow the natural unit
1296 to appear as something like: "CO 3-2 @ 30km/s LSR radio".
1297  
1298 =head1 AUTHORS
1299  
1300 Tim Jenness E<lt>t.jenness@jach.hawaii.eduE<gt>
1301 Alasdair Allan E<lt>aa@astro.ex.ac.ukE<gt>
1302 Tim Lister E<lt>tlister@lcogt.netE<gt>
1303  
1304 =head1 COPYRIGHT
1305  
1306 Copyright (C) 2001-2003 Particle Physics and Astronomy Research Council.
1307 All Rights Reserved.
1308  
1309 This program is free software; you can redistribute it and/or modify
1310 it under the same terms as Perl itself.
1311  
1312 =cut
1313  
1314 1 1;
↑ Summary