line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Astro::Flux; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Astro::Flux - Class for handling astronomical flux quantities. |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Astro::Flux; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
$flux = new Astro::Flux( $quantity, $units, $waveband ); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
$quantity = $flux->quantity('mag'); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 DESCRIPTION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Class for handling astronomical flux quantities. This class does |
18
|
|
|
|
|
|
|
not currently support conversions from one flux type to another |
19
|
|
|
|
|
|
|
(say, from magnitudes to Janskies) but may in the future. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=cut |
22
|
|
|
|
|
|
|
|
23
|
3
|
|
|
3
|
|
27499
|
use 5.006; |
|
3
|
|
|
|
|
12
|
|
|
3
|
|
|
|
|
739
|
|
24
|
3
|
|
|
3
|
|
17
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
101
|
|
25
|
3
|
|
|
3
|
|
26
|
use warnings; |
|
3
|
|
|
|
|
83
|
|
|
3
|
|
|
|
|
95
|
|
26
|
3
|
|
|
3
|
|
15
|
use warnings::register; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
383
|
|
27
|
3
|
|
|
3
|
|
17
|
use Carp; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
408
|
|
28
|
|
|
|
|
|
|
|
29
|
3
|
|
|
3
|
|
3403
|
use Number::Uncertainty; |
|
3
|
|
|
|
|
9941
|
|
|
3
|
|
|
|
|
2792
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 METHODS |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head2 Constructor |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=over 4 |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=item B |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Create a new instance of an C object. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
$flux = new Astro::Flux( $quantity, $type, $waveband ); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
The first three parameters must be defined. They are: |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
quantity - numerical value for the flux, my be a primitive, or a |
48
|
|
|
|
|
|
|
C object. |
49
|
|
|
|
|
|
|
type - type of flux. Can be any string. |
50
|
|
|
|
|
|
|
waveband - waveband for the given flux. Must be an C object. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
If any of the parameters are undefined, the constructor will throw |
53
|
|
|
|
|
|
|
an error. If the waveband parameter is not an C object, |
54
|
|
|
|
|
|
|
the constructor will throw an error. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
The type is case-insensitive for lookups using the C method. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
A fourth optional argument may be passed; this is a hash containing |
59
|
|
|
|
|
|
|
the following optional keys: |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
quality - an C object denoting quality flags for the |
62
|
|
|
|
|
|
|
C object. |
63
|
|
|
|
|
|
|
reference_waveband - an C object denoting a reference |
64
|
|
|
|
|
|
|
waveband for the C object. This is used for determining |
65
|
|
|
|
|
|
|
magnitudes when deriving them from C objects. See |
66
|
|
|
|
|
|
|
C. |
67
|
|
|
|
|
|
|
datetime - an C object which is the datetime of observation for the |
68
|
|
|
|
|
|
|
measurement in the C object. |
69
|
|
|
|
|
|
|
obsid - An array reference to a list of observation identifiers. Can be |
70
|
|
|
|
|
|
|
used to identify the observation(s) from which this measurement was |
71
|
|
|
|
|
|
|
taken (e.g. from a filename). |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=cut |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub new { |
76
|
22
|
|
|
22
|
1
|
3552
|
my $proto = shift; |
77
|
22
|
|
33
|
|
|
97
|
my $class = ref( $proto ) || $proto; |
78
|
|
|
|
|
|
|
|
79
|
22
|
|
|
|
|
29
|
my $quantity = shift; |
80
|
22
|
|
|
|
|
26
|
my $type = shift; |
81
|
22
|
|
|
|
|
29
|
my $waveband = shift; |
82
|
|
|
|
|
|
|
|
83
|
22
|
|
|
|
|
39
|
my %args = @_; |
84
|
|
|
|
|
|
|
|
85
|
22
|
50
|
|
|
|
52
|
croak "Quantity must be defined" |
86
|
|
|
|
|
|
|
unless defined $quantity; |
87
|
|
|
|
|
|
|
|
88
|
22
|
100
|
|
|
|
76
|
unless ( UNIVERSAL::isa($quantity, "Number::Uncertainty" ) ) { |
89
|
8
|
|
|
|
|
34
|
$quantity = new Number::Uncertainty( Value => $quantity ); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
22
|
50
|
|
|
|
620
|
croak "Type must be defined" |
93
|
|
|
|
|
|
|
unless defined $type; |
94
|
|
|
|
|
|
|
|
95
|
22
|
50
|
|
|
|
39
|
croak "Waveband must be defined" |
96
|
|
|
|
|
|
|
unless defined $waveband; |
97
|
|
|
|
|
|
|
|
98
|
22
|
50
|
|
|
|
72
|
unless ( UNIVERSAL::isa($waveband, "Astro::WaveBand") ) { |
99
|
0
|
|
|
|
|
0
|
$waveband = new Astro::WaveBand( Filter => $waveband ); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
22
|
|
|
|
|
32
|
my $flux = {}; |
103
|
|
|
|
|
|
|
|
104
|
22
|
|
|
|
|
69
|
$flux->{QUANTITY} = { uc($type) => $quantity }; |
105
|
22
|
|
|
|
|
36
|
$flux->{WAVEBAND} = $waveband; |
106
|
22
|
|
|
|
|
41
|
$flux->{TYPE} = uc( $type ); |
107
|
|
|
|
|
|
|
|
108
|
22
|
100
|
66
|
|
|
110
|
if( defined( $args{'quality'} ) && |
109
|
|
|
|
|
|
|
UNIVERSAL::isa( $args{'quality'}, "Misc::Quality" ) ) { |
110
|
14
|
|
|
|
|
31
|
$flux->{QUALITY} = $args{'quality'}; |
111
|
|
|
|
|
|
|
} |
112
|
22
|
100
|
66
|
|
|
80
|
if( defined( $args{'reference_waveband'} ) && |
113
|
|
|
|
|
|
|
UNIVERSAL::isa( $args{'reference_waveband'}, "Astro::WaveBand" ) ) { |
114
|
8
|
|
|
|
|
14
|
$flux->{REFERENCE_WAVEBAND} = $args{'reference_waveband'}; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
22
|
50
|
33
|
|
|
58
|
if( defined( $args{'datetime'} ) && |
118
|
|
|
|
|
|
|
UNIVERSAL::isa( $args{'datetime'}, "DateTime" ) ) { |
119
|
0
|
|
|
|
|
0
|
$flux->{TIME} = $args{'datetime'}; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
22
|
50
|
|
|
|
45
|
if( defined( $args{'obsid'} ) ) { |
123
|
0
|
|
|
|
|
0
|
$flux->{OBSID} = $args{'obsid'}; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
22
|
|
|
|
|
39
|
bless( $flux, $class ); |
127
|
22
|
|
|
|
|
69
|
return $flux; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=back |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head2 Accessor Methods |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=over 4 |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=item B |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Returns the quantity for a requested flux type. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
my $mag = $flux->quantity('mag'); |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
No conversions are done between types. What you put in via the |
144
|
|
|
|
|
|
|
constructor is all you can get out, so if you specify the type |
145
|
|
|
|
|
|
|
to be 'magnitude' and you ask for a 'mag', this method will |
146
|
|
|
|
|
|
|
throw an error. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
The type is case-insensitive. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=cut |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub quantity { |
153
|
25
|
|
|
25
|
1
|
441
|
my $self = shift; |
154
|
25
|
|
|
|
|
39
|
my $type = uc(shift); |
155
|
|
|
|
|
|
|
|
156
|
25
|
50
|
|
|
|
51
|
return undef if ! defined $type; |
157
|
|
|
|
|
|
|
|
158
|
25
|
50
|
|
|
|
64
|
croak "Cannot translate between flux types" |
159
|
|
|
|
|
|
|
if ! defined( $self->{QUANTITY}->{$type} ); |
160
|
|
|
|
|
|
|
|
161
|
25
|
|
|
|
|
38
|
my $number = $self->{QUANTITY}->{$type}; |
162
|
25
|
|
|
|
|
131
|
my $value = $number->value(); |
163
|
25
|
|
|
|
|
161
|
return $value; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=item B |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Returns the error in the quantity for a requested flux type. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
my $mag = $flux->error('mag'); |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
No conversions are done between types. What you put in via the |
174
|
|
|
|
|
|
|
constructor is all you can get out, so if you specify the type |
175
|
|
|
|
|
|
|
to be 'magnitude' and you ask for a 'mag', this method will |
176
|
|
|
|
|
|
|
throw an error. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
The type is case-insensitive. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Errors are only returned if one was created with the object. |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=cut |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
sub error { |
185
|
26
|
|
|
26
|
1
|
31
|
my $self = shift; |
186
|
26
|
|
|
|
|
36
|
my $type = uc(shift); |
187
|
|
|
|
|
|
|
|
188
|
26
|
50
|
|
|
|
50
|
return undef if ! defined $type; |
189
|
|
|
|
|
|
|
|
190
|
26
|
50
|
|
|
|
71
|
croak "Cannot translate between flux types" |
191
|
|
|
|
|
|
|
if ! defined( $self->{QUANTITY}->{$type} ); |
192
|
|
|
|
|
|
|
|
193
|
26
|
|
|
|
|
40
|
my $number = $self->{QUANTITY}->{$type}; |
194
|
26
|
|
|
|
|
61
|
my $error = $number->error(); |
195
|
26
|
|
|
|
|
1235
|
return $error; |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=item B |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
Returns the waveband for the given flux object. |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
my $waveband = $flux->waveband; |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Returns an C object. |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=cut |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
sub waveband { |
210
|
33
|
|
|
33
|
1
|
42
|
my $self = shift; |
211
|
|
|
|
|
|
|
|
212
|
33
|
|
|
|
|
158
|
return $self->{WAVEBAND}; |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=item B |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
Returns the quality for the given flux object. |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
my $quality = $flux->quality; |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
Returns an C object if defined. If not, returns undef. |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=cut |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
sub quality { |
226
|
12
|
|
|
12
|
1
|
14
|
my $self = shift; |
227
|
|
|
|
|
|
|
|
228
|
12
|
|
|
|
|
30
|
return $self->{QUALITY}; |
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=item B |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
Returns the reference waveband for the given flux object. |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
my $ref_waveband = $flux->reference_waveband; |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
Returns an C object if defined. If not, returns undef. |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=cut |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
sub reference_waveband { |
242
|
58
|
|
|
58
|
1
|
63
|
my $self = shift; |
243
|
|
|
|
|
|
|
|
244
|
58
|
|
|
|
|
211
|
return $self->{REFERENCE_WAVEBAND}; |
245
|
|
|
|
|
|
|
} |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=item B |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
Sets or returns the datetime stamp for the given flux object. |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
my $datetime = $flux->datetime; |
253
|
|
|
|
|
|
|
$flux->datetime( new DateTime ); |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
Returns an C object if defined. If not, returns undef. |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
=cut |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
sub datetime { |
260
|
4
|
|
|
4
|
1
|
8
|
my $self = shift; |
261
|
|
|
|
|
|
|
|
262
|
4
|
50
|
|
|
|
13
|
if (@_) { |
263
|
0
|
|
|
|
|
0
|
$self->{TIME} = shift; |
264
|
|
|
|
|
|
|
} |
265
|
|
|
|
|
|
|
|
266
|
4
|
|
|
|
|
25
|
return $self->{TIME}; |
267
|
|
|
|
|
|
|
} |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=item B |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
Sets or returns the observation ID for the given flux object. |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
my $obsid = $flux->obsid; |
274
|
|
|
|
|
|
|
$flux->obsid( $obsid ); |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
Returns an array reference if defined. If not, returns undef. |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
=cut |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
sub obsid { |
281
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
282
|
|
|
|
|
|
|
|
283
|
0
|
0
|
|
|
|
0
|
if( @_ ) { |
284
|
0
|
|
|
|
|
0
|
$self->{OBSID} = shift; |
285
|
|
|
|
|
|
|
} |
286
|
0
|
|
|
|
|
0
|
return $self->{OBSID}; |
287
|
|
|
|
|
|
|
} |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
=item B |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
Returns the type of flux measurement stored. |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
my $type = $flux->type; |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
Cannot be used to set the type. |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
=cut |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
sub type { |
300
|
18
|
|
|
18
|
1
|
343
|
my $self = shift; |
301
|
18
|
|
|
|
|
85
|
return $self->{TYPE}; |
302
|
|
|
|
|
|
|
} |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
=back |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
=head1 REVISION |
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
$Id: Flux.pm,v 1.14 2005/06/24 21:02:11 bradc Exp $ |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
=head1 AUTHORS |
311
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
Brad Cavanagh Eb.cavanagh@jach.hawaii.eduE, |
313
|
|
|
|
|
|
|
Alasdair Allan Eaa@astro.ex.ac.ukE |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
=head1 COPYRIGHT |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
Copyright (C) 2004 - 2005 Particle Physics and Astronomy Research |
318
|
|
|
|
|
|
|
Council. All Rights Reserved. |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or |
321
|
|
|
|
|
|
|
modify it under the same terms as Perl itself. |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
=cut |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
1; |