Astro/Catalog/Query/USNOA2.pm

filter: Statementstmt 41.3% 43 / 104 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 94.1% 16 / 17 Podpod n/a totaltotal 40.4% 59 / 146 CC 13 SCAR 44.1
CC
13
Cov
34%
_parse_query
182.0
BEGIN
1.0
BEGIN
1.0
CRAP 82.1
« Astro/Catalog.pm ↑ Summary Astro/Catalog/IO/JCMT.pm »
1 package Astro::Catalog::Query::USNOA2;
2  
3 =head1 NAME
4  
5 Astro::Catalog::Query::USNOA2 - A query request to the USNO-A2.0 Catalog
6  
7 =head1 SYNOPSIS
8  
9 $usno = new Astro::Catalog::Query::USNOA2(
10 Coords => new Astro::Coords(),
11 Radius => $radius,
12 Bright => $magbright,
13 Faint => $magfaint,
14 Sort => $sort_type,
15 Number => $number_out);
16  
17 my $catalog = $usno->querydb();
18  
19 =head1 DESCRIPTION
20  
21 The module is an object orientated interface to the online USNO-A2.0
22 catalog at the ESO/ST-ECF archive site.
23  
24 Stores information about an prospective USNO-A2.0 query and allows the query to
25 be made, returning an Astro::Catalog::USNOA2::Catalog object.
26  
27 The object will by default pick up the proxy information from the HTTP_PROXY
28 and NO_PROXY environment variables, see the LWP::UserAgent documentation for
29 details.
30  
31 See L<Astro::Catalog::BaseQuery> for the catalog-independent methods.
32  
33 =cut
34  
35 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 2 ▶use base qw/Astro::Catalog::Transport::REST/;
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 2 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 2 ▶use Astro::Coords;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 2 ▶use Astro::Catalog;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 2 ▶use Astro::Catalog::Item;
Subroutine BEGIN: called CC=1 SCAR=0.0
45  
46 2 ▶use Astro::Flux;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 2 ▶use Astro::Fluxes;
Subroutine BEGIN: called CC=1 SCAR=0.0
48 2 ▶use Astro::FluxColor;
Subroutine BEGIN: called CC=1 SCAR=0.0
49 2 ▶use Number::Uncertainty;
Subroutine BEGIN: called CC=1 SCAR=0.0
50  
51 2 our $VERSION = '4.38';
52  
53 =begin __PRIVATE_METHODS__
54  
55 =head2 Private methods
56  
57 These methods are for internal use only.
58  
59 =over 4
60  
61 =item B<_default_remote_host>
62  
63 =cut
64  
65 1 ▶sub _default_remote_host {
Subroutine _default_remote_host: called CC=1 SCAR=0.0
66 1 return "archive.eso.org";
67 }
68  
69 =item B<_default_url_path>
70  
71 =cut
72  
73 1 ▶sub _default_url_path {
Subroutine _default_url_path: called CC=1 SCAR=0.0
74 1 return "skycat/servers/usnoa_res?";
75 }
76  
77 =item B<_get_allowed_options>
78  
79 Returns a hash with keys, being the internal options supported
80 by this subclass, and values being the key name actually required
81 by the remote system (and to be included in the query).
82  
83 =cut
84  
85 21 ▶sub _get_allowed_options {
Subroutine _get_allowed_options: called CC=1 SCAR=0.0
86 21 my $self = shift;
87 return (
88 21 ra => 'ra',
89 dec => 'dec',
90 object => 'object',
91 radmax => 'radmax',
92 magbright => 'magbright',
93 magfaint => 'magfaint',
94 sort => 'sort',
95 nout => 'nout',
96 format => 'format',
97 );
98 }
99  
100 =item B<_get_default_options>
101  
102 Get the default query state.
103  
104 =cut
105  
106 1 ▶sub _get_default_options {
Subroutine _get_default_options: called CC=1 SCAR=0.0
107 return (
108 1 ra => undef,
109 dec => undef,
110 object => undef,
111  
112 radmax => 5,
113 magbright => 0,
114 magfaint => 100,
115 format => 1,
116 sort => 'RA',
117 nout => 2000,
118 );
119 }
120  
121 =item B<_parse_query>
122  
123 Private function used to parse the results returned in an USNO-A2.0 query.
124 Should not be called directly. Instead use the querydb() assessor method to
125 make and parse the results.
126  
127 =cut
128  
129 0 ▶sub _parse_query {
Subroutine _parse_query: not called CC=13 SCAR=52.0
130 0 my $self = shift;
131  
132 # get a local copy of the current BUFFER
133 0 my @buffer = split /\n/, $self->{BUFFER};
134 0 chomp @buffer;
135  
136 # create an Astro::Catalog object to hold the search results
137 0 my $catalog = new Astro::Catalog();
138  
139 # create a temporary object to hold stars
140 0 my $star;
141  
142 0 my ($line, $counter);
143  
144 # Read field centre a line at a time and store it outside the loop
145 0 my %field;
146  
147 # loop round the returned buffer and stuff the contents into star objects
148 0 foreach $line (0 ... $#buffer) {
149 # Parse field centre
150  
151 # RA
152 0 ▶ if (lc($buffer[$line]) =~ "<td>ra:") {
Branch: 1 branch
BranchTrueFalseTotal
if (lc($buffer[$line]) =~ /<td>ra:/) 0 0 0
153 0 $_ = lc($buffer[$line]);
154 0 my ( $ra ) = /^\s*<td>ra:\s+(.*)<\/td>/;
155 0 $field{RA} = $ra;
156 }
157  
158 # Dec
159 0 ▶ if( lc($buffer[$line]) =~ "<td>dec:" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc($buffer[$line]) =~ /<td>dec:/) 0 0 0
160 0 $_ = lc($buffer[$line]);
161 0 my ( $dec ) = /^\s+<td>dec:\s+(.*)<\/td>/;
162 0 $field{Dec} = $dec;
163 }
164  
165 # Radius
166 0 ▶ if( lc($buffer[$line]) =~ "search radius:" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc($buffer[$line]) =~ /search radius:/) 0 0 0
167 0 $_ = lc($buffer[$line+1]);
168 0 my ( $radius ) = />\s+(.*)\s\w/;
169 0 $field{Radius} = $radius;
170 }
171  
172 # Parse list of objects
173  
174 0 ▶ if( lc($buffer[$line]) =~ "<pre>" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc($buffer[$line]) =~ /<pre>/) 0 0 0
175  
176 # reached the catalog block, loop through until </pre> reached
177 0 $counter = $line+2;
178 0 ▶ until ( lc($buffer[$counter+1]) =~ "</pre>" ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (lc($buffer[$counter + 1]) =~ m[</pre>]) 0 0 0
179  
180 # hack for first line, remove </b>
181 0 ▶ if ( lc($buffer[$counter]) =~ "</b>" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc($buffer[$counter]) =~ m[</b>]) 0 0 0
182 0 $buffer[$counter] = substr( $buffer[$counter], 5);
183 }
184  
185 # remove leading spaces
186 0 $buffer[$counter] =~ s/^\s+//;
187  
188 # split each line
189 0 my @separated = split( /\s+/, $buffer[$counter] );
190  
191 # check that there is something on the line
192 0 ▶ if (defined $separated[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $separated[0]) 0 0 0
193 # create a temporary place holder object
194 0 $star = new Astro::Catalog::Item();
195  
196 # ID
197 0 my $id = $separated[1];
198 0 $star->id( $id );
199  
200 # RA
201 0 my $objra = "$separated[2] $separated[3] $separated[4]";
202  
203 # Dec
204 0 my $objdec = "$separated[5] $separated[6] $separated[7]";
205  
206 # only generate coordinates if the seconds field of the
207 # dec isn't 60.0, if it is, lets just dump this star as
208 # currently the Astro::Coords object gives totally bogus
209 # answers due to the bogus answers its getting from SLALIB.
210 0 ▶ unless ($separated[7] == 60 || $separated[4] == 60) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($separated[7] == 60 or $separated[4] == 60) 0 0 0
Condition0%0/3
$separated[7] == 60 or $separated[4] == 60
l!l&&r!l&&!r
000
MC/DC0%0/2
$separated[7] == 60 or $separated[4] == 60
$separated[7] == 60 $separated[4] == 60
Truth table0%0/3
A or B
A= $separated[7] == 60B= $separated[4] == 60
ABresult
1X1
011
000
211 0 $star->coords(new Astro::Coords(
212 ra => $objra,
213 dec => $objdec,
214 units => 'sex',
215 type => 'J2000',
216 name => $star->id(),
217 ));
218 }
219  
220 # Quality
221 0 my $quality = $separated[10];
222 0 $star->quality( $quality );
223  
224 # Field
225 0 my $field = $separated[11];
226 0 $star->field( $field );
227  
228 # GSC
229 0 my $gsc = $separated[12];
230 0 ▶ if ($gsc eq "+") {
Branch: 1 branch
BranchTrueFalseTotal
if ($gsc eq '+') { } 0 0 0
231 0 $star->gsc("TRUE");
232 }
233 else {
234 0 $star->gsc("FALSE");
235 }
236  
237 # Distance
238 0 my $distance = $separated[13];
239 0 $star->distance( $distance );
240  
241 # Position Angle
242 0 my $pos_angle = $separated[14];
243 0 $star->posangle( $pos_angle );
244 }
245  
246 # Calculate error
247  
248 # Error are calculated as follows
249 #
250 # Delta.R = 0.15*sqrt( 1 + 10**(0.8*(R-19)) )
251 # Delta.B = 0.15*sqrt( 1 + 10**(0.8*(B-19)) )
252 0 my ($power, $delta_r, $delta_b);
253  
254 # delta.R
255 0 $power = 0.8*( $separated[8] - 19.0 );
256 0 $delta_r = 0.15* (( 1.0 + ( 10.0 ** $power ) ) ** (1.0/2.0));
257  
258 # delta.B
259 0 $power = 0.8*( $separated[9] - 19.0 );
260 0 $delta_b = 0.15* (( 1.0 + ( 10.0 ** $power ) ) ** (1.0/2.0));
261  
262  
263 # calcuate B-R colour and error
264  
265 # Error is calculated as follows
266 #
267 # Delta.(B-R) = sqrt( Delta.R**2 + Delta.B**2 )
268  
269 0 my $b_minus_r = $separated[9] - $separated[8];
270  
271 # delta.(B-R)
272 0 my $delta_bmr = ( ( $delta_r ** 2.0 ) + ( $delta_b ** 2.0 ) ) ** (1.0/2.0);
273  
274 0 $star->fluxes(new Astro::Fluxes(
275 new Astro::Flux(
276 new Number::Uncertainty(
277 Value => $separated[8],
278 Error => $delta_r ),
279 'mag', "R"),
280 new Astro::Flux(
281 new Number::Uncertainty(
282 Value => $separated[9],
283 Error => $delta_b),
284 'mag', "B"),
285 new Astro::FluxColor(
286 lower => "R",
287 upper => "B",
288 quantity => new Number::Uncertainty(
289 Value => $b_minus_r,
290 Error => $delta_bmr)),
291 ));
292  
293 # Push the star into the catalog
294  
295 # only push the star if the Astro::Coords object is
296 # correctly defined. The Dec might be bogus since the
297 # USNO-A2 catalog has its seconds field out of
298 # normal range (0-59.9) in some cases.
299 0 ▶ if ($star->coords()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($star->coords) 0 0 0
300 0 $catalog->pushstar($star);
301 }
302  
303 # increment counter
304 0 $counter = $counter + 1;
305 }
306  
307 # reset $line to correct place
308 0 $line = $counter;
309 }
310 }
311  
312 # set the field centre
313 0 $catalog->fieldcentre(%field);
314  
315 0 return $catalog;
316 }
317  
318 =back
319  
320 =head2 Translation Methods
321  
322 The query options stored internally in the object are not necessarily
323 the form required for a query to a remote server. Methods for converting
324 from the internal representation to the external query format are
325 provided in the form of _from_$opt. ie:
326  
327 ($outkey, $outvalue) = $q->_from_ra();
328 ($outkey, $outvalue) = $q->_from_object();
329  
330 Currently translations are a bit thin on the ground...
331  
332 =cut
333  
334 # None special for subclass
335  
336 2 1;
337  
338 __END__
« Astro/Catalog.pm ↑ Summary Astro/Catalog/IO/JCMT.pm »