File Coverage

blib/lib/Astro/Catalog/Query/USNOA2.pm
Criterion Covered Total %
statement 9 9 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 12 12 100.0


line stmt bran cond sub pod time code
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( Coords => new Astro::Coords(),
10             Radius => $radius,
11             Bright => $magbright,
12             Faint => $magfaint,
13             Sort => $sort_type,
14             Number => $number_out );
15              
16             my $catalog = $usno->querydb();
17              
18             =head1 DESCRIPTION
19              
20             The module is an object orientated interface to the online USNO-A2.0
21             catalogue at the ESO/ST-ECF archive site.
22              
23             Stores information about an prospective USNO-A2.0 query and allows the query to
24             be made, returning an Astro::Catalog::USNOA2::Catalog object.
25              
26             The object will by default pick up the proxy information from the HTTP_PROXY
27             and NO_PROXY environment variables, see the LWP::UserAgent documentation for
28             details.
29              
30             See L for the catalog-independent methods.
31              
32             =cut
33              
34             # L O A D M O D U L E S --------------------------------------------------
35              
36 1     1   7501390 use strict;
  1         21  
  1         116  
37 1     1   7 use warnings;
  1         2  
  1         155  
38 1     1   63 use base qw/ Astro::Catalog::Transport::REST /;
  1         3  
  1         1048  
39             use vars qw/ $VERSION /;
40              
41             use File::Spec;
42             use Carp;
43              
44             # generic catalog objects
45             use Astro::Coords;
46             use Astro::Catalog;
47             use Astro::Catalog::Star;
48              
49             use Astro::Flux;
50             use Astro::Fluxes;
51             use Astro::FluxColor;
52             use Number::Uncertainty;
53              
54             $VERSION = "4.31";
55              
56             =head1 REVISION
57              
58             $Id: USNOA2.pm,v 1.8 2005/06/16 01:57:35 aa Exp $
59              
60             =begin __PRIVATE_METHODS__
61              
62             =head2 Private methods
63              
64             These methods are for internal use only.
65              
66             =over 4
67              
68             =item B<_default_remote_host>
69              
70             =cut
71              
72             sub _default_remote_host {
73             return "archive.eso.org";
74             }
75              
76             =item B<_default_url_path>
77              
78             =cut
79              
80             sub _default_url_path {
81             return "skycat/servers/usnoa_res?";
82             }
83              
84             =item B<_get_allowed_options>
85              
86             Returns a hash with keys, being the internal options supported
87             by this subclass, and values being the key name actually required
88             by the remote system (and to be included in the query).
89              
90             =cut
91              
92             sub _get_allowed_options {
93             my $self = shift;
94             return (
95             ra => 'ra',
96             dec => 'dec',
97             object => 'object',
98             radmax => 'radmax',
99             magbright => 'magbright',
100             magfaint => 'magfaint',
101             sort => 'sort',
102             nout => 'nout',
103             format => 'format',
104             );
105             }
106              
107              
108             =item B<_get_default_options>
109              
110             Get the default query state.
111              
112             =cut
113              
114             sub _get_default_options {
115             return (
116             ra => undef,
117             dec => undef,
118             object => undef,
119              
120             radmax => 5,
121             magbright => 0,
122             magfaint => 100,
123             format => 1,
124             sort => 'RA',
125             nout => 2000,
126             );
127             }
128              
129             =item B<_parse_query>
130              
131             Private function used to parse the results returned in an USNO-A2.0 query.
132             Should not be called directly. Instead use the querydb() assessor method to
133             make and parse the results.
134              
135             =cut
136              
137             sub _parse_query {
138             my $self = shift;
139              
140             # get a local copy of the current BUFFER
141             my @buffer = split( /\n/,$self->{BUFFER});
142             chomp @buffer;
143              
144             # create an Astro::Catalog object to hold the search results
145             my $catalog = new Astro::Catalog();
146              
147             # create a temporary object to hold stars
148             my $star;
149              
150             my ( $line, $counter );
151              
152             # Read field centre a line at a time and store it outside the loop
153             my %field;
154              
155             # loop round the returned buffer and stuff the contents into star objects
156             foreach $line ( 0 ... $#buffer ) {
157              
158             # Parse field centre
159             # ------------------
160              
161             # RA
162             if( lc($buffer[$line]) =~ "ra:" ) {
163             $_ = lc($buffer[$line]);
164             my ( $ra ) = /^\s*ra:\s+(.*)<\/td>/;
165             $field{RA} = $ra;
166             }
167              
168             # Dec
169             if( lc($buffer[$line]) =~ "dec:" ) {
170             $_ = lc($buffer[$line]);
171             my ( $dec ) = /^\s+dec:\s+(.*)<\/td>/;
172             $field{Dec} = $dec;
173             }
174              
175             # Radius
176             if( lc($buffer[$line]) =~ "search radius:" ) {
177             $_ = lc($buffer[$line+1]);
178             my ( $radius ) = />\s+(.*)\s\w/;
179             $field{Radius} = $radius;
180             }
181              
182             # Parse list of objects
183             # ---------------------
184              
185             if( lc($buffer[$line]) =~ "
" ) { 
186              
187             # reached the catalog block, loop through until reached
188             $counter = $line+2;
189             until ( lc($buffer[$counter+1]) =~ "" ) {
190              
191             # hack for first line, remove
192             if ( lc($buffer[$counter]) =~ "" ) {
193             $buffer[$counter] = substr( $buffer[$counter], 5);
194             }
195              
196             # remove leading spaces
197             $buffer[$counter] =~ s/^\s+//;
198              
199             # split each line
200             my @separated = split( /\s+/, $buffer[$counter] );
201              
202             # debugging (leave in)
203             #foreach my $thing ( 0 .. $#separated ) {
204             # print " $thing # $separated[$thing] #\n";
205             #}
206              
207             # check that there is something on the line
208             if ( defined $separated[0] ) {
209              
210             # create a temporary place holder object
211             $star = new Astro::Catalog::Star();
212              
213             # ID
214             my $id = $separated[1];
215             #my $num = $counter - $line -2;
216             #print "# ID $id star $num\n";
217             $star->id( $id );
218              
219             # RA
220             my $objra = "$separated[2] $separated[3] $separated[4]";
221              
222             # Dec
223             my $objdec = "$separated[5] $separated[6] $separated[7]";
224              
225             # only generate coordinates if the seconds field of the
226             # dec isn't 60.0, if it is, lets just dump this star as
227             # currently the Astro::Coords object gives totally bogus
228             # answers due to the bogus answers its getting from SLALIB.
229             unless ( $separated[7] == 60 || $separated[4] == 60 ) {
230             $star->coords( new Astro::Coords( ra => $objra,
231             dec => $objdec,
232             units => 'sex',
233             type => 'J2000',
234             name => $star->id(),
235             ) );
236             }
237              
238             # R Magnitude
239             #my %r_mag = ( R => $separated[8] );
240             #$star->magnitudes( \%r_mag );
241              
242             # B Magnitude
243             #my %b_mag = ( B => $separated[9] );
244             #$star->magnitudes( \%b_mag );
245              
246             # Quality
247             my $quality = $separated[10];
248             $star->quality( $quality );
249              
250             # Field
251             my $field = $separated[11];
252             $star->field( $field );
253              
254             # GSC
255             my $gsc = $separated[12];
256             if ( $gsc eq "+" ) {
257             $star->gsc( "TRUE" );
258             } else {
259             $star->gsc( "FALSE" );
260             }
261              
262             # Distance
263             my $distance = $separated[13];
264             $star->distance( $distance );
265              
266             # Position Angle
267             my $pos_angle = $separated[14];
268             $star->posangle( $pos_angle );
269              
270             }
271              
272              
273              
274             # Calculate error
275             # ---------------
276              
277             # Error are calculated as follows
278             #
279             # Delta.R = 0.15*sqrt( 1 + 10**(0.8*(R-19)) )
280             # Delta.B = 0.15*sqrt( 1 + 10**(0.8*(B-19)) )
281             #
282              
283             my ( $power, $delta_r, $delta_b );
284              
285             # delta.R
286             $power = 0.8*( $separated[8] - 19.0 );
287             $delta_r = 0.15* (( 1.0 + ( 10.0 ** $power ) ) ** (1.0/2.0));
288              
289             # delta.B
290             $power = 0.8*( $separated[9] - 19.0 );
291             $delta_b = 0.15* (( 1.0 + ( 10.0 ** $power ) ) ** (1.0/2.0));
292              
293             # mag errors
294             #my %mag_errors = ( B => $delta_b, R => $delta_r );
295             #$star->magerr( \%mag_errors );
296              
297             # calcuate B-R colour and error
298             # -----------------------------
299              
300             # Error is calculated as follows
301             #
302             # Delta.(B-R) = sqrt( Delta.R**2 + Delta.B**2 )
303             #
304              
305             my $b_minus_r = $separated[9] - $separated[8];
306              
307             #my %colours = ( 'B-R' => $b_minus_r );
308             #$star->colours( \%colours );
309              
310             # delta.(B-R)
311             my $delta_bmr = ( ( $delta_r ** 2.0 ) + ( $delta_b ** 2.0 ) ) ** (1.0/2.0);
312              
313             # col errors
314             #my %col_errors = ( 'B-R' => $delta_bmr );
315             #$star->colerr( \%col_errors );
316              
317             $star->fluxes( new Astro::Fluxes(
318             new Astro::Flux(
319             new Number::Uncertainty( Value => $separated[8],
320             Error => $delta_r ),'mag', "R" ),
321             new Astro::Flux(
322             new Number::Uncertainty( Value => $separated[9],
323             Error => $delta_b),'mag', "B" ),
324             new Astro::FluxColor( lower => "R", upper => "B",
325             quantity => new Number::Uncertainty(
326             Value => $b_minus_r,
327             Error => $delta_bmr) ),
328             ));
329              
330             # Push the star into the catalog
331             # ------------------------------
332              
333             # only push the star if the Astro::Coords object is
334             # correctly defined. The Dec might be bogus since the
335             # USNO-A2 catalogue has its seconds field out of
336             # normal range (0-59.9) in some cases.
337             if( $star->coords() ) {
338             $catalog->pushstar( $star );
339             }
340              
341             # increment counter
342             # -----------------
343             $counter = $counter + 1;
344             }
345              
346             # reset $line to correct place
347             $line = $counter;
348             }
349              
350             }
351              
352             # set the field centre
353             $catalog->fieldcentre( %field );
354              
355             return $catalog;
356             }
357              
358             =back
359              
360             =head2 Translation Methods
361              
362             The query options stored internally in the object are not necessarily
363             the form required for a query to a remote server. Methods for converting
364             from the internal representation to the external query format are
365             provided in the form of _from_$opt. ie:
366              
367             ($outkey, $outvalue) = $q->_from_ra();
368             ($outkey, $outvalue) = $q->_from_object();
369              
370             Currently translations are a bit thin on the ground...
371              
372             =cut
373              
374             # None special for subclass
375              
376             =end __PRIVATE_METHODS__
377              
378             =head1 SEE ALSO
379              
380             L, L
381              
382             =head1 COPYRIGHT
383              
384             Copyright (C) 2001 University of Exeter. All Rights Reserved.
385             Some modifications copyright (C) 2003 Particle Physics and Astronomy
386             Research Council. All Rights Reserved.
387              
388             This program was written as part of the eSTAR project and is free software;
389             you can redistribute it and/or modify it under the terms of the GNU Public
390             License.
391              
392             =head1 AUTHORS
393              
394             Alasdair Allan Eaa@astro.ex.ac.ukE,
395             Tim Jenness Etjenness@cpan.orgE
396              
397             =cut
398              
399             # L A S T O R D E R S ------------------------------------------------------
400              
401             1;