Astro/Catalog/IO/ASSM.pm

filter: Statementstmt 34.3% 33 / 96 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 90.9% 10 / 11 Podpod n/a totaltotal 29.2% 43 / 147 CC 22 SCAR 58.5
CC
22
Cov
25%
_read_catalog
506.0
BEGIN
1.0
BEGIN
1.0
CRAP 348.2
« Astro/Catalog/Query/2MASS.pm ↑ Summary Astro/Catalog/IO/Binary.pm »
1 package Astro::Catalog::IO::ASSM;
2  
3 =head1 NAME
4  
5 Astro::Catalog::IO::ASSM - AJP ASSM format
6  
7 =head1 SYNOPSIS
8  
9 $catalog = Astro::Catalog::IO::ASSM->_read_catalog(\@lines);
10  
11 =head1 DESCRIPTION
12  
13 Performs simple IO, reading or writing "id_string hh mm ss.s +dd mm ss.s"
14 formated strings for each Astro::Catalog::Item object in the catalog.
15  
16 =cut
17  
18 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use warnings::register;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 1 ▶use Astro::Catalog;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use Astro::Catalog::Item;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use Astro::Coords;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use Astro::Flux;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use Astro::Fluxes;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 1 ▶use base qw/Astro::Catalog::IO::ASCII/;
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 1 our $VERSION = '4.38';
32 1 our $DEBUG = 0;
33  
34 =head1 METHODS
35  
36 =head2 Private methods
37  
38 These methods are for internal use only and are called from the
39 Astro::Catalog module. It is not expected that anyone would want to
40 call them from outside that module.
41  
42 =over 4
43  
44 =item B<_read_catalog>
45  
46 Parses a reference to an array containing a simply formatted catalog
47  
48 $catalog = Astro::Catalog::IO::ASSM->_read_catalog(\@lines);
49  
50 =cut
51  
52 0 ▶sub _read_catalog {
Subroutine _read_catalog: not called CC=22 SCAR=62.3
53 0 my $class = shift;
54 0 my $arg = shift;
55 0 my @lines = @{$arg};
56  
57 # create an Astro::Catalog object;
58 0 my $catalog = new Astro::Catalog();
59  
60 # loop through lines
61 0 my $starnum = 1;
62 0 my $hdrnotprocessed = 1;
63 0 my @allfilters;
64  
65 0 foreach my $i (0 .. $#lines) {
66 # Skip commented and blank lines
67 0 ▶ next if ($lines[$i] =~ /^\s*[\#*%]/);
Branch: 1 branch
BranchTrueFalseTotal
if $lines[$i] =~ /^\s*[\#*%]/ 0 0 0
68 0 ▶ next if ($lines[$i] =~ /^\s*$/);
Branch: 1 branch
BranchTrueFalseTotal
if $lines[$i] =~ /^\s*$/ 0 0 0
69  
70 0 ▶ print $lines[$i]."\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Astro::Catalog::IO::ASSM::DEBUG 0 0 0
71  
72 # We need the last line of the header as it has the fieldnames, including
73 # the filters
74 0 ▶ if ($hdrnotprocessed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hdrnotprocessed) 0 0 0
75 0 ▶ print "Header processing\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Astro::Catalog::IO::ASSM::DEBUG 0 0 0
76  
77 # Extract last line of header, strip off the hash and any starting
78 # whitespace and then split into fields
79 0 my $colhdr = $lines[$i-1];
80 0 $colhdr =~ s/^\s*#//g;
81 0 my @hdrfields = split(/\s+/, $colhdr);
82  
83 # Determine which columns are filters...
84 0 my $idx = 0;
85 0 my $first_filter_idx =0;
86 0 my $last_filter_idx =0;
87 0 foreach my $colname (@hdrfields) {
88 0 ▶ if ($colname eq 'DECdeg') {
Branch: 2 branches
BranchTrueFalseTotal
if ($colname eq 'DECdeg') { } 0 0 0
elsif ($colname eq 'sptyp') { } 0 0 0
89 # We've found the leftmost edge of the filter columns
90 0 $first_filter_idx = $idx + 1;
91 }
92 elsif ($colname eq 'sptyp') {
93 # We've found the rightmost edge of the filter columns
94 0 $last_filter_idx = $idx - 1;
95 }
96 0 $idx++;
97 }
98  
99 0 @allfilters = @hdrfields[$first_filter_idx .. $last_filter_idx];
100 0 ▶ print "Found " . @allfilters . " Filters\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Astro::Catalog::IO::ASSM::DEBUG 0 0 0
101 0 for my $f (@allfilters) {
102 0 ▶ print "filter was: $f\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Astro::Catalog::IO::ASSM::DEBUG 0 0 0
103 }
104 0 $hdrnotprocessed = 0;
105 }
106 0 my @fields = split(/\s+/, $lines[$i]);
107 0 my $ra_value = $fields[0];
108 0 my $dec_value = $fields[1];
109  
110 # Skip if the 3rd entry is 'NoStars' or there aren't the right number of fields
111 0 ▶ next if $fields[2] eq 'NoStars' or @fields != @allfilters + 4;
Branch: 1 branch
BranchTrueFalseTotal
if $fields[2] eq "NoStars" or @fields != @allfilters + 4 0 0 0
Condition0%0/3
$fields[2] eq "NoStars" or @fields != @allfilters + 4
l!l&&r!l&&!r
000
MC/DC0%0/2
$fields[2] eq "NoStars" or @fields != @allfilters + 4
$fields[2] eq "NoStars" @fields != @allfilters + 4
Truth table0%0/3
A or B
A= $fields[2] eq "NoStars"B= @fields != @allfilters + 4
ABresult
1X1
011
000
112  
113 0 my $star = new Astro::Catalog::Item();
114 # Set up the Astro::Coords object, assuming our RA and Dec are in units
115 # of degrees.
116  
117 0 my $coords;
118 0 ▶ if (defined($ra_value) && defined($dec_value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ra_value and defined $dec_value) 0 0 0
Condition0%0/3
defined $ra_value and defined $dec_value
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ra_value and defined $dec_value
defined $ra_value defined $dec_value
Truth table0%0/3
A and B
A= defined $ra_valueB= defined $dec_value
ABresult
0X0
100
111
119 0 $coords = new Astro::Coords(
120 ra => $ra_value,
121 dec => $dec_value,
122 units => 'degrees',
123 type => 'J2000',
124 );
125 }
126  
127 0 ▶ croak "Error creating coordinate object from $ra_value / $dec_value "
Branch: 1 branch
BranchTrueFalseTotal
unless defined $coords 0 0 0
128 unless defined $coords;
129  
130 # and push it into the Astro::Catalog::Item object
131 0 $star->coords($coords);
132  
133 # Go through the passbands and create the Astro::Flux object for
134 # this magnitude.
135 0 my $waveband;
136 0 my $filtnum = 2;
137 0 my @mags;
138 0 foreach my $filter (@allfilters) {
139 0 ▶ print "Filter=$filter, " if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Astro::Catalog::IO::ASSM::DEBUG 0 0 0
140 0 $waveband = new Astro::WaveBand(Filter => $filter);
141 # Create the Astro::Flux object for this magnitude.
142 0 my $flux = new Astro::Flux(
143 new Number::Uncertainty(Value => $fields[$filtnum]),
144 'MAG_CATALOG',
145 $waveband);
146 0 push @mags, $flux;
147 0 $filtnum++;
148 }
149 0 ▶ print "\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Astro::Catalog::IO::ASSM::DEBUG 0 0 0
150 0 my $fluxes = new Astro::Fluxes(@mags);
151 # and push the fluxes into the catalog
152 0 $star->fluxes($fluxes);
153 0 $star->preferred_magnitude_type('MAG_CATALOG');
154  
155 # get the sptype, strip out underscores
156 0 my $spectype = $fields[5];
157 0 $spectype =~ s/_//g;
158 0 ▶ print "Spectype=$spectype\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Astro::Catalog::IO::ASSM::DEBUG 0 0 0
159 # and push into object
160 0 $star->spectype($spectype);
161  
162 # push the source column into the Comment field
163 0 $star->comment($fields[6]);
164  
165 # push id number
166 0 $star->id($starnum);
167 # push it onto the stack
168 0 $catalog->pushstar($star);
169  
170 0 $starnum++;
171 }
172  
173 0 $catalog->origin('IO::ASSM');
174 0 return $catalog;
175 }
176  
177 1 1;
178  
179 __END__
« Astro/Catalog/Query/2MASS.pm ↑ Summary Astro/Catalog/IO/Binary.pm »