Astro/Catalog/Query/MPC.pm

filter: Statementstmt 50.0% 45 / 90 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 94.1% 16 / 17 Podpod n/a totaltotal 53.0% 61 / 115 CC 6 SCAR 25.0
CC
6
Cov
46%
_parse_query
42.0
BEGIN
1.0
BEGIN
1.0
CRAP 12.2
« Astro/Catalog/Query/GSC.pm ↑ Summary Astro/Catalog/IO/Northstar.pm »
1 package Astro::Catalog::Query::MPC;
2  
3 =head1 NAME
4  
5 Astro::Catalog::Query::MPC - A query request to the Minor Planet Center's
6 Minor Planet Checker.
7  
8 =head1 SYNOPSIS
9  
10 $mpc = new Astro::Catalog::Query::MPC(
11 RA => $ra,
12 Dec => $dec,
13 Year => $year,
14 Month => $month,
15 Day => $day,
16 Radmax => $radius,
17 Limit => $limit,
18 ObsCode => $obscode,
19 );
20  
21 my $catalog = $mpc->querydb();
22  
23 =head1 DESCRIPTION
24  
25 This module provides an object-oriented interface to the Minor Planet
26 Center's Minor Planet Checker webform available at
27 http://scully.harvard.edu/~cgi/CheckMP. It stores information about
28 asteroids found in a search radius at a specific epoch in an
29 C<Astro::Catalog> object.
30  
31 The object will by default pick up the proxy information from the HTTP_PROXY
32 and NO_PROXY environment variables. See the LWP::UserAgent documentation
33 for details.
34  
35 See L<Astro::Catalog::BaseQuery> for the catalog-independent methods.
36  
37 =cut
38  
39 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 2 ▶use base qw/Astro::Catalog::Transport::REST/;
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 2 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 2 ▶use Time::Piece ':override';
Subroutine BEGIN: called CC=1 SCAR=0.0
45 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47 2 ▶use Astro::Catalog;
Subroutine BEGIN: called CC=1 SCAR=0.0
48 2 ▶use Astro::Catalog::Item;
Subroutine BEGIN: called CC=1 SCAR=0.0
49  
50 2 ▶use Astro::Flux;
Subroutine BEGIN: called CC=1 SCAR=0.0
51 2 ▶use Astro::Fluxes;
Subroutine BEGIN: called CC=1 SCAR=0.0
52 2 ▶use Number::Uncertainty;
Subroutine BEGIN: called CC=1 SCAR=0.0
53  
54 2 our $VERSION = '4.38';
55  
56 =begin __PRIVATE_METHODS__
57  
58 =head2 Private Methods
59  
60 These methods are for internal use only.
61  
62 =over 4
63  
64 =item B<_default_remote_host>
65  
66 Defines the default remote host to be scully.harvard.edu.
67  
68 =cut
69  
70 1 ▶sub _default_remote_host {
Subroutine _default_remote_host: called CC=1 SCAR=0.0
71 1 return "scully.harvard.edu";
72 }
73  
74 =item B<_default_url_path>
75  
76 Defines the default URL path to be ~cgi/MPCheck.COM?.
77  
78 =cut
79  
80 1 ▶sub _default_url_path {
Subroutine _default_url_path: called CC=1 SCAR=0.0
81 1 return "~cgi/MPCheck.COM?";
82 }
83  
84 =item B<_get_allowed_options>
85  
86 Returns a hash with key being the internal options supported
87 by this subclass, and values being the key name actually requred
88 by the remote system (and to be included in the query).
89  
90 =cut
91  
92 30 ▶sub _get_allowed_options {
Subroutine _get_allowed_options: called CC=1 SCAR=0.0
93 30 my $self = shift;
94 return (
95 30 ra => 'ra',
96 dec => 'decl',
97 year => 'year',
98 month => 'month',
99 day => 'day',
100 limit => 'limit',
101 obscode => 'oc',
102 which => 'which',
103 mpcsort => 'sort',
104 mot => 'mot',
105 tmot => 'tmot',
106 needed => 'needed',
107 ps => 'ps',
108 type => 'type',
109 radmax => 'radius',
110 textarea => 'TextArea',
111 );
112 }
113  
114 =item B<_get_default_options>
115  
116 Get the default query state.
117  
118 =cut
119  
120 1 ▶sub _get_default_options {
Subroutine _get_default_options: called CC=1 SCAR=0.0
121 1 my $time = gmtime;
122  
123 1 my $day = sprintf("%.2f", $time->mday + ( $time->hour / 24 )
124 + ( $time->min / 1440 ) + ( $time->sec / 86400 ));
125  
126 return (
127 # Hidden and constant options
128 1 which => 'pos',
129 mpcsort => 'd',
130 mot => 'h',
131 tmot => 's',
132 needed => 'f',
133 ps => 'n',
134 type => 'p',
135 textarea => '',
136  
137 # Target information
138 ra => undef,
139 dec => undef,
140 year => $time->year,
141 month => $time->mon,
142 day => $day,
143 obscode => 500,
144  
145 # Limits
146 radmax => 15,
147 limit => 20.0,
148 );
149 }
150  
151 =item B<_parse_query>
152  
153 Private function used to parse the results returned in an MPC query.
154 Should not be called directly. Instead, use the querydb() accessor
155 method to make and parse the results.
156  
157 =cut
158  
159 0 ▶sub _parse_query {
Subroutine _parse_query: not called CC=6 SCAR=37.4
160 0 my $self = shift;
161  
162 # Get a local copy of the current BUFFER.
163 0 my @buffer = split /\n/, $self->{BUFFER};
164 0 chomp @buffer;
165  
166 # Create an Astro::Catalog object to hold the search results.
167 0 my $catalog = new Astro::Catalog();
168  
169 # Create a temporary object to hold stars.
170 0 my $star;
171  
172 0 my ($line, $counter);
173 0 my ($epoch);
174  
175 # Loop around the returned buffer and stuff the contents into
176 # star objects.
177 0 foreach $line ( 0 ... $#buffer ) {
178 # Get the limiting magnitude, field center, radius, and epoch.
179 0 ▶ if ($buffer[$line] =~ /^The following objects/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buffer[$line] =~ /^The following objects/) 0 0 0
180 0 $buffer[$line] =~ /\<i\>V\<\/i\> = ([0-9\.]+), were found in the ([0-9\.]+)-arcminute region around R.A. = ([0-9\. ]+), Decl. = ([\-+0-9\. ]+) \(J2000.0\) on (\d{4}) (\d{2}) ([0-9\.]+)/;
181 0 my $limit = $1;
182 0 my $radius = $2;
183 0 my $ra = $3;
184 0 my $dec = $4;
185 0 my $year = $5;
186 0 my $month = $6;
187 0 my $day = $7;
188  
189 0 my $hour = int(($day - int($day)) * 24);
190 0 my $minute = int(((($day - int($day)) * 24) - $hour) * 60);
191 0 my $second = int(((((($day - int($day)) * 24) - $hour) * 60) - $minute) * 60);
192 0 $day = int($day);
193  
194 0 my $t = Time::Piece->strptime(
195 "$year $month $day $hour $minute $second",
196 "%Y %m %d %H %M %S");
197 0 $epoch = $t->year + ($t->yday / 365.24);
198 }
199  
200 0 ▶ if ($buffer[$line] =~ "<pre>") {
Branch: 1 branch
BranchTrueFalseTotal
if ($buffer[$line] =~ /<pre>/) 0 0 0
201 # We're now in the list of asteroids. Loop through until we
202 # hit </pre>.
203 0 $counter = $line + 4;
204 0 ▶ until ($buffer[$counter] =~ "</pre>") {
Branch: 1 branch
BranchTrueFalseTotal
unless ($buffer[$counter] =~ m[</pre>]) 0 0 0
205 0 my ($name, $ra, $dec, $vmag, $raoff, $decoff, $pm_ra, $pm_dec, $orbit, $comment)
206 = unpack("A24A11A10A6A7A7A7A7A6A*", $buffer[$counter]);
207  
208 0 ▶ if (defined $ra) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ra) 0 0 0
209 0 $star = new Astro::Catalog::Item();
210  
211 0 $name =~ s/^\s+//;
212 0 $star->id( $name );
213  
214 0 $vmag =~ s/^\s+//;
215  
216 0 $star->fluxes(new Astro::Fluxes(new Astro::Flux(
217 new Number::Uncertainty(
218 Value => $vmag ),
219 'mag', "V" )));
220  
221 0 $comment =~ s/^\s+//;
222 0 $star->comment( $comment );
223  
224 # Deal with the coordinates. RA and Dec are almost in the
225 # right format (need to replace separating spaces with colons).
226 0 $ra =~ s/^\s+//;
227 0 $ra =~ s/ /:/g;
228 0 $dec =~ s/^\s+//;
229 0 $dec =~ s/ /:/g;
230  
231 0 my $coords = new Astro::Coords(
232 name => $name,
233 ra => $ra,
234 dec => $dec,
235 type => 'J2000',
236 epoch => $epoch,
237 );
238  
239 0 $star->coords($coords);
240  
241 # Push the star onto the catalog.
242 0 $catalog->pushstar( $star );
243 }
244 0 $counter++;
245 }
246 0 $line = $counter
247 }
248 }
249  
250 0 return $catalog;
251 }
252  
253 =back
254  
255 =head2 Translation Methods
256  
257 The query options stored internally in the object are not necessarily
258 the form required for a query to a remote server. Methods for converting
259 from the internal representation to the external query format are
260 provided in the form of _from_$opt. ie:
261  
262 ($outkey, $outvalue) = $q->_from_ra();
263 ($outkey, $outvalue) = $q->_from_object();
264  
265 The base class only includes one to one mappings.
266  
267 =over 4
268  
269 =item B<_translate_one_to_one>
270  
271 Return a list of internal options (as defined in C<_get_allowed_options>)
272 that are known to support a one-to-one mapping of the internal value
273 to the external value.
274  
275 %one = $q->_translate_one_to_one();
276  
277 Returns a hash with keys and no values (this makes it easy to
278 check for the option).
279  
280 This method also returns the values from the parent class.
281  
282 =cut
283  
284 1 ▶sub _translate_one_to_one {
Subroutine _translate_one_to_one: called CC=1 SCAR=0.0
285 1 my $self = shift;
286 # convert to a hash-list
287 return ($self->SUPER::_translate_one_to_one,
288 1 map {$_, undef} (qw/
289 year month day obscode
290 ra dec radius limit
291 which mot tmot mpcsort
292 needed ps type textarea
293 /)
294 );
295 }
296  
297 2 1;
298  
299 __END__
« Astro/Catalog/Query/GSC.pm ↑ Summary Astro/Catalog/IO/Northstar.pm »