Astro/Catalog/IO/JCMT_OT_SC.pm

filter: Statementstmt 24.7% 30 / 121 Branchbran 0.0% 0 / 56 Conditioncond 0.0% 0 / 27 MC/DCmcdc 0.0% 0 / 18 Subroutinesub 81.8% 9 / 11 Podpod n/a totaltotal 16.7% 39 / 233 CC 40 SCAR 59.3
CC
40
Cov
15%
_read_catalog
552.0
_write_catalog
342.0
BEGIN
1.0
CRAP 377.2
« Astro/Catalog/IO/TST.pm ↑ Summary Astro/Catalog/Query/2MASS.pm »
1 package Astro::Catalog::IO::JCMT_OT_SC;
2  
3 =head1 NAME
4  
5 Astro::Catalog::IO::JCMT_OT_SC - JCMT OT Survey Container format catalog parser
6  
7 =cut
8  
9 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use warnings::register;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 ▶use Astro::Telescope;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Astro::Coords;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Astro::Catalog;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Astro::Catalog::Item;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 1 ▶use parent qw/Astro::Catalog::IO::ASCII/;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 1 our $VERSION = '4.38';
23  
24 1 our $BASE_TAG = 'SCIENCE';
25  
26 =head1 METHODS
27  
28 =over 4
29  
30 =item B<_read_catalog>
31  
32 Parses the catalog lines and returns a new C<Astro::Catalog> object.
33  
34 $cat = Astro::Catalog::IO::JCMT_OT_SC->_read_catalog(\@lines, %options);
35  
36 Options:
37  
38 =over 4
39  
40 =item telescope
41  
42 Name of telescope to associate with each entry. [Default: JCMT]
43  
44 =item tag
45  
46 Only read targets with the given tag, e.g. SCIENCE. [Default: read all tags]
47  
48 =back
49  
50 =cut
51  
52 0 ▶sub _read_catalog {
Subroutine _read_catalog: not called CC=23 SCAR=63.1
53 0 my $class = shift;
54 0 my $lines = shift;
55  
56 0 my %default = (
57 telescope => 'JCMT',
58 );
59  
60 0 my %options = (%default, @_);
61  
62 0 ▶ croak "_read_catalog: catalog lines must be an array reference"
Branch: 1 branch
BranchTrueFalseTotal
unless "ARRAY" eq ref $lines 0 0 0
63 unless 'ARRAY' eq ref $lines;
64  
65 0 my $tel = undef;
66 $tel = new Astro::Telescope($options{'telescope'})
67 0 ▶ if defined $options{'telescope'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $options{"telescope"} 0 0 0
68  
69 0 my $selected_tag = undef;
70 0 ▶ if (exists $options{'tag'} and defined $options{'tag'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $options{"tag"} and defined $options{"tag"}) 0 0 0
Condition0%0/3
exists $options{"tag"} and defined $options{"tag"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $options{"tag"} and defined $options{"tag"}
exists $options{"tag"} defined $options{"tag"}
Truth table0%0/3
A and B
A= exists $options{"tag"}B= defined $options{"tag"}
ABresult
0X0
100
111
71 0 $selected_tag = $options{'tag'};
72 }
73  
74 0 my @items;
75 0 my %cat_misc = ();
76  
77 0 foreach my $line (@$lines) {
78 0 $line =~ s/^\s+//;
79 0 $line =~ s/\s+$//;
80 0 ▶ next unless $line;
Branch: 1 branch
BranchTrueFalseTotal
unless $line 0 0 0
81  
82 0 ▶ if ($line =~ /^SURVEY_?ID/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^SURVEY_?ID/) 0 0 0
83 0 my (undef, $survey_id) = split /[:=]/, $line, 2;
84 0 $survey_id =~ s/^\s+//;
85  
86 0 ▶ $cat_misc{'survey_id'} = $survey_id if $survey_id;
Branch: 1 branch
BranchTrueFalseTotal
if $survey_id 0 0 0
87  
88 0 next;
89 }
90  
91 0 my ($tag, $name, $x, $y, $coord_sys, $pos_in_tile,
92 $remaining, $priority, @extra) = split /[ ,;]+/, $line;
93  
94 0 my %opt = (
95 name => $name,
96 );
97 0 my %misc = (
98 tag => $tag,
99 );
100  
101 0 my @dec_units;
102 0 ▶ if ($coord_sys eq 'FK5' or $coord_sys eq 'J2000') {
Branch: 3 branches
BranchTrueFalseTotal
if ($coord_sys eq 'FK5' or $coord_sys eq 'J2000') { } 0 0 0
elsif ($coord_sys eq 'FK4' or $coord_sys eq 'B1950') { } 0 0 0
elsif ($coord_sys =~ /^GAL/) { } 0 0 0
Condition0%0/3
$coord_sys eq "FK5" or $coord_sys eq "J2000"
l!l&&r!l&&!r
000
MC/DC0%0/2
$coord_sys eq "FK5" or $coord_sys eq "J2000"
$coord_sys eq "FK5" $coord_sys eq "J2000"
Truth table0%0/3
A or B
A= $coord_sys eq "FK5"B= $coord_sys eq "J2000"
ABresult
1X1
011
000
103 0 $opt{'type'} = 'J2000';
104 0 $opt{'ra'} = $x;
105 0 $opt{'dec'} = $y;
106 0 @dec_units = ('hours', 'degrees');
107 }
108 ▶ elsif ($coord_sys eq 'FK4' or $coord_sys eq 'B1950') {
Condition0%0/3
$coord_sys eq "FK4" or $coord_sys eq "B1950"
l!l&&r!l&&!r
000
MC/DC0%0/2
$coord_sys eq "FK4" or $coord_sys eq "B1950"
$coord_sys eq "FK4" $coord_sys eq "B1950"
Truth table0%0/3
A or B
A= $coord_sys eq "FK4"B= $coord_sys eq "B1950"
ABresult
1X1
011
000
109 0 $opt{'type'} = 'B1950';
110 0 $opt{'ra'} = $x;
111 0 $opt{'dec'} = $y;
112 0 @dec_units = ('hours', 'degrees');
113 }
114 elsif ($coord_sys =~ /^GAL/) {
115 0 $opt{'type'} = 'galactic';
116 0 $opt{'long'} = $x;
117 0 $opt{'lat'} = $y;
118 0 @dec_units = ('degrees', 'degrees');
119 }
120 else {
121 0 die "Did not recognize coordinate system '$coord_sys'";
122 }
123  
124 0 ▶ $opt{'units'} = [
Branch: 2 branches
BranchTrueFalseTotal
$x =~ /:/ ? : 0 0 0
$y =~ /:/ ? : 0 0 0
125 (($x =~ /:/) ? 'sexagesimal' : $dec_units[0]),
126 (($y =~ /:/) ? 'sexagesimal' : $dec_units[1])];
127  
128 0 my $c = new Astro::Coords(%opt);
129  
130 0 ▶ $c->telescope($tel) if defined $tel;
Branch: 1 branch
BranchTrueFalseTotal
if defined $tel 0 0 0
131  
132 # The OT only processes the extra columns for base positions.
133 0 ▶ if ($tag eq $BASE_TAG) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag eq $Astro::Catalog::IO::JCMT_OT_SC::BASE_TAG) 0 0 0
134 0 ▶ if (defined $pos_in_tile) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pos_in_tile) 0 0 0
135 0 $misc{'position_in_tile'} = 0 + $pos_in_tile;
136 }
137 0 ▶ if (defined $priority) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $priority) 0 0 0
138 0 $misc{'priority'} = 0 + $priority;
139 }
140 0 ▶ if (defined $remaining) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $remaining) 0 0 0
141 0 $misc{'remaining'} = 0 + $remaining;
142 }
143 }
144  
145 0 ▶ if ((not defined $selected_tag) or ($tag eq $selected_tag)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $selected_tag or $tag eq $selected_tag) 0 0 0
Condition0%0/3
not defined $selected_tag or $tag eq $selected_tag
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $selected_tag or $tag eq $selected_tag
not defined $selected_tag $tag eq $selected_tag
Truth table0%0/3
not(A) or B
A= not defined $selected_tagB= $tag eq $selected_tag
ABresult
1X1
011
000
146 0 push @items, new Astro::Catalog::Item(
147 id => $name,
148 coords => $c,
149 misc => \%misc,
150 );
151 }
152 }
153  
154 0 return new Astro::Catalog(Stars => \@items, Misc => \%cat_misc);
155 }
156  
157 =item B<_write_catalog>
158  
159 Write the catalog to an array of lines.
160  
161 $lines = Astro::Catalog::IO::JCMT_OT_SC->_write_catalog($cat);
162  
163 =cut
164  
165 0 ▶sub _write_catalog {
Subroutine _write_catalog: not called CC=18 SCAR=58.3
166 0 my $class = shift;
167 0 my $cat = shift;
168  
169 0 my @lines;
170  
171 0 my $cat_misc = $cat->misc;
172 0 ▶ if (defined $cat_misc) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cat_misc) 0 0 0
173 0 ▶ if (exists $cat_misc->{'survey_id'} and defined $cat_misc->{'survey_id'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $cat_misc->{"survey_id"} and defined $cat_misc->{"survey_id"}) 0 0 0
Condition0%0/3
exists $cat_misc->{"survey_id"} and defined $cat_misc->{"survey_id"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $cat_misc->{"survey_id"} and defined $cat_misc->{"survey_id"}
exists $cat_misc->{"survey_id"} defined $cat_misc->{"survey_id"}
Truth table0%0/3
A and B
A= exists $cat_misc->{"survey_id"}B= defined $cat_misc->{"survey_id"}
ABresult
0X0
100
111
174 0 push @lines, sprintf 'SURVEYID = %s', $cat_misc->{'survey_id'};
175 }
176 }
177  
178 0 for my $item ($cat->stars) {
179 0 my $coords = $item->coords;
180 0 my $name = $coords->name;
181 0 my $type = $coords->type;
182 0 my $misc = $item->misc;
183 0 ▶ $misc = {} unless defined $misc;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $misc 0 0 0
184  
185 0 ▶ if ($type eq 'RADEC') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'RADEC') { } 0 0 0
186 0 my ($x, $y, $type);
187 0 ▶ unless ('glonglat' eq $coords->native) {
Branch: 1 branch
BranchTrueFalseTotal
if ('glonglat' eq $coords->native) { } 0 0 0
188 0 $type = 'FK5';
189 0 $x = $coords->ra(format => 'sexagesimal');
190 0 $y = $coords->dec(format => 'sexagesimal');
191 }
192 else {
193 0 $type = 'GAL';
194 0 my ($lon, $lat) = $coords->glonglat();
195 0 $x = $lon->in_format('sexagesimal');
196 0 $y = $lat->in_format('sexagesimal');
197 }
198  
199 0 $x =~ s/^\s//;
200 0 $y =~ s/^\s//;
201  
202 my $tag = (exists $misc->{'tag'} and defined $misc->{'tag'})
203 0 ▶ ? $misc->{'tag'} : 'SCIENCE';
Branch: 1 branch
BranchTrueFalseTotal
exists $misc->{'tag'} && defined $misc->{'tag'} ? : 0 0 0
Condition0%0/3
exists $misc->{"tag"} and defined $misc->{"tag"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $misc->{"tag"} and defined $misc->{"tag"}
exists $misc->{"tag"} defined $misc->{"tag"}
Truth table0%0/3
A and B
A= exists $misc->{"tag"}B= defined $misc->{"tag"}
ABresult
0X0
100
111
204  
205 # Fill in extra columns right to left, so that we can set defaults
206 # for any undefined values in columns to the left of defined ones.
207 0 my @extra = ();
208 0 ▶ if (exists $misc->{'priority'} and defined $misc->{'priority'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $misc->{"priority"} and defined $misc->{"priority"}) 0 0 0
Condition0%0/3
exists $misc->{"priority"} and defined $misc->{"priority"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $misc->{"priority"} and defined $misc->{"priority"}
exists $misc->{"priority"} defined $misc->{"priority"}
Truth table0%0/3
A and B
A= exists $misc->{"priority"}B= defined $misc->{"priority"}
ABresult
0X0
100
111
209 0 unshift @extra, $misc->{'priority'};
210 }
211 0 ▶ if (exists $misc->{'remaining'} and defined $misc->{'remaining'}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $misc->{'remaining'} and defined $misc->{'remaining'}) { } 0 0 0
elsif (@extra) { } 0 0 0
Condition0%0/3
exists $misc->{"remaining"} and defined $misc->{"remaining"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $misc->{"remaining"} and defined $misc->{"remaining"}
exists $misc->{"remaining"} defined $misc->{"remaining"}
Truth table0%0/3
A and B
A= exists $misc->{"remaining"}B= defined $misc->{"remaining"}
ABresult
0X0
100
111
212 0 unshift @extra, $misc->{'remaining'};
213 }
214 elsif (@extra) {
215 0 unshift @extra, 1;
216 }
217 0 ▶ if (exists $misc->{'position_in_tile'} and defined $misc->{'position_in_tile'}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $misc->{'position_in_tile'} and defined $misc->{'position_in_tile'}) { } 0 0 0
elsif (@extra) { } 0 0 0
Condition0%0/3
exists $misc->{"position_in_tile"} and defined $misc->{"position_in_tile"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $misc->{"position_in_tile"} and defined $misc->{"position_in_tile"}
exists $misc->{"position_in_tile"} defined $misc->{"position_in_tile"}
Truth table0%0/3
A and B
A= exists $misc->{"position_in_tile"}B= defined $misc->{"position_in_tile"}
ABresult
0X0
100
111
218 0 unshift @extra, $misc->{'position_in_tile'};
219 }
220 elsif (@extra) {
221 0 unshift @extra, -1;
222 }
223  
224 # Remove separators ( ,;) and other possibly problematic characters from name.
225 0 $name =~ s/[^-()+.0-9:=A-Z_a-z]/_/g;
226  
227 0 push @lines, join ' ', $tag, $name, $x, $y, $type, @extra;
228 }
229 else {
230 0 warnings::warnif "Coordinate of type '$type' for target '$name' not currently supported\n";
231 }
232 }
233  
234 0 return \@lines;
235 }
236  
237 1 1;
238  
239 __END__
« Astro/Catalog/IO/TST.pm ↑ Summary Astro/Catalog/Query/2MASS.pm »