File Coverage

blib/lib/Astro/Catalog/Query/2MASS.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::2MASS;
2              
3             =head1 NAME
4              
5             Astro::Catalog::Query::2MASS - A query request to the 2MASS Catalog
6              
7             =head1 SYNOPSIS
8              
9             $gsc = new Astro::Catalog::Query::2MASS( RA => $ra,
10             Dec => $dec,
11             Radius => $radius,
12             Nout => $number_out );
13              
14             my $catalog = $gsc->querydb();
15              
16             =head1 WARNING
17              
18             This code should be superceeded by the generic Vizier query class.
19              
20             =head1 DESCRIPTION
21              
22             The module is an object orientated interface to the online
23             2MASS.
24              
25             Stores information about an prospective query and allows the query to
26             be made, returning an Astro::Catalog::Query::2MASS object.
27              
28             The object will by default pick up the proxy information from the HTTP_PROXY
29             and NO_PROXY environment variables, see the LWP::UserAgent documentation for
30             details.
31              
32             See L for the catalog-independent methods.
33              
34             =cut
35              
36             # L O A D M O D U L E S --------------------------------------------------
37              
38 1     1   7277948 use 5.006;
  1         11  
  1         85  
39 1     1   8 use strict;
  1         3  
  1         117  
40 1     1   66 use warnings;
  1         3  
  1         144  
41 1     1   6 use base qw/ Astro::Catalog::Transport::REST /;
  1         1  
  1         1362  
42             use vars qw/ $VERSION /;
43              
44             use File::Spec;
45             use Carp;
46              
47             # generic catalog objects
48             use Astro::Catalog;
49             use Astro::Catalog::Star;
50              
51             $VERSION = "4.31";
52              
53             =head1 REVISION
54              
55             $Id: 2MASS.pm,v 1.10 2005/02/04 02:47:53 cavanagh Exp $
56              
57             =begin __PRIVATE_METHODS__
58              
59             =head2 Private methods
60              
61             These methods are for internal use only.
62              
63             =over 4
64              
65             =item B<_default_remote_host>
66              
67             =cut
68              
69             sub _default_remote_host {
70             return "vizier.u-strasbg.fr";
71             }
72              
73             =item B<_default_url_path>
74              
75             =cut
76              
77             sub _default_url_path {
78             return "viz-bin/asu-acl?";
79             }
80              
81             =item B<_get_allowed_options>
82              
83             Returns a hash with keys, being the internal options supported
84             by this subclass, and values being the key name actually required
85             by the remote system (and to be included in the query).
86              
87             =cut
88              
89             sub _get_allowed_options {
90             my $self = shift;
91             return (
92             ra => '-c.ra',
93             dec => '-c.dec',
94             radmax => '-c.rm',
95             nout => '-out.max',
96             catalog => '-source',
97             );
98             }
99              
100              
101             =item B<_get_default_options>
102              
103             Get the default query state.
104              
105             =cut
106              
107             sub _get_default_options {
108             return (
109             # Internal
110             catalog => '2MASS',
111              
112             # Target information
113             ra => undef,
114             dec => undef,
115              
116             # Limits
117             radmax => 5,
118             nout => 20000,
119             );
120             }
121              
122             =item B<_parse_query>
123              
124             Private function used to parse the results returned in an 2MASS query.
125             Should not be called directly. Instead use the querydb() assessor method to
126             make and parse the results.
127              
128             =cut
129              
130             sub _parse_query {
131             my $self = shift;
132              
133             #print $self->{BUFFER};
134             my $query = new Astro::Catalog( Format => 'TST',
135             Data => $self->{BUFFER},
136             Origin => '2MASS Catalogue',
137             ReadOpt => { ra_col => 1, dec_col => 2, id_col => 0 } );
138              
139             # Grab each star in the catalog and add some value to it
140             my $catalog = new Astro::Catalog( );
141             $catalog->origin( $query->origin() );
142             $catalog->set_coords( $query->get_coords() ) if defined $query->get_coords();
143              
144             my ( @oldstars, @newstars );
145             @oldstars = $query->allstars();
146             foreach my $i ( 0 ... $query->sizeof() ) {
147              
148             my $star = $oldstars[$i];
149              
150             # Ungodly hack warning...
151             # -----------------------
152             # We have J, H and K magnitudes, we probably also want some
153             # colours, so lets generate some here and push it into the
154             # star object. This is 2MASS specific so goes here, but in
155             # reality we probably want something general in Star.pm which
156             # dynamically generates colours and errors depending on the
157             # stored magnitudes.
158              
159             # generate the colours
160             my $j_minus_h = $star->get_magnitude( 'J' ) -
161             $star->get_magnitude( 'H' ) if defined $star;
162              
163             my $j_minus_k = $star->get_magnitude( 'J' ) -
164             $star->get_magnitude( 'K' ) if defined $star;
165              
166             my $h_minus_k = $star->get_magnitude( 'H' ) -
167             $star->get_magnitude( 'K' ) if defined $star;
168              
169             # generate the deltas
170             my $delta_j = $star->get_errors( 'J' ) if defined $star;
171             my $delta_h = $star->get_errors( 'H' ) if defined $star;
172             my $delta_k = $star->get_errors( 'K' ) if defined $star;
173              
174             # quick kludge, stars without errors will get flagged bad anyway
175             $delta_j = 0.000 unless defined $delta_j;
176             $delta_h = 0.000 unless defined $delta_h;
177             $delta_k = 0.000 unless defined $delta_k;
178              
179             my $delta_jmh = ( ( $delta_j ** 2.0 ) + ( $delta_h ** 2.0 ) ) ** (1.0/2.0);
180             my $delta_jmk = ( ( $delta_j ** 2.0 ) + ( $delta_k ** 2.0 ) ) ** (1.0/2.0);
181             my $delta_hmk = ( ( $delta_h ** 2.0 ) + ( $delta_k ** 2.0 ) ) ** (1.0/2.0);
182              
183             # fudge accuracy for readable catalogues
184             $j_minus_h = sprintf("%.4f", $j_minus_h ) if defined $star;
185             $j_minus_k = sprintf("%.4f", $j_minus_k ) if defined $star;
186             $h_minus_k = sprintf("%.4f", $h_minus_k ) if defined $star;
187             $delta_jmh = sprintf("%.4f", $delta_jmh ) if defined $star;
188             $delta_jmk = sprintf("%.4f", $delta_jmk ) if defined $star;
189             $delta_hmk = sprintf("%.4f", $delta_hmk ) if defined $star;
190              
191             # generate the hashes
192             my %colours = ( 'J-H' => $j_minus_h,
193             'J-K' => $j_minus_k,
194             'H-K' => $h_minus_k ) if defined $star;
195              
196             my %col_errors = ( 'J-H' => $delta_jmh,
197             'J-K' => $delta_jmk,
198             'H-K' => $delta_hmk ) if defined $star;
199              
200             # append to star object
201             $star->colours( \%colours ) if defined $star;
202             $star->colerr( \%col_errors ) if defined $star;
203              
204             $newstars[$i] = $star if defined $star;
205              
206             }
207             $catalog->pushstar( @newstars );
208              
209             # return the modified catalogue
210             return $catalog;
211             }
212              
213              
214             =back
215              
216             =head2 Translation Methods
217              
218             The query options stored internally in the object are not necessarily
219             the form required for a query to a remote server. Methods for converting
220             from the internal representation to the external query format are
221             provided in the form of _from_$opt. ie:
222              
223             ($outkey, $outvalue) = $q->_from_ra();
224             ($outkey, $outvalue) = $q->_from_object();
225              
226             The base class only includes one to one mappings.
227              
228             =over 4
229              
230             =item B<_translate_one_to_one>
231              
232             Return a list of internal options (as defined in C<_get_allowed_options>)
233             that are known to support a one-to-one mapping of the internal value
234             to the external value.
235              
236             %one = $q->_translate_one_to_one();
237              
238             Returns a hash with keys and no values (this makes it easy to
239             check for the option).
240              
241             This method also returns, the values from the parent class.
242              
243             =cut
244              
245             sub _translate_one_to_one {
246             my $self = shift;
247             # convert to a hash-list
248             return ($self->SUPER::_translate_one_to_one,
249             map { $_, undef }(qw/
250             catalog
251             /)
252             );
253             }
254              
255             =back
256              
257             =end __PRIVATE_METHODS__
258              
259             =head1 COPYRIGHT
260              
261             Copyright (C) 2001 University of Exeter. All Rights Reserved.
262             Some modifications copyright (C) 2003 Particle Physics and Astronomy
263             Research Council. All Rights Reserved.
264              
265             This program was written as part of the eSTAR project and is free software;
266             you can redistribute it and/or modify it under the terms of the GNU Public
267             License.
268              
269             =head1 AUTHORS
270              
271             Alasdair Allan Eaa@astro.ex.ac.ukE,
272             Tim Jenness Etjenness@cpan.orgE
273              
274             =cut
275              
276             # L A S T O R D E R S ------------------------------------------------------
277              
278             1;