Astro::WaveBand - Transparently work in waveband, wavelength or filter
use Astro::WaveBand; $w = new Astro::WaveBand( Filter => $filter ); $w = new Astro::WaveBand( Wavelength => $wavelength ); $w = new Astro::WaveBand( 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 ) { ... }
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.
Astro::WaveBand
Create a new instance of an Astro::WaveBand object.
$w = new Astro::WaveBand( 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.
Units
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 class Astro::WaveBand) will be issued.
undef
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).
Wavelength in microns.
$wav = $w->wavelength; $w->wavelength(450.0);
Frequency in Hertz.
$frequency = $w->frequency; $w->frequency(345E9);
Wavenumber (reciprocal of wavelength) in inverse centimetres.
$value = $w->wavenumber; $w->wavenumber(1500);
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.
Name of associated instrument.
$inst = $w->instrument; $w->instrument( 'SCUBA' );
Used to aid in the choice of 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');
Return the name of the waveband associated with the object.
Returns undef if none can be determined.
$band = $w->waveband;
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.
natural_unit
$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.
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 the natural method to check if two wavebands are identical.
equals
natural
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 compare method for that.
compare
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 the natural method AND for the instrument method (if it is defined for both objects) , and 0 of they return different values.
instrument
This method is overloaded using the == operator, so
if( $wb1 == $wb2 ) { ... }
is functionally the same as the first example.
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 the instrument method return different values. If the instrument is undefined for either object, then the natural method will be used.
This method is overloaded using the != operator, so
if( $wb1 != $wb2 ) { ... }
These functions enable the user to obtain an overview of the supported filter, instrument and telescope combinations.
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.
Returns true if the a particular instrument exists for a particular telescope, otherwise returns undef, e.g.
if( Astro::WaveBand::has_instrument( UKIRT => "UIST" ) { ... }
Returns true if the a particular telescope and filter combination is avaialable, otherwise returns undef, e.g.
if( Astro::WaveBand::is_observable( UKIRT => 'Kprime' ) { ... }
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 could accept a molecule and transition, allowing the natural unit to appear as something like: "CO 3-2 @ 30km/s LSR radio".
Tim Jenness <t.jenness@jach.hawaii.edu> Alasdair Allan <aa@astro.ex.ac.uk> Tim Lister <tlister@lcogt.net>
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.
To install Astro::WaveBand, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Astro::WaveBand
CPAN shell
perl -MCPAN -e shell install Astro::WaveBand
For more information on module installation, please visit the detailed CPAN module installation guide.