Astro-Catalog

 view release on metacpan or  search on metacpan

lib/Astro/Catalog/IO/FITSTable.pm  view on Meta::CPAN

=head1 PUBLIC METHODS

These methods are usually called automatically from the C<Astro::Catalog>
constructor, but are available for public use.

=over 4

=item B<input_format>

Returns the requested input format for the FITSTable class, which is
'name', meaning the name of the file to be turned into an C<Astro::Catalog>
object.

    $input_format = Astro::Catalog::IO::FITSTable->input_format;

=cut

sub input_format {
    return "name";
}

=back

=begin __PRIVATE_METHODS__

=head1 PRIVATE METHODS

These methods are usually called automatically from the C<Astro::Catalog>
constructor.

=item B<_read_catalog>

Parses the binary FITS table and returns a new C<Astro::Catalog> object
containing the catalog entries.

    $cat = Astro::Catalog::IO::FITSTable->_read_catalog($whatever);

The current translations from FITS table column names to
C<Astro::Catalog::Item> properties are:

=over 4

=item No. - ID

=item X_coordinate - X

=item Y_coordinate - Y

=item RA & DEC - Coords

=item Isophotal_flux, Total_flux, Core_flux, Core1_flux, Core2_flux,
 Core3_flux, Core4_flux, Core5_flux - C<Astro::Flux> objects pushed into
 the C<Astro::Catalog::Item> fluxes accessor.

=item Ellipticity & Position_angle - Morphology

=back

RA and Dec are assumed to be in J2000 coordinates, and are in units
of radians. The isophotal flux is assumed to be in units of counts,
and is converted into a magnitude through the formula -2.5 * log10(flux).
The position angle is assumed to be the angle measured counter-
clockwise from the positive x axis, in degrees.

An attempt to read in the DATE-OBS header is made so that flux measurements
can be timestamped. If the DATE-OBS header does not exist, then the current
date and time will be used for the flux timestamps.

=cut

sub _read_catalog {
    my $class = shift;
    my %args = @_;

    unless (defined $args{'filename'}) {
        croak "Must supply a filename to read";
    }
    my $filename = $args{'filename'};

    my $obsid;
    if (defined $args{'obsid'}) {
        $obsid = $args{'obsid'};
    }
    else {
        $obsid = [];
    }

    # A lookup table for column name mappings.
    my %column_name = (
        'ID' => 'No.',
        'X' => 'X_coordinate',
        'Y' => 'Y_coordinate',
        'RA' => 'RA',
        'Dec' => 'DEC',
        'isophotal_flux' => 'Isophotal_flux',
        'total_flux' => 'Total_flux',
        'core_flux' => 'Core_flux',
        'core1_flux' => 'Core1_flux',
        'core2_flux' => 'Core2_flux',
        'core3_flux' => 'Core3_flux',
        'core4_flux' => 'Core4_flux',
        'core5_flux' => 'Core5_flux',
        'ellipticity' => 'Ellipticity',
        'position_angle' => 'Position_angle',
    );

    # The new Astro::Catalog object.
    my $catalog = new Astro::Catalog;

    # CFITSIO status variable.
    my $status = 0;

    # Open the file using CFITSIO.
    my $fptr = Astro::FITS::CFITSIO::open_file($filename,
            Astro::FITS::CFITSIO::READONLY(),
            $status);
    if ($status != 0) {
        Astro::FITS::CFITSIO::fits_get_errstatus($status, my $text);
        croak "Error opening FITS file: $status $text";
    }



( run in 0.899 second using v1.01-cache-2.11-cpan-cd2fffc590a )