Astro-Cosmology

 view release on metacpan or  search on metacpan

Cosmology.pm  view on Meta::CPAN

converges (ie the absolute difference in the values from the
last two iterations is smaller than the C<ABSTOL>
parameter, which is described in the L<new|/new> method).

Typically, the romberg integration scheme produces greater
accuracy for smooth functions when compared to simpler
methods (e.g. Simpson's method) while having little extra
overhead for badly-behaved functions.

=head1 CONSTANTS

Currently the following constants are available via
C<use Astro::Cosmology qw( :constants )>:

=over 4

=item *

LIGHT - the speed of light in m/s.

=item *

PARSEC - one parsec in metres.

=item *

STERADIAN - one steradian in degrees^2.

=item *

YEAR_TROPICAL - one tropical year in seconds.

=item *

PI - defined as 4.0 * atan(1.0,1.0) [this is in uppercase, whatever
this document may say]

=item *

FOURPI - 4.0 * PI [again PI should be in upper case here]

=back

Please do I<not> use this feature, as it will be removed when
an 'Astronomy constants' is created - e.g. see the astroconst
package at http://clavelina.as.arizona.edu/astroconst/ .

=head1 SYNTAX

This document uses the C<$object-E<gt>func(...)> syntax throughout.
If you prefer the C<func($object,...)> style, then you need to
import the functions:

  use Astro::Cosmology qw( :Func );

Most functions have two names; a short one and a (hopefully) more
descriptive one, such as C<pmot_dist()> and C<proper_motion_distance()>.

Most of the routines below include a C<sig:> line in their documentation.
This is an attempt to say how they
`L<thread|PDL::indexing>' (in the L<PDL|PDL> sense of the word).
So, for routines like C<lum_dist> - which have a sig line of
C<dl() = $cosmo-E<gt>lum_dist( z() )> - the return value has the
same format as the input C<$z> value; supply a scalar, get a scalar back,
send in a piddle and get a piddle of the same dimensions back.
For routines like C<abs_mag> - with a sig line of
C<absmag() = $cosmo-E<gt>abs_mag( appmag(), z() )> - you can thread over
either of the two input values,
in this case the apparent magnitude and redshift.

=head1 SUMMARY

=head2 Utility routines

=over 4

=item * new

=item * version

=item * stringify

=item * setvars

=item * matter/omega_matter, lambda/omega_lambda, h0/hO

=back

=head2 Distance measures

=over 4

=item * lum_dist/luminosity_distance

=item * adiam_dist/angular_diameter_distance

=item * pmot_dist/proper_motion_distance

=item * comov_dist/comoving_distance

=back

=head2 Volume measures

=over 4

=item * comov_vol/comoving_volume

=item * dcomov_vol/differential_comoving_volume

=back

=head2 Time measures

=over 4

=item * lookback_time

=back

=head1 ROUTINES

=head2 new

  my $cosmo = Astro::Cosmology->new(
                matter => 0.3, lambda => 0.7 );
  my $cosmo = Astro::Cosmology->new(

Cosmology.pm  view on Meta::CPAN

    $self->setvars( OMEGA_LAMBDA => $_[0] ) if @_;
    return $self->{OMEGA_LAMBDA};
}
*lambda = \&omega_lambda;

sub h0 ($;$) {
    my $self = shift;
    $self->setvars( H0 => $_[0] ) if @_;
    return $self->{H0};
}
*hO = \&h0;

# we ignore the need for K/evolutionary corrections
# in the following
#
# NOTE:
#   correct use of units is rather poor
#
sub abs_mag ($$$) {
    my ( $self, $apparent, $z ) = @_;

    return ( $apparent - 25 - 5 * $self->lum_dist($z)->log10() );

} # sub: abs_mag()
*absolute_magnitude = \&abs_mag;

sub app_mag ($$$) {
    my ( $self, $absolute, $z ) = @_;

    return ( $absolute + 25 + 5 * $self->lum_dist($z)->log10() );

} # sub: app_mag()
*apparent_magnitude = \&app_mag;

sub luminosity ($$$) {
    my ( $self, $flux, $z ) = @_;

    my $dl = $self->lum_dist($z) * 1.0e8 * PARSEC;  # convert to cm
    return ( FOURPI * $dl * $dl * $flux );

} # sub: luminosity()

sub flux ($$$) {
    my ( $self, $luminosity, $z ) = @_;

    my $dl = $self->lum_dist($z) * 1.0e8 * PARSEC;  # convert to cm
    return ( $luminosity / ( FOURPI * $dl * $dl ) );

} # sub: flux()

# note:
#  one parameter:  age of z = 0  -> $1
#  two parameters: age of z = $1 -> $2
#
# ie lookback_time ( [ $z_low ], $z_high )
#
# note: we call the C code directly
#
sub lookback_time ($$;$) {
    my $self   = shift;
    my $z_low  = $#_ == 1 ? shift : 0;   # let PDL do the threading if z_high is a piddle
    my $z_high = shift;

    return Astro::Cosmology::Internal::_lookback_time( $z_low, $z_high,
			   $self->{OMEGA_MATTER}, $self->{OMEGA_LAMBDA},
			   $self->{ABSTOL}, $self->{TCONV} );

} # sub: lookback_time

####################################################################
#
# distance measures: PM code
#
####################################################################

sub lum_dist ($$) {
    my $self = shift;
    my $z    = shift;

    return Astro::Cosmology::Internal::_lum_dist( $z, $self->{COSMOLOGY}, $self->{OMEGA_MATTER}, $self->{OMEGA_LAMBDA},
		      $self->{KAPPA}, $self->{ABSTOL}, $self->{DCONV} );

} # sub: lum_dist()
*luminosity_distance = \&lum_dist;

sub pmot_dist ($$) {
    my $self = shift;
    my $z    = shift;

    return Astro::Cosmology::Internal::_lum_dist( $z, $self->{COSMOLOGY}, $self->{OMEGA_MATTER}, $self->{OMEGA_LAMBDA},
		      $self->{KAPPA}, $self->{ABSTOL}, $self->{DCONV} ) /
			  (1.0+$z);

} # sub: pmot_dist()
*proper_motion_distance = \&pmot_dist;

sub adiam_dist ($$) {
    my $self = shift;
    my $z    = shift;

    return Astro::Cosmology::Internal::_lum_dist( $z, $self->{COSMOLOGY}, $self->{OMEGA_MATTER}, $self->{OMEGA_LAMBDA},
		      $self->{KAPPA}, $self->{ABSTOL}, $self->{DCONV} ) /
			  ( (1.0+$z) * (1.0+$z) );

} # sub: adiam_dist()
*angular_diameter_distance = \&adiam_dist;

sub comov_dist ($$) {
    my $self = shift;
    my $z    = shift;

    return Astro::Cosmology::Internal::_comov_dist( $z, $self->{OMEGA_MATTER}, $self->{OMEGA_LAMBDA},
			$self->{ABSTOL}, $self->{DCONV} );

} # sub: comov_dist()
*comoving_distance = \&comov_dist;

####################################################################
#
# volume measures: PM code
#



( run in 1.217 second using v1.01-cache-2.11-cpan-d06a3f9ecfd )