File Coverage

blib/lib/Astro/Catalog/Query/MPC.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 16 16 100.0


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