Astro/Catalog/Query/SIMBAD.pm

filter: Statementstmt 31.5% 23 / 73 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 53.8% 7 / 13 Podpod n/a totaltotal 29.4% 30 / 102 CC 8 SCAR 33.9
CC
8
Cov
27%
_parse_query
72.0
_default_remote_host
2.0
_default_url_path
2.0
CRAP 29.6
« Astro/Catalog/IO/VEX.pm ↑ Summary Astro/Catalog/Item.pm »
1 package Astro::Catalog::Query::SIMBAD;
2  
3 =head1 NAME
4  
5 Astro::Catalog::Query::SIMBAD - A query request to the SIMBAD database
6  
7 =head1 SYNOPSIS
8  
9 $sim = new Astro::Catalog::Query::SIMBAD(
10 RA => $ra,
11 Dec => $dec,
12 Radius => $radius,
13 Target => $target,
14 );
15  
16 my $catalog = $sim->querydb();
17  
18 =head1 DESCRIPTION
19  
20 The module is an object orientated interface to the online SIMBAD
21 database. Designed to return information on a single object.
22  
23 Target name overrides RA/Dec.
24  
25 The object will by default pick up the proxy information from the
26 HTTP_PROXY and NO_PROXY environment variables, see the LWP::UserAgent
27 documentation for details.
28  
29 See L<Astro::Catalog::Query> for the catalog-independent methods.
30  
31 =cut
32  
33 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 1 ▶use base qw/Astro::Catalog::Transport::REST/;
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 1 ▶use Astro::Coords;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 1 ▶use Astro::Catalog;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 1 ▶use Astro::Catalog::Item;
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 1 our $VERSION = '4.38';
44  
45 =begin __PRIVATE_METHODS__
46  
47 =head2 Private methods
48  
49 These methods are for internal use only.
50  
51 =over 4
52  
53 =item B<_default_remote_host>
54  
55 =cut
56  
57 0 ▶sub _default_remote_host {
Subroutine _default_remote_host: not called CC=1 SCAR=6.9
58 0 return "simbad.u-strasbg.fr";
59 }
60  
61 =item B<_default_url_path>
62  
63 =cut
64  
65 0 ▶sub _default_url_path {
Subroutine _default_url_path: not called CC=1 SCAR=6.9
66 0 return "sim-id.pl?";
67 }
68  
69 =item B<_get_allowed_options>
70  
71 Returns a hash with keys, being the internal options supported
72 by this subclass, and values being the key name actually required
73 by the remote system (and to be included in the query).
74  
75 =cut
76  
77 0 ▶sub _get_allowed_options {
Subroutine _get_allowed_options: not called CC=1 SCAR=6.9
78 0 my $self = shift;
79 return (
80 0 ra => 'ra',
81 dec => 'dec',
82 object => 'Ident',
83 radmax => 'Radius',
84 nout => "output.max",
85 bibyear1 => "Bibyear1",
86 bibyear2 => "Bibyear2",
87 _protocol => "protocol",
88 _nbident => "NbIdent",
89 _catall => "o.catall",
90 _mesdisp => "output.mesdisp",
91  
92 radunits => "Radius.unit", # arcsec, arcmin or deg
93  
94 # These should not be published
95 # Since we need to switch to Astro::Coords
96 _coordframe => "CooFrame", # FK5 or FK4
97 _coordepoch => "CooEpoch", # 2000
98 _coordequi => "CooEqui", # 2000
99  
100 _frame1 => "Frame1",
101 _equi1 => "Equi1",
102 _epoch1 => "Epoch1",
103  
104 _frame2 => "Frame2",
105 _equi2 => "Equi2",
106 _epoch2 => "Epoch2",
107  
108 _frame3 => "Frame3",
109 _equi3 => "Equi3",
110 _epoch3 => "Epoch3",
111 );
112 }
113  
114 =item B<_get_default_options>
115  
116 Get the default query state.
117  
118 =cut
119  
120 0 ▶sub _get_default_options {
Subroutine _get_default_options: not called CC=1 SCAR=6.9
121 return (
122 # Target information
123 0 ra => undef,
124 dec => undef,
125 object => undef,
126 radmax => 0.1,
127 radunits => "arcmin", # For consistency
128 nout => "all",
129  
130 _protocol => "html",
131 _coordepoch => "2000",
132 _coordequi => "2000",
133 _coordframe => "FK5",
134 _nbident => "around",
135 _nbident => "around",
136 _catall => "on",
137 _mesdisp => "A",
138  
139 bibyear1 => 1983,
140 bibyear2 => 2003,
141  
142 # Frame 1, 2 and 3
143 # Frame 1 FK5 2000/2000
144 _frame1 => "FK5",
145 _equi1 => "2000.0",
146 _epoch1 => "2000.0",
147  
148 # Frame 2 FK4 1950/1950
149 _frame2 => "FK4",
150 _equi2 => "1950.0",
151 _epoch2 => "1950.0",
152  
153 # Frame 3 Galactic
154 _frame3 => "G",
155 _equi3 => "2000.0",
156 _epoch3 => "2000.0",
157 );
158 }
159  
160 =item B<_parse_query>
161  
162 Private function used to parse the results returned in a SIMBAD query.
163 Should not be called directly. Instead use the querydb() assessor
164 method to make and parse the results.
165  
166 $cat = $q->_parse_query();
167  
168 Returns an Astro::Catalog object.
169  
170 =cut
171  
172 0 ▶sub _parse_query {
Subroutine _parse_query: not called CC=8 SCAR=42.8
173 0 my $self = shift;
174  
175 # get a local copy of the current BUFFER
176 0 my @buffer = split /\n/, $self->{BUFFER};
177 0 chomp @buffer;
178  
179 # create an Astro::Catalog object to hold the search results
180 0 my $catalog = new Astro::Catalog();
181  
182 # loop round the returned buffer
183 0 my @target; # raw HTML lines, one per object
184 0 foreach my $line (0 ... $#buffer) {
185 # NUMBER OF OBJECTS FOUND IN ERROR CIRCLE
186 0 ▶ if ($buffer[$line] =~ /(\d+)\s+objects: <\/b><pre>/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buffer[$line] =~ m[(\d+)\s+objects: </b><pre>]i) 0 0 0
187 # Number of objects found
188 0 my $number = $1;
189  
190 # GRAB EACH OBJECT - starting from 2 lines after the
191 # current position (since that is the table header and
192 # table separator
193 0 @target = map {$buffer[$_]} ($line+2 ... $line+$number+1);
194  
195 # DROP OUT OF FIRST LOOP
196 0 last;
197 }
198 }
199  
200 # ...and stuff the contents into Object objects
201 0 foreach my $line (@target) {
202 # create a temporary place holder object
203 0 my $star = new Astro::Catalog::Item();
204  
205 # split each line using the "pipe" symbol separating
206 # the table columns
207 0 my @separated = split /\|/, $line;
208  
209 # FRAME
210  
211 # grab the current co-ordinate frame from the query object itself
212 # Assume J2000 for now.
213  
214 # URL
215  
216 # grab the url based on quotes around the string
217 0 my $start_index = index( $separated[0], q/"/ );
218 0 my $last_index = rindex( $separated[0], q/"/ );
219 0 my $url = substr( $separated[0], $start_index+1,
220 $last_index-$start_index-1);
221  
222 # push it into the object
223 0 $star->moreinfo($url);
224  
225 # NAME
226  
227 # get the object name from the same section
228 0 my $final_index = rindex( $separated[0], "A" );
229 0 my $name = substr($separated[0],$last_index+2,$final_index-$last_index-4);
230  
231 # push it into the object
232 0 $star->id($name);
233  
234 # TYPE
235 0 my $type = $separated[1];
236  
237 # dump leading spaces
238 0 $type =~ s/^\s+//g;
239  
240 # push it into the object
241 0 $star->startype( $type );
242  
243 # RA
244  
245 # remove leading spaces
246 0 my $coords = $separated[2];
247 0 $coords =~ s/^\s+//g;
248  
249 # split the RA and Dec line into an array elements
250 0 my @radec = split( /\s+/, $coords );
251  
252 # ...and then rebuild it
253 0 my $ra;
254 0 ▶ unless ($radec[2] =~ '\+' || $radec[2] =~ '-') {
Branch: 1 branch
BranchTrueFalseTotal
if ($radec[2] =~ /\+/ or $radec[2] =~ /-/) { } 0 0 0
Condition0%0/3
$radec[2] =~ /\+/ or $radec[2] =~ /-/
l!l&&r!l&&!r
000
MC/DC0%0/2
$radec[2] =~ /\+/ or $radec[2] =~ /-/
$radec[2] =~ /\+/ $radec[2] =~ /-/
Truth table0%0/3
A or B
A= $radec[2] =~ /\+/B= $radec[2] =~ /-/
ABresult
1X1
011
000
255 0 $ra = "$radec[0] $radec[1] $radec[2]";
256 }
257 else {
258 0 $ra = "$radec[0] $radec[1] 00.0";
259 }
260  
261 # DEC
262  
263 # ...and rebuild the Dec
264 0 my $dec;
265 0 ▶ unless ($radec[2] =~ '\+' || $radec[2] =~ '-') {
Branch: 1 branch
BranchTrueFalseTotal
if ($radec[2] =~ /\+/ or $radec[2] =~ /-/) { } 0 0 0
Condition0%0/3
$radec[2] =~ /\+/ or $radec[2] =~ /-/
l!l&&r!l&&!r
000
MC/DC0%0/2
$radec[2] =~ /\+/ or $radec[2] =~ /-/
$radec[2] =~ /\+/ $radec[2] =~ /-/
Truth table0%0/3
A or B
A= $radec[2] =~ /\+/B= $radec[2] =~ /-/
ABresult
1X1
011
000
266 0 $dec = "$radec[3] $radec[4] $radec[5]";
267 }
268 else {
269 0 $dec = "$radec[2] $radec[3] 00.0";
270 }
271  
272 # Store the coordinates
273 0 $star->coords(new Astro::Coords(
274 name => $name,
275 ra => $ra,
276 dec => $dec,
277 type => "J2000",
278 units => "s",
279 ));
280  
281 # SPECTRAL TYPE
282 0 my $spectral = $separated[4];
283  
284 # remove leading and trailing spaces
285 0 $spectral =~ s/^\s+//g;
286 0 $spectral =~ s/\s+$//g;
287  
288 # push it into the object
289 0 $star->spectype($spectral);
290  
291 # Add the target object to the Astro::Catalog::Item object
292 0 $catalog->pushstar( $star );
293 }
294  
295 # Field centre?
296  
297 # return the catalog
298 0 return $catalog;
299 }
300  
301 =item B<_translate_one_to_one>
302  
303 Return a list of internal options (as defined in C<_get_allowed_options>)
304 that are known to support a one-to-one mapping of the internal value
305 to the external value.
306  
307 %one = $q->_translate_one_to_one();
308  
309 Returns a hash with keys and no values (this makes it easy to
310 check for the option).
311  
312 This method also returns, the values from the parent class.
313  
314 =cut
315  
316 0 ▶sub _translate_one_to_one {
Subroutine _translate_one_to_one: not called CC=1 SCAR=6.9
317 0 my $self = shift;
318 # convert to a hash-list
319 return ($self->SUPER::_translate_one_to_one,
320 0 map { $_, undef }(qw/
321 bibyear1 bibyear2 radunits
322 _protocol _catall _mesdisp _nbident
323 _coordepoch _coordequi _coordframe
324 _epoch1 _frame1 _equi1
325 _epoch2 _frame2 _equi2
326 _epoch3 _frame3 _equi3
327 /)
328 );
329 }
330  
331 1 1;
332  
333 __END__
« Astro/Catalog/IO/VEX.pm ↑ Summary Astro/Catalog/Item.pm »