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