1package Astro::FluxColor;
2
3=head1 NAME
4
5Astro::FluxColor - Class for handling astronomical color quantities.
6
7=head1 SYNOPSIS
8
9use Astro::FluxColor;
10
11  $color = new Astro::FluxColor( lower => $lower_waveband,
12                                 upper => $upper_waveband,
13                                 quantity => $quantity,
14				 datetime => new DateTime );
15
16  $quantity = $color->quantity;
17
18=head1 DESCRIPTION
19
20Class for handling astronomical color quantities.
21
22=cut
23
24use 5.006;
25use strict;
26use warnings;
27use warnings::register;
28use Carp;
29
30use Astro::WaveBand;
31use Number::Uncertainty;
32
33our $VERSION = '0.01';
34
35=head1 METHODS
36
37=head2 Constructor
38
39=over 4
40
41=item B<new>
42
43Create a new instance of an C<Astro::FluxColor> object.
44
45$color = new Astro::FluxColor( lower => $lower_waveband,
46                               upper => $upper_waveband,
47                               quantity => $quantity,
48			       datetime => new DateTime );
49
50The three named parameters are mandatory. F<lower> and F<upper>
51denote the lower and upper wavebands for the colour, and
52must be C<Astro::WaveBand> objects. F<quantity> is a numerical
53value in magnitudes.
54
55=cut
56
57sub new {
58  my $proto = shift;
59  my $class = ref( $proto ) || $proto;
60
61  my %args = @_;
62
63  if( ! defined( $args{'lower'} ) ) {
64    croak "Lower waveband must be defined";
65  } elsif( ! UNIVERSAL::isa( $args{'lower'}, "Astro::WaveBand" ) ) {
66     $args{'lower'} = new Astro::WaveBand( Filter => $args{'lower'} );
67  }
68
69  if( ! defined( $args{'upper'} ) ) {
70    croak "Upper waveband must be defined";
71  } elsif( ! UNIVERSAL::isa( $args{'upper'}, "Astro::WaveBand" ) ) {
72     $args{'upper'} = new Astro::WaveBand( Filter => $args{'upper'} );
73  }
74
75  my $quantity;
76  if( ! defined( $args{'quantity'} ) ) {
77    croak "Color quantity must be defined";
78  } elsif ( ! UNIVERSAL::isa($args{'quantity'}, "Number::Uncertainty" ) ) {
79     $quantity = new Number::Uncertainty( Value => $args{'quantity'} );
80  } else {
81     $quantity = $args{'quantity'};
82  }
83  my $color = {};
84
85  $color->{LOWER} = $args{'lower'};
86  $color->{UPPER} = $args{'upper'};
87  $color->{QUANTITY} = $quantity;
88
89  if( defined( $args{'datetime'} ) ) {
90     unless ( UNIVERSAL::isa( $args{'datetime'}, "DateTime" ) ) {
91        croak "Time stamp must be a DateTime object\n";
92     } else {
93        $color->{TIME} = $args{'datetime'};
94     }
95  }
96
97  bless( $color, $class );
98  return $color;
99
100}
101
102=back
103
104=head2 Accessor Methods
105
106=over 4
107
108=item B<quantity>
109
110Returns the actual color value.
111
112  my $value = $color->quantity;
113
114There are no parameters.
115
116=cut
117
118sub quantity {
119  my $self = shift;
120
121  my $number = $self->{QUANTITY};
122  my $value = $number->value();
123  return $value;
124}
125
126=item B<error>
127
128Returns the actual uncertainty in the cerror.
129
130  my $e = $color->error;
131
132There are no parameters.
133
134=cut
135
136sub error {
137  my $self = shift;
138
139  my $number = $self->{QUANTITY};
140  my $error = $number->error();
141  return $error;
142}
143
144=item B<lower>
145
146Returns the lower waveband.
147
148  my $lower = $color->lower;
149
150There are no parameters. An C<Astro::WaveBand> object is returned.
151
152=cut
153
154sub lower {
155  my $self = shift;
156  return $self->{LOWER};
157}
158
159=item B<upper>
160
161Returns the upper waveband.
162
163  my $upper = $color->upper;
164
165There are no parameters. An C<Astro::WaveBand> object is returned.
166
167=cut
168
169sub upper {
170  my $self = shift;
171  return $self->{UPPER};
172}
173
174
175=item B<datetime>
176
177Returns the datetime stamp for the given flux object.
178
179  my $datetime = $flux->datetime;
180
181Returns an C<Date::datetime> object if defined. If not, returns undef.
182
183=cut
184
185sub datetime {
186  my $self = shift;
187
188  return $self->{TIME};
189}
190
191=back
192
193=head1 REVISION
194
195  $Id: FluxColor.pm,v 1.6 2005/06/15 01:14:01 allan Exp $
196
197=head1 AUTHORS
198
199Brad Cavanagh E<lt>b.cavanagh@jach.hawaii.eduE<gt>,
200Alasdair Allan E<lt>aa@astro.ex.ac.ukE<gt>
201
202=head1 COPYRIGHT
203
204Copyright (C) 2004 Particle Physics and Astronomy Research
205Council.  All Rights Reserved.
206
207This program is free software; you can redistribute it and/or
208modify it under the same terms as Perl itself.
209
210=cut
211
2121;
213