NAME
Astro::WaveBand - Transparently work in waveband, wavelength or filter
SYNOPSIS
use Astro::WaveBand;
$w = Astro::WaveBand->new(Filter => $filter);
$w = Astro::WaveBand->new(Wavelength => $wavelength);
$w = Astro::WaveBand->new(
Wavelength => $wavelength,
Instrument => 'CGS4');
$filter = $w->filter;
$wave = $w->wavelength;
$band = $w->waveband; # radio, xray, submm
$freq = $w->frequency;
$wnum = $w->wavenumber;
$natural = $w->natural;
$natural = "$w";
$w->natural_unit("wavelength");
if ($w1 > $w2) {...}
if ($w1 == $w2) {...}
DESCRIPTION
Class to transparently deal with the conversion between filters, wavelength, frequency and other methods of specifying a location in the electro-magentic spectrum.
The class tries to determine the natural form of the numbers such that a request for a summary of the object when it contains 2.2 microns would return the filter name but would return the wavelength if it was not a standard filter. In ambiguous cases an instrument name is required to decide what to return. In really ambiguous cases the user can specify the unit in which to display the numbers on stringification.
Used mainly as a way of storing a single number in a database table but using logic to determine the number that an observer is most likely to understand.
Numerical comparison operators can be used to compare two Astro::WaveBand
objects. When checking equality, the "natural" and "instrument" methods are used, so if two Astro::WaveBand
objects return the same value from those methods, they are considered to be equal. When checking other comparisons such as greater than, the wavelength is used.
METHODS
Constructor
- new
-
Create a new instance of an
Astro::WaveBand
object.$w = Astro::WaveBand->new(Filter => $filter);
Allowed keys for constructor are one of:
Filter - filter name Wavelength - wavelength in microns Frequency - frequency in Hertz Wavenumber - wavenumber in cm^-1
plus optionally:
Instrument - name of associated instrument
In the future there may be a
Units
key to allow the units to be supplied in alternative forms.If a mandatory key is missing or there is more than one mandatory key the constructor will fail and return
undef
. Additionally a warning (of classAstro::WaveBand
) will be issued.
Accessor methods
All the accessor methods associated with conversions will automatically convert to the correct format on demand and will cache it for later. If a new value is provided all caches will be cleared.
All input values are converted to microns internally (since a single base unit should be chosen to simplify internal conversions).
If a numeric accessor (wavelength, frequency, wavenumber) is called with a hash reference as the first argument then it is interpreted as a set of options. (The filter accessor also accepts an initial hash reference for consistency.) Options can include:
- format
-
If returning a value, construct a formatted string including the units.
- ndp
-
When returning a string (
format
is true), round the value to this number of decimal places. If not specified, 3 is used.
For example:
$w->frequency({format => 1})
Could return a string such as "345.796 GHz".
- wavelength
-
Wavelength in microns.
$wav = $w->wavelength; $w->wavelength(450.0);
- frequency
-
Frequency in Hertz.
$frequency = $w->frequency; $w->frequency(345E9);
- wavenumber
-
Wavenumber (reciprocal of wavelength) in inverse centimetres.
$value = $w->wavenumber; $w->wavenumber(1500);
- filter
-
Set or retrieve filter name.
Returns
undef
if the filter can not be determined. If the filter name can not be translated to a wavelength it will not be possible to do any conversions to other forms. - instrument
-
Name of associated instrument.
$inst = $w->instrument; $w->instrument('SCUBA');
Used to aid in the choice of natural unit.
- natural_unit
-
Override the natural unit to be used for stringification. If this value is not set the class will determine the unit of choice by looking at the instrument name and then by taking an informed guess.
$w->natural_unit('filter');
- species
-
Name of species involved in an emission line.
- transition
-
Transition giving rise to line emission.
General Methods
- waveband
-
Return the name of the waveband associated with the object.
Returns
undef
if none can be determined.$band = $w->waveband;
- natural
-
Return the contents of the object in its most natural form. For example, with UFTI the filter name will be returned whereas with ACSIS the frequency will be returned. The choice of unit is chosen using the supplied default unit (see
natural_unit
) or the instrument name. If none of these is specified filter will be used and if no match is present wavelength in microns.$value = $w->natural;
Returns
undef
if the value can not be determined.This method is called automatically when the object is stringified. Note that you will not know the unit that was chosen a priori.
If a hash reference (containing formatting options) is given then it is passed to the relevant accessor method.
- compare
-
Compares two
Astro::WaveBand
objects.if ($wb1->compare($wb2)) {...}
This method will return -1 if, in the above example, $wb1 is of a shorter wavelength than $wb2, 0 if the wavelengths are equal, and +1 if $wb1 is of a longer wavelength than $wb2. Please note that for strict waveband equality the
equals
method should be used, as that method uses thenatural
method to check if two wavebands are identical.This method is overloaded with the standard numerical comparison operators, so to check if one waveband is shorter than another you would do
if ($wb1 < $wb2) {...}
and it will work as you expect. This method does not overload the == operator; see the
equals
method for that. - equals
-
Compares two
Astro::WaveBand
objects for equality.if ($wb1->equals($wb2)) {...}
This method will return 1 if, in the above example, both
Astro::WaveBand
objects return the same value from thenatural
method AND for theinstrument
method (if it is defined for both objects) , and 0 of they return different values.This method is overloaded using the == operator, so
if ($wb1 == $wb2) {...}
is functionally the same as the first example.
- not_equals
-
Compares two
Astro::WaveBand
objects for inequality.if ($wb1->not_equals($wb2)) {...}
This method will return 1 if, in the above example, either the
natural
method or theinstrument
method return different values. If the instrument is undefined for either object, then thenatural
method will be used.This method is overloaded using the != operator, so
if ($wb1 != $wb2) {...}
is functionally the same as the first example.
Static functions
These functions enable the user to obtain an overview of the supported filter, instrument and telescope combinations.
- has_filter
-
Returns true if the a particular instrument has a particular filter, otherwise returns
undef
, e.g.if (Astro::WaveBand::has_filter(UIST => "Kprime")) { ... }
if you pass a hash containing multiple instrument combinations, all must be valid or the method will return undef.
- has_instrument
-
Returns true if the a particular instrument exists for a particular telescope, otherwise returns
undef
, e.g.if (Astro::WaveBand::has_instrument(UKIRT => "UIST")) { ... }
if you pass a hash containing multiple instrument combinations, all must be valid or the method will return undef.
- is_observable
-
Returns true if the a particular telescope and filter combination is avaialable, otherwise returns
undef
, e.g.if (Astro::WaveBand::is_observable(UKIRT => 'Kprime')) { ... }
BUGS
Does not automatically convert metres to microns and GHz to Hz etc.
Can not handle filters that correspond to multiple wavelengths. Currently SCUBA is the main issue. With a 450:850 filter this class always returns the shortest wavelength (since that is the wavelength that affects scheduling the most).
Should handle velocities and redshifts in order to disambiguate rest frequencies and observed frequencies. Would also be nice if the class used the species and transition to allow the natural unit to appear as something like: "CO 3-2 @ 30km/s LSR radio".
AUTHORS
Tim Jenness <t.jenness@jach.hawaii.edu> Alasdair Allan <aa@astro.ex.ac.uk> Tim Lister <tlister@lcogt.net>
COPYRIGHT
Copyright (C) 2001-2003 Particle Physics and Astronomy Research Council. All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.