Correlate.pm

filter: Statementstmt 17.7% 19 / 107 Branchbran 0.0% 0 / 46 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 30.0% 6 / 20 Podpod 100% 12 / 12 totaltotal 18.2% 37 / 203 CC 29 SCAR 33.9
CC
29
Cov
12%
new
110.0
temp
20.0
catalog1
12.0
CRAP 29.7
« Correlate/Method/FINDOFF.pm ↑ Summary
1 package Astro::Correlate;
2  
3 =head1 NAME
4  
5 Astro::Correlate - Class for cross-correlating astronomical catalogues.
6  
7 =head1 SYNOPSIS
8  
9 use Astro::Correlate;
10  
11 my $corr = new Astro::Correlate( catalog1 => $cat1,
12 catalog2 => $cat2,
13 method => 'FINDOFF' );
14  
15 $result = $corr->correlate;
16  
17 =head1 DESCRIPTION
18  
19 Class for cross-correlating astronomical catalogues.
20  
21 =cut
22  
23 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use warnings::register;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶use File::Temp qw/ tempdir /;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 1 our $VERSION = '1.0';
31  
32 =head1 METHODS
33  
34 =head2 CONSTRUCTOR
35  
36 =over 4
37  
38 =item B<new>
39  
40 Create a new instance of an C<Astro::Correlate> object.
41  
42 $corr = new Astro::Correlate( catalog1 => $cat1,
43 catalog2 => $cat2 );
44  
45 The two mandatory named arguments must be defined and must be
46 C<Astro::Catalog> objects. Both catalogs must be comparable --
47 the C<Astro::Catalog::Star> objects in those catalogs must have
48 x/y or RA/Dec defined, or be able to calculate one from the other
49 using a C<Starlink::AST> FrameSet.
50  
51 =cut
52  
53 0 ▶sub new {
Subroutine new: not called CC=10 SCAR=47.0
Pod documented
54 0 my $proto = shift;
55 0 ▶ my $class = ref( $proto ) || $proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
56  
57 0 my %args = @_;
58  
59 0 ▶ if( ! defined( $args{'catalog1'} ) ||
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"catalog1"} and UNIVERSAL::isa($args{"catalog1"}, "Astro::Catalog") and defined $args{"catalog2"} and UNIVERSAL::isa($args{"catalog2"}, "Astro::Catalog")) 0 0 0
Condition0%0/9
defined $args{"catalog1"} and UNIVERSAL::isa($args{"catalog1"}, "Astro::Catalog") and defined $args{"catalog2"} and UNIVERSAL::isa($args{"catalog2"}, "Astro::Catalog")
!ll&&!rl&&r
000
defined $args{"catalog1"} and UNIVERSAL::isa($args{"catalog1"}, "Astro::Catalog") and defined $args{"catalog2"}
!ll&&!rl&&r
000
defined $args{"catalog1"} and UNIVERSAL::isa($args{"catalog1"}, "Astro::Catalog")
!ll&&!rl&&r
000
MC/DC0%0/4
defined $args{"catalog1"} and UNIVERSAL::isa($args{"catalog1"}, "Astro::Catalog") and defined $args{"catalog2"} and UNIVERSAL::isa($args{"catalog2"}, "Astro::Catalog")
defined $args{"catalog1"} UNIVERSAL::isa($args{"catalog1"}, "Astro::Catalog") defined $args{"catalog2"} UNIVERSAL::isa($args{"catalog2"}, "Astro::Catalog")
Truth table0%0/5
A and B and C and D
A= defined $args{"catalog1"}B= UNIVERSAL::isa($args{"catalog1"}, "Astro::Catalog")C= defined $args{"catalog2"}D= UNIVERSAL::isa($args{"catalog2"}, "Astro::Catalog")
ABCDresult
0XXX0
10XX0
110X0
11100
11111
60 ! UNIVERSAL::isa( $args{'catalog1'}, "Astro::Catalog" ) ||
61 ! defined( $args{'catalog2'} ) ||
62 ! UNIVERSAL::isa( $args{'catalog2'}, "Astro::Catalog" ) ) {
63 0 croak "Must supply two Astro::Catalog objects to Astro::Correlate constructor.\n";
64 }
65  
66 # Create the object.
67 0 my $corr = {};
68 0 bless( $corr, $class );
69  
70 # Configure the object.
71 0 $corr->_configure( \%args );
72  
73 # Set up default options.
74 0 ▶ $corr->keeptemps( 0 ) if ( ! defined( $corr->keeptemps ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $corr->keeptemps 0 0 0
75 0 ▶ $corr->messages( 0 ) if ( ! defined( $corr->messages ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $corr->messages 0 0 0
76 0 ▶ $corr->timeout( 60 ) if ( ! defined( $corr->timeout ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $corr->timeout 0 0 0
77 0 ▶ $corr->temp( tempdir( CLEANUP => ( ! $corr->keeptemps ) ) ) if ( ! defined( $corr->temp ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $corr->temp 0 0 0
78  
79 # And return the object.
80 0 return $corr;
81 }
82  
83 =back
84  
85 =head2 Accessor Methods
86  
87 =over 4
88  
89 =item B<catalog1>
90  
91 Return or set the first catalogue used for correlation.
92  
93 my $catalog = $corr->catalog1;
94 $corr->catalog1( $catalog );
95  
96 Returns an C<Astro::Catalog> object.
97  
98 =cut
99  
100 0 ▶sub catalog1 {
Subroutine catalog1: not called CC=3 SCAR=24.8
Pod documented
101 0 my $self = shift;
102 0 ▶ if( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
103 0 my $cat = shift;
104 0 ▶ if( UNIVERSAL::isa( $cat, "Astro::Catalog" ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($cat, "Astro::Catalog")) 0 0 0
105 0 $self->{CATALOG1} = $cat;
106 }
107 }
108 0 return $self->{CATALOG1};
109 }
110  
111 =item B<catalog2>
112  
113 Return or set the second catalogue used for correlation.
114  
115 my $catalog = $corr->catalog2;
116 $corr->catalog2( $catalog );
117  
118 Returns an C<Astro::Catalog> object.
119  
120 =cut
121  
122 0 ▶sub catalog2 {
Subroutine catalog2: not called CC=3 SCAR=24.8
Pod documented
123 0 my $self = shift;
124 0 ▶ if( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
125 0 my $cat = shift;
126 0 ▶ if( UNIVERSAL::isa( $cat, "Astro::Catalog" ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($cat, "Astro::Catalog")) 0 0 0
127 0 $self->{CATALOG2} = $cat;
128 }
129 }
130 0 return $self->{CATALOG2};
131 }
132  
133 =item B<cat1magtype>
134  
135 The magnitude type to use for the first catalogue.
136  
137 my $magtype = $corr->cat1magtype;
138 $corr->cat1magtype( 'mag_iso' );
139  
140 This is used for Astro::Catalog::Item objects that have Astro::Flux
141 measurements that are not standard magnitudes, and for correlation
142 methods that require a measure of object brightness for optimizations
143 like the RITMatch method. If this is not defined, it will default to
144 'mag'.
145  
146 =cut
147  
148 0 ▶sub cat1magtype {
Subroutine cat1magtype: not called CC=2 SCAR=17.9
Pod documented
149 0 my $self = shift;
150 0 ▶ if( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
151 0 my $magtype = shift;
152 0 $self->{CAT1MAGTYPE} = $magtype;
153 }
154 0 return $self->{CAT1MAGTYPE};
155 }
156  
157 =item B<cat2magtype>
158  
159 The magnitude type to use for the second catalogue.
160  
161 my $magtype = $corr->cat2magtype;
162 $corr->cat2magtype( 'mag_iso' );
163  
164 As for cat1magtype(), but for the second catalogue.
165  
166 =cut
167  
168 0 ▶sub cat2magtype {
Subroutine cat2magtype: not called CC=2 SCAR=17.9
Pod documented
169 0 my $self = shift;
170 0 ▶ if( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
171 0 my $magtype = shift;
172 0 $self->{CAT2MAGTYPE} = $magtype;
173 }
174 0 return $self->{CAT2MAGTYPE};
175 }
176  
177 =item B<keeptemps>
178  
179 Whether or not to keep temporary files after processing is completed.
180  
181 my $keeptemps = $corr->keeptemps;
182 $corr->keeptemps( 1 );
183  
184 Temporary files are created in a temporary directory that is reported
185 during execution. The location of this temporary directory can be
186 controlled using the C<tempdir> method.
187  
188 This parameter defaults to false, so all temporary files are deleted
189 after processing.
190  
191 =cut
192  
193 0 ▶sub keeptemps {
Subroutine keeptemps: not called CC=2 SCAR=17.9
Pod documented
194 0 my $self = shift;
195 0 ▶ if( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
196 0 my $keeptemps = shift;
197 0 $self->{KEEPTEMPS} = $keeptemps;
198 }
199 0 return $self->{KEEPTEMPS};
200 }
201  
202 =item B<messages>
203  
204 Whether or not to display messages from the correlation task while
205 processing.
206  
207 my $messages = $corr->messages;
208 $corr->messages( 1 );
209  
210 If set to true, then messages from the correlation task will be
211 printed.
212  
213 Defaults to false.
214  
215 =cut
216  
217 0 ▶sub messages {
Subroutine messages: not called CC=2 SCAR=17.9
Pod documented
218 0 my $self = shift;
219 0 ▶ if( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
220 0 my $messages = shift;
221 0 $self->{MESSAGES} = $messages;
222 }
223 0 return $self->{MESSAGES};
224 }
225  
226 =item B<method>
227  
228 Retrieve or set the method to be used for correlation.
229  
230 my $method = $corr->method;
231 $corr->method( 'FINDOFF' );
232  
233 The method is case-sensitive.
234  
235 =cut
236  
237 0 ▶sub method {
Subroutine method: not called CC=2 SCAR=17.9
Pod documented
238 0 my $self = shift;
239 0 ▶ if( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
240 0 my $method = shift;
241 0 $self->{METHOD} = $method;
242 }
243 0 return $self->{METHOD};
244 }
245  
246 =item B<temp>
247  
248 Retrieve or set the directory to be used for temporary files.
249  
250 my $temp = $corr->temp;
251 $corr->temp( '/tmp' );
252  
253 If undef (which is the default), a temporary directory will be
254 created using C<File::Temp>.
255  
256 =cut
257  
258 0 ▶sub temp {
Subroutine temp: not called CC=4 SCAR=30.0
Pod documented
259 0 my $self = shift;
260 0 ▶ if( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
261 0 my $temp = shift;
262 0 $self->{TEMP} = $temp;
263 }
264 0 ▶ if( ! defined( $self->{TEMP} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"TEMP"}) 0 0 0
265 0 ▶ $self->{TEMP} = tempdir( CLEANUP => ( defined( $self->keeptemps )
Branch: 1 branch
BranchTrueFalseTotal
defined $self->keeptemps ? : 0 0 0
266 ? ! $self->keeptemps
267 : 1 ) );
268 }
269 0 return $self->{TEMP};
270 }
271  
272 =item B<timeout>
273  
274 Retrieve or set the timeout.
275  
276 my $timeout = $corr->timeout;
277 $corr->timeout( 120 );
278  
279 Time is in seconds and defaults to 60.
280  
281 =cut
282  
283 0 ▶sub timeout {
Subroutine timeout: not called CC=2 SCAR=17.9
Pod documented
284 0 my $self = shift;
285 0 ▶ if( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
286 0 my $timeout = shift;
287 0 $self->{TIMEOUT} = $timeout;
288 }
289 0 return $self->{TIMEOUT};
290 }
291  
292 =item B<verbose>
293  
294 Retrieve or set the verbosity level.
295  
296 my $verbose = $corr->verbose;
297 $corr->verbose( 1 );
298  
299 If set to true, then much output will be output to STD_ERR. Defaults to false.
300  
301 =cut
302  
303 0 ▶sub verbose {
Subroutine verbose: not called CC=2 SCAR=17.9
Pod documented
304 0 my $self = shift;
305 0 ▶ if( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
306 0 my $verbose = shift;
307 0 $self->{VERBOSE} = $verbose;
308 }
309 0 return $self->{VERBOSE};
310 }
311  
312 =back
313  
314 =head2 General Methods
315  
316 =over 4
317  
318 =item B<correlate>
319  
320 Cross-correlates two catalogues using the supplied method.
321  
322 ( $corrcat1, $corrcat2 ) = $corr->correlate;
323  
324 This method returns two catalogues, both containing stars that matched
325 in the two catalogues passed to the constructor. The returned catalogues
326 are C<Astro::Catalog> objects, and each matched C<Astro::Catalog::Star>
327 object has the same ID number in either catalogue.
328  
329 =cut
330  
331 0 ▶sub correlate {
Subroutine correlate: not called CC=3 SCAR=24.8
Pod documented
332 0 my $self = shift;
333  
334 0 ▶ if( ! defined( $self->method ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->method) 0 0 0
335 0 croak "Must supply cross-correlation method";
336 }
337  
338 # Find out what the cross-correlation class is called.
339 0 my $corrclass = _load_corr_plugin( $self->method );
340 0 ▶ if( ! defined( $corrclass ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $corrclass) 0 0 0
341 0 croak "Could not load cross-correlation method class for " . $self->method . " method";
342 }
343  
344 # Set up the correlated catalogues.
345 0 my $corrcat1;
346 my $corrcat2;
347  
348 # And do the correlation.
349 0 ( $corrcat1, $corrcat2 ) = $corrclass->correlate( catalog1 => $self->catalog1,
350 catalog2 => $self->catalog2,
351 cat1magtype => $self->cat1magtype,
352 cat2magtype => $self->cat2magtype,
353 keeptemps => $self->keeptemps,
354 messages => $self->messages,
355 temp => $self->temp,
356 timeout => $self->timeout,
357 verbose => $self->verbose );
358  
359 # Return the correlated catalogues;
360 0 return( $corrcat1, $corrcat2 );
361 }
362  
363 =back
364  
365 =begin __PRIVATE_METHODS__
366  
367 =head2 Private Methods
368  
369 The following methods are private to the module.
370  
371 =over 4
372  
373 =item B<_configure>
374  
375 Configures the object.
376  
377 $auto->_configure( $args );
378  
379 Takes one argument, a hash reference. The hash contains key/value pairs
380 that correspond to the various accessor methods of this module.
381  
382 =cut
383  
384 0 ▶sub _configure {
Subroutine _configure: not called CC=3 SCAR=24.8
385 0 my $self = shift;
386 0 my $args = shift;
387  
388 0 foreach my $key ( keys %$args ) {
389 0 ▶ if( $self->can( $key ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can($key)) 0 0 0
390 0 $self->$key( $args->{$key} );
391 }
392 }
393 }
394  
395 =item B<_load_corr_plugin>
396  
397 Loads a correlation plugin module.
398  
399 $class = _load_corr_plugin( $method );
400  
401 Returns the class name on successful load. If the class cannot be
402 found or loaded, issues a warning and returns undef.
403  
404 =cut
405  
406 0 ▶sub _load_corr_plugin {
Subroutine _load_corr_plugin: not called CC=2 SCAR=17.9
407 0 my $method = shift;
408  
409 # Set the class name.
410 0 my $class = "Astro::Correlate::Method::$method";
411  
412 # Eval the class to see if it loads, issuing a warning
413 # if it fails.
414 0 eval "use $class;";
415 0 ▶ if( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
416 0 warnings::warnif( "Error loading correlation plugin module $class: $@" );
417 0 return undef;
418 }
419  
420 0 return $class;
421 }
422  
423 =back
424  
425 =end __PRIVATE_METHODS__
426  
427 =head1 REVISION
428  
429 $Id$
430  
431 =head1 AUTHORS
432  
433 Brad Cavanagh <brad.cavanagh@gmail.com>
434  
435 =head1 COPYRIGHT
436  
437 Copyright (C) 2005-2006 Particle Physics and Astronomy Research Council.
438 All Rights Reserved.
439  
440 This program is free software; you can redistribute it and/or modify it under
441 the terms of the GNU General Public License as published by the Free Software
442 Foundation; either version 2 of the License, or (at your option) any later
443 version.
444  
445 This program is distributed in the hope that it will be useful,but WITHOUT ANY
446 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
447 PARTICULAR PURPOSE. See the GNU General Public License for more details.
448  
449 You should have received a copy of the GNU General Public License along with
450 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
451 Place,Suite 330, Boston, MA 02111-1307, USA
452  
453 =cut
454  
455 1 1;
« Correlate/Method/FINDOFF.pm ↑ Summary