| 1 | package Astro::Catalog::IO::GaiaPick; | ||||||||||
| 2 | |||||||||||
| 3 | =head1 NAME | ||||||||||
| 4 | |||||||||||
| 5 | Astro::Catalog::IO::GaiaPick - Catalog reader for GAIA Pick Object files | ||||||||||
| 6 | |||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||
| 8 | |||||||||||
| 9 | $cat = Astro::Catalog::IO::GaiaPick->_read_catalog(\@lines); | ||||||||||
| 10 | |||||||||||
| 11 | =head1 DESCRIPTION | ||||||||||
| 12 | |||||||||||
| 13 | This class provides a read method for catalogs in the GAIA Pick | ||||||||||
| 14 | Object catalog format. This format is written by the Starlink GAIA | ||||||||||
| 15 | application when a user requests the result of a "Pick Object" are to | ||||||||||
| 16 | be saved. The method is not public and should, in general, only be | ||||||||||
| 17 | called from the C<Astro::Catalog> C<read_catalog> method. | ||||||||||
| 18 | |||||||||||
| 19 | =cut | ||||||||||
| 20 | |||||||||||
| 21 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | 2 | ▶ | use warnings::register; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 24 | 2 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 25 | 2 | ▶ | use Data::Dumper; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | |||||||||||
| 27 | 2 | ▶ | use Astro::Catalog; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 28 | 2 | ▶ | use Astro::Catalog::Item; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 29 | 2 | ▶ | use Astro::Coords; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 30 | |||||||||||
| 31 | 2 | ▶ | use base qw/Astro::Catalog::IO::ASCII/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 32 | |||||||||||
| 33 | 2 | our $DEBUG = 0; | |||||||||
| 34 | 2 | our $VERSION = '4.38'; | |||||||||
| 35 | |||||||||||
| 36 | # Named Constants for column positions | ||||||||||
| 37 | 2 | ▶ | use constant NAME => 0; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 38 | 2 | ▶ | use constant XPIX => 1; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 39 | 2 | ▶ | use constant YPIX => 2; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 40 | 2 | ▶ | use constant RA => 3; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 41 | 2 | ▶ | use constant DEC => 4; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 42 | 2 | ▶ | use constant EQUINOX => 5; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 43 | 2 | ▶ | use constant ANGLE => 6; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 44 | 2 | ▶ | use constant PEAK => 7; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 45 | 2 | ▶ | use constant BACKGROUND => 8; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 46 | 2 | ▶ | use constant FWHM_X => 9; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 47 | 2 | ▶ | use constant FWHM_Y => 11; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 48 | |||||||||||
| 49 | =begin __PRIVATE_METHODS__ | ||||||||||
| 50 | |||||||||||
| 51 | =head1 Private Methods | ||||||||||
| 52 | |||||||||||
| 53 | These methods are usually called automatically from the C<Astro::Catalog> | ||||||||||
| 54 | constructor. | ||||||||||
| 55 | |||||||||||
| 56 | =over 4 | ||||||||||
| 57 | |||||||||||
| 58 | =item B<_read_catalog> | ||||||||||
| 59 | |||||||||||
| 60 | Read contents of a GaiaPick log file. | ||||||||||
| 61 | |||||||||||
| 62 | $cat = Astro::Catalog::IO::TST->_read_catalog(\@lines); | ||||||||||
| 63 | |||||||||||
| 64 | =cut | ||||||||||
| 65 | |||||||||||
| 66 | 1 | ▶ | sub _read_catalog { | ||||||||
|
Subroutine
_read_catalog: called CC=6 SCAR=18.1
| |||||||||||
| 67 | 1 | my $class = shift; | |||||||||
| 68 | 1 | my $lines = shift; | |||||||||
| 69 | |||||||||||
| 70 | # Local copy of array [may be a problem for very large catalogs] | ||||||||||
| 71 | 1 | my @lines = @$lines; | |||||||||
| 72 | |||||||||||
| 73 | # Remove the first line from the array | ||||||||||
| 74 | # without trying to parse the column names | ||||||||||
| 75 | # We have defined indices at the top. | ||||||||||
| 76 | 1 | shift(@lines); | |||||||||
| 77 | |||||||||||
| 78 | # Somewhere to put the stars | ||||||||||
| 79 | 1 | my @stars; | |||||||||
| 80 | |||||||||||
| 81 | # Star ID [integer] | ||||||||||
| 82 | 1 | my $currid = 0; | |||||||||
| 83 | |||||||||||
| 84 | # Loop through the array until we run out of lines | ||||||||||
| 85 | # Expect lines to be read in pairs | ||||||||||
| 86 | 1 | ▶ | while (scalar(@lines) >= 2) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 87 | 2 | my $tstamp = shift(@lines); | |||||||||
| 88 | 2 | my $pickline = shift(@lines); | |||||||||
| 89 | |||||||||||
| 90 | # Skip if we have a blank line [should be rare] | ||||||||||
| 91 | 2 | ▶ | next unless defined $tstamp; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 92 | 2 | ▶ | next unless defined $pickline; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 93 | 2 | ▶ | next unless $pickline =~ /\d/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 94 | 2 | ▶ | next unless $tstamp =~ /\d/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 95 | |||||||||||
| 96 | # Parse the time stamp. Need to work out where to put the | ||||||||||
| 97 | # time since this is not an observation date (epoch). | ||||||||||
| 98 | # Think of a concept for Astro::Catalog::Item | ||||||||||
| 99 | # catalogDate ?? | ||||||||||
| 100 | |||||||||||
| 101 | # Parse the actual star information. Split on space. | ||||||||||
| 102 | 2 | my @chunks = split(/\s+/, $pickline); | |||||||||
| 103 | |||||||||||
| 104 | # The first column refers to the file name so is | ||||||||||
| 105 | # effectively the field ID. | ||||||||||
| 106 | |||||||||||
| 107 | # We need to create our own unique star ID for now. | ||||||||||
| 108 | # Use an integer starting at 1. | ||||||||||
| 109 | 2 | $currid ++; | |||||||||
| 110 | |||||||||||
| 111 | # Coordinate object | ||||||||||
| 112 | 2 | my $c = new Astro::Coords( | |||||||||
| 113 | name => $currid, | ||||||||||
| 114 | ra => $chunks[RA], | ||||||||||
| 115 | dec => $chunks[DEC], | ||||||||||
| 116 | type => $chunks[EQUINOX], | ||||||||||
| 117 | units => 'sex', | ||||||||||
| 118 | ); | ||||||||||
| 119 | |||||||||||
| 120 | 2 | my $star = new Astro::Catalog::Item( | |||||||||
| 121 | ID => $currid, | ||||||||||
| 122 | Field => $chunks[0], | ||||||||||
| 123 | Coords => $c, | ||||||||||
| 124 | X => $chunks[XPIX], | ||||||||||
| 125 | Y => $chunks[YPIX], | ||||||||||
| 126 | ); | ||||||||||
| 127 | |||||||||||
| 128 | 2 | push @stars, $star; | |||||||||
| 129 | } | ||||||||||
| 130 | |||||||||||
| 131 | 1 | my $cat = new Astro::Catalog( | |||||||||
| 132 | Stars => \@stars, | ||||||||||
| 133 | Origin => 'GaiaPick', | ||||||||||
| 134 | ); | ||||||||||
| 135 | } | ||||||||||
| 136 | |||||||||||
| 137 | 2 | 1; | |||||||||
| 138 | |||||||||||
| 139 | __END__ | ||||||||||