← Index
Performance Profile   « block view • line view • sub view »
For /wise/base/deliv/dev/bin/framedepth
  Run on Fri May 28 15:23:26 2010
Reported on Fri May 28 15:26:24 2010

File/wise/base/deliv/dev/lib/perl/WISE/FITSIO/Utils.pm
Statements Executed30
Total Time0.002984 seconds

Subroutines — ordered by exclusive time
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
00000WISE::WCS::AUTOLOAD
00000WISE::WCS::BEGIN
00000WISE::WCS::DESTROY
00000WISE::WCS::__ANON__[:34]
00000WISE::WCS::new
00000WISE::WCS::nxpix
00000WISE::WCS::nypix
00000WISE::WCS::pix2wcs
00000WISE::WCS::wcs2pix
00000WISE::WCS::xref
00000WISE::WCS::xscale
00000WISE::WCS::yref
00000WISE::WCS::yscale

LineStmts.Exclusive
Time
Avg.Code
1
236.2e-52.1e-5use strict;
# spent 43µs making 1 call to strict::import
332.6e-58.7e-6use warnings;
# spent 28µs making 1 call to warnings::import
460.000111.9e-5use 5.010;
# spent 36µs making 1 call to feature::import
5
634.6e-51.5e-5use WISE::Env (cfglib=>'/wise/base/deliv/dev/lib/perl');
# spent 541µs making 1 call to WISE::Env::import
7
8# Misc utility FITS-based objects
9
10package WISE::WCS;
11
12# Lightweight WCS package that by-passes the WISE::FITSIO overhead
13
1433.3e-51.1e-5use Astro::FITS::CFITSIO qw(:constants);
# spent 1.90ms making 1 call to Exporter::import
1530.001360.00045use Astro::WCS::LibWCS;
# spent 66µs making 1 call to Exporter::import
16
1732.9e-59.7e-6use vars qw(@ISA @EXPORT @EXPORT_OK $VERSION $AUTOLOAD);
# spent 80µs making 1 call to vars::import
1830.001300.00043use Exporter::Lite;
# spent 50µs making 1 call to Exporter::Lite::import
1911.0e-61.0e-6$VERSION = 1.00;
2012.0e-62.0e-6@ISA = qw();
21
22sub AUTOLOAD {}
23
24sub new {
25 my $this = shift;
26 my $hdr = shift;
27 my $opts = shift || {};
28 my $err = "*** $0/WCS/new";
29 warn("$err: No input header specified.\n"), return if ! $hdr;
30 my $class = ref($this) || $this;
31
32 $this = {};
33
34 my $yell = $this->{yell} = $opts->{warn} ? sub{warn @_} : sub{die @_};
35
36 if(! ref $hdr) {
37 my $file;
38 if(length($hdr) < 2880 || (length($hdr)%2880) != 0) {
39 # Assume a WCS-laden FITS image file name was passed
40 $file = $hdr;
41 my ($stat,$nhdr,$fp);
42 Astro::FITS::CFITSIO::ffopen($fp="",$file,READONLY,$stat=0);
43 $yell->("$err: Unable to open file '$file'; Stat=$stat.\n"), return
44 if ! $fp || $stat;
45 Astro::FITS::CFITSIO::fits_hdr2str($fp,1,$hdr="",$nhdr=0,$stat);
46 $yell->("$err: Unable retrieve from file '$file' (1)".
47 "; Stat=$stat.\n"), return
48 if ! $hdr || $stat;
49 ffclos($fp,$stat);
50 } else {
51 $file = "<STRING>";
52 }
53 $this->{hdrstr} = $hdr;
54 $this->{wcs} = Astro::WCS::LibWCS::wcsinit($hdr);
55 $yell->("$err: Unable to init WCS from file '$file' (1).\n"), return
56 if ! $this->{wcs};
57 } elsif(ref($hdr) =~ /fitsio/i) {
58 # It's a fitsio object, so get the header string
59 my $file = $hdr->file();
60 my $hdr2 = $hdr->hdrstr() or
61 $yell->("$err: Unable to retrieve header from '$file' (2).\n"),
62 return;
63 $hdr = $this->{hdrstr} = $hdr2;
64 $this->{wcs} = Astro::WCS::LibWCS::wcsinit($hdr);
65 $yell->("$err: Unable to init WCS from file '$file' (2).\n"), return
66 if ! $this->{wcs};
67 } else {
68 # Assume WCS keyword values passed directly (bypassing header i/o)
69 # as a hash ref
70 my $nx = $hdr->{nxpix} || $hdr->{npix};
71 my $ny = $hdr->{nypix} || $nx;
72 $this->{wcs} = Astro::WCS::LibWCS::wcskinit
73 ($nx,$ny,
74 $hdr->{ctype1}||'RA---SIN-SIP',
75 $hdr->{ctype2}||'DEC--SIN-SIP',
76 $hdr->{crpix1}//$hdr->{crpix}//($nx/2+0.5),
77 $hdr->{crpix2}//$hdr->{crpix1}//$hdr->{crpix}//($ny/2+0.5),
78 $hdr->{crval1}//$hdr->{lon}//$hdr->{ra},
79 $hdr->{crval2}//$hdr->{lat}//$hdr->{dec},
80 $hdr->{cd}//undef,
81 $hdr->{cdelt1}||(-($hdr->{cdelt}||0)),
82 $hdr->{cdelt2}||(-($hdr->{cdelt1}||0))||$hdr->{cdelt},
83 $hdr->{crota2}//$hdr->{crota}//(-($hdr->{pa}||0)),
84 $hdr->{equinox}||2000,
85 $hdr->{epoch}||0
86 );
87 $yell->("$err: Unable to init WCS from keywords: ",
88 join(", ", map {"$_=$hdr->{$_}"} keys %$hdr),
89 "\n"), return
90 if ! $this->{wcs};
91 }
92
93 return bless $this,$class;
94}
95
96sub DESTROY {
97 $_[0]->wcsfree();
98}
99
100sub wcs2pix {
101 my $this = shift;
102 my $err = "*** $0/WCS/2pix";
103 if(! ref $this) {
104 $this = $this->new(shift) or return;
105 }
106 my $yell = $this->{yell};
107 $yell->("$err: Bad position count; ".@_." not >0 and even.\n"), return
108 if ! @_ || (@_%2) != 0;
109 my ($x,$y,$off);
110 my @out;
111 while(@_) {
112 $this->{wcs}->wcs2pix(shift(@_),shift(@_),$x,$y,$off);
113 push @out, ($x, $y);
114 }
115 return wantarray ? @out : \@out;
116}
117
118sub pix2wcs {
119 my $this = shift;
120 my $err = "*** $0/WCS/2wcs";
121 if(! ref $this) {
122 $this = $this->new(shift) or return;
123 }
124 my $yell = $this->{yell};
125 $yell->("$err: Bad position count; ".@_." not >0 and even.\n"), return
126 if ! @_ || (@_%2) != 0;
127 my ($lon,$lat);
128 my @out;
129 while(@_) {
130 $this->{wcs}->pix2wcs(shift(@_),shift(@_),$lon,$lat);
131 push @out, ($lon,$lat);
132 }
133 return wantarray ? @out : \@out;
134}
135
136sub xref {
137 my $this = shift;
138 return $this->{wcs}->xref();
139}
140
141sub yref {
142 my $this = shift;
143 return $this->{wcs}->yref();
144}
145
146sub xscale {
147 my $this = shift;
148 return $this->{wcs}->xinc();
149}
150
151sub yscale {
152 my $this = shift;
153 return $this->{wcs}->yinc();
154}
155
156sub nxpix {
157 my $this = shift;
158 return $this->{wcs}->nxpix();
159}
160
161sub nypix {
162 my $this = shift;
163 return $this->{wcs}->nypix();
164}
165
16615.0e-65.0e-61;