Astro-Flux
view release on metacpan or search on metacpan
* Fluxes.pm: Added whatwavebands().
* Flux.pm & FluxColor.pm: Strings are automatically promoted
to Astro::WaveBand objects if we don't have one already.
2005-06-13 Alasdair Allan <aa@astro.ex.ac.uk>
* Fluxes.pm: Added allfluxes() and fluxesbywaveband() methods.
* Flux.pm: Moved $quanitity to be a Number::Uncertainty object,
added support to date stamp the flux using a DateTime object,
and support to retreieve the error independantly. All changes
should be backwards compatible.
* Added some more tests
2005-06-10 Alasdair Allan <aa@astro.ex.ac.uk>
* Fluxes.pm & Flux.pm: Replaced Astro::Quality with Misc::Quality
(say, from magnitudes to Janskies) but may in the future.
=cut
use 5.006;
use strict;
use warnings;
use warnings::register;
use Carp;
use Number::Uncertainty;
our $VERSION = '0.01';
=head1 METHODS
=head2 Constructor
=over 4
=item B<new>
Create a new instance of an C<Astro::Flux> object.
$flux = new Astro::Flux( $quantity, $type, $waveband );
The first three parameters must be defined. They are:
quantity - numerical value for the flux, my be a primitive, or a
C<Number::Uncertainty> object.
type - type of flux. Can be any string.
waveband - waveband for the given flux. Must be an C<Astro::WaveBand> object.
If any of the parameters are undefined, the constructor will throw
an error. If the waveband parameter is not an C<Astro::WaveBand> object,
the constructor will throw an error.
The type is case-insensitive for lookups using the C<quantity> method.
A fourth optional argument may be passed; this is a hash containing
my $quantity = shift;
my $type = shift;
my $waveband = shift;
my %args = @_;
croak "Quantity must be defined"
unless defined $quantity;
unless ( UNIVERSAL::isa($quantity, "Number::Uncertainty" ) ) {
$quantity = new Number::Uncertainty( Value => $quantity );
}
croak "Type must be defined"
unless defined $type;
croak "Waveband must be defined"
unless defined $waveband;
unless ( UNIVERSAL::isa($waveband, "Astro::WaveBand") ) {
$waveband = new Astro::WaveBand( Filter => $waveband );
FluxColor.pm view on Meta::CPAN
=cut
use 5.006;
use strict;
use warnings;
use warnings::register;
use Carp;
use Astro::WaveBand;
use Number::Uncertainty;
our $VERSION = '0.01';
=head1 METHODS
=head2 Constructor
=over 4
=item B<new>
FluxColor.pm view on Meta::CPAN
if( ! defined( $args{'upper'} ) ) {
croak "Upper waveband must be defined";
} elsif( ! UNIVERSAL::isa( $args{'upper'}, "Astro::WaveBand" ) ) {
$args{'upper'} = new Astro::WaveBand( Filter => $args{'upper'} );
}
my $quantity;
if( ! defined( $args{'quantity'} ) ) {
croak "Color quantity must be defined";
} elsif ( ! UNIVERSAL::isa($args{'quantity'}, "Number::Uncertainty" ) ) {
$quantity = new Number::Uncertainty( Value => $args{'quantity'} );
} else {
$quantity = $args{'quantity'};
}
my $color = {};
$color->{LOWER} = $args{'lower'};
$color->{UPPER} = $args{'upper'};
$color->{QUANTITY} = $quantity;
if( defined( $args{'datetime'} ) ) {
FluxColor.pm view on Meta::CPAN
sub quantity {
my $self = shift;
my $number = $self->{QUANTITY};
my $value = $number->value();
return $value;
}
=item B<error>
Returns the actual uncertainty in the cerror.
my $e = $color->error;
There are no parameters.
=cut
sub error {
my $self = shift;
$running_error = sqrt( $running_error ) if defined $running_error;
# Form a flux object with the running total and the input waveband,
# and return that.
if( ! defined( $running_total ) ) {
return undef;
} else {
my $number;
if ( defined $running_error ) {
$number = new Number::Uncertainty( Value => $running_total,
Error => $running_error );
} else {
$number = $running_total;
}
if ( defined $args{'datetime'} ) {
my $returned_flux = new Astro::Flux( $number, 'mag', $waveband,
quality => new Misc::Quality( derived => 1 ),
datetime => $ref_datetime );
return $returned_flux;
} else {
my $datetime = $flux->datetime;
}
}
my $ref_key = $flux->reference_waveband()->natural();
if( $ref_key eq $upper_key ) {
my $num;
if ( defined $flux->error('mag') ) {
$num = new Number::Uncertainty ( Value => $flux->quantity('mag'),
Error => $flux->error('mag') )
} else {
$num = new Number::Uncertainty ( Value => $flux->quantity('mag') );
}
if ( defined $flux->datetime() ) {
my $color = new Astro::FluxColor( lower => $lower,
upper => $upper,
quantity => $num,
datetime => $flux->datetime() );
return $color;
} else {
my $color = new Astro::FluxColor( lower => $lower,
$upper_mag = $self->flux( waveband => $upper, derived => 1 );
$lower_mag = $self->flux( waveband => $lower, derived => 1 );
}
if( defined( $upper_mag ) && defined( $lower_mag ) ) {
my $num;
my $value = $lower_mag->quantity('mag') - $upper_mag->quantity('mag');
if ( defined $upper_mag->error('mag') && $lower_mag->error('mag') ) {
my $error = sqrt( $upper_mag->error('mag')*$upper_mag->error('mag')
+ $lower_mag->error('mag')*$lower_mag->error('mag') );
$num = new Number::Uncertainty ( Value => $value,
Error => $error )
} else {
$num = new Number::Uncertainty ( Value => $value );
}
if ( defined $lower_mag->datetime() && defined $upper_mag->datetime() ) {
my $color = new Astro::FluxColor( lower => $lower,
upper => $upper,
quantity => $num,
datetime => $lower_mag->datetime() );
return $color;
} else {
my $color = new Astro::FluxColor( lower => $lower,
upper => $upper,
my $key = $arg->waveband()->natural();
push @{${$self->{FLUXES}}{$key}}, $arg;
push @{$self->{FLUX}}, $arg->waveband();
} elsif( UNIVERSAL::isa( $arg, "Astro::FluxColor" ) ) {
# Create an Misc::Quality object saying that these are derived
# magnitudes.
my $quality = new Misc::Quality( 'derived' => 1 );
# Create two flux objects, one for the lower and one for the upper.
my $num = new Number::Uncertainty( Value => $arg->quantity,
Error => $arg->error );
my ( $lower_flux, $upper_flux );
if ( defined $arg->datetime() ) {
$lower_flux = new Astro::Flux( $num , 'mag', $arg->lower,
quality => $quality,
reference_waveband => $arg->upper,
datetime => $arg->datetime );
$upper_flux = new Astro::Flux( -1.0 * $num, 'mag', $arg->upper,
quality => $quality,
# http://module-build.sourceforge.net/META-spec.html
#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
name: Astro-Flux
version: 0.01
version_from: Flux.pm
installdirs: site
requires:
Astro::WaveBand: 0
DateTime: 0
Misc::Quality: 0
Number::Uncertainty: 0
distribution_type: module
generated_by: ExtUtils::MakeMaker version 6.30
Makefile.PL view on Meta::CPAN
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile being created.
WriteMakefile(
'NAME' => 'Astro::Flux',
'VERSION_FROM' => 'Flux.pm',
'PREREQ_PM' => {
'Astro::WaveBand' => 0,
'DateTime' => 0,
'Misc::Quality' => 0,
'Number::Uncertainty' => 0,
},
($] >= 5.005 ? ## Add these new keywords supported since 5.005
(ABSTRACT_FROM => 'Flux.pm',
AUTHOR => 'Brad Cavanagh <b.cavanagh@jach.hawaii.edu>') : ()),
'dist' => {COMPRESS=>'gzip -9f', SUFFIX=>'gz'},
);
( run in 0.448 second using v1.01-cache-2.11-cpan-4e96b696675 )