blib/lib/PDL/CCS/IO/FITS.pm

filter: Statementstmt 100% 45 / 45 Branchbran 50.0% 9 / 18 Conditioncond 47.0% 8 / 17 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 72.7% 72 / 99 CC 18 SCAR 23.2
CC
18
Cov
78%
ccs_rfits
14.6
ccs_wfits
11.4
BEGIN
1.0
CRAP 10.2
« CCS/t/06_matops.t ↑ Summary t/common.plt »
1 ## File: PDL::CCS::IO::FITS.pm
2 ## Author: Bryan Jurish <moocow@cpan.org>
3 ## Description: PDL::IO::FITS wrappers for PDL::CCS::Nd
4  
5 package PDL::CCS::IO::FITS;
6 1 ▶use PDL::CCS::Version;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use PDL::CCS::Nd;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use PDL;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use PDL::CCS::IO::Common qw(:intern); ##-- for e.g. _ccsio_write_header, _ccsio_read_header
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Carp qw(confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 our $VERSION = '1.24.1';
14 1 our @ISA = ('PDL::Exporter');
15 1 our @EXPORT_OK =
16 (
17 qw(ccs_wfits ccs_rfits),
18 );
19 1 our %EXPORT_TAGS =
20 (
21 Func => [@EXPORT_OK], ##-- respect PDL conventions (hopefully)
22 );
23  
24  
25  
26 ##======================================================================
27 ## pod: headers
28 =pod
29  
30 =head1 NAME
31  
32 PDL::CCS::IO::FITS - PDL::IO::FITS wrappers for PDL::CCS::Nd
33  
34 =head1 SYNOPSIS
35  
36 use PDL;
37 use PDL::CCS::Nd;
38 use PDL::CCS::IO::FITS;
39  
40 $ccs = PDL::CCS::Nd->newFromWhich($which,$nzvals);
41  
42 ccs_wfits($ccs,$fname); # write a pair of FITS files
43 $ccs2 = ccs_readfits($fname); # read a pair of FITS files
44  
45 =cut
46  
47  
48 ##======================================================================
49 ## I/O utilities
50 =pod
51  
52 =head1 I/O Utilities
53  
54 =cut
55  
56 ##---------------------------------------------------------------
57 ## ccs_wfits
58 =pod
59  
60 =head2 ccs_wfits
61  
62 Write a pair of FITS files using L<PDL::IO::FITS::wfits()|PDL::IO::FITS/wfits>.
63 Piddles of type L<indx|PDL::Core/indx> will be implicitly converted
64 to L<long|PDL::Core/long>, since they are not currently supported by L<PDL::IO::FITS|PDL::IO::FITS> in PDL v2.014.
65  
66 ccs_wfits($ccs,$fname)
67 ccs_wfits($ccs,$fname,\%opts)
68  
69 Options %opts:
70  
71 Header => $Header, ##-- default="$fname.hdr"
72 ixFile => $ixFile, ##-- default="$fname.ix.fits"
73 nzFile => $nzFile, ##-- default="$fname.nz.fits"
74  
75 =cut
76  
77 1 *PDL::ccs_wfits = *PDL::CCS::Nd::wfits = \&ccs_wfits;
78 1 ▶sub ccs_wfits {
Subroutine ccs_wfits: called CC=9 SCAR=24.3
Pod documented
79 1 my ($ccs,$fname,$opts) = @_;
80  
81 ##-- get filenames
82 1 ▶ my $hFile = $opts->{Header} // "$fname.hdr";
Condition50%1/2
$opts->{"Header"} // "$fname.hdr"
l!l
01
MC/DC0%0/1
$opts->{"Header"} // "$fname.hdr"
$opts->{"Header"}
Truth table50%1/2
A
A= $opts->{"Header"}
Aresult
11
00
83 1 ▶ my $ixFile = $opts->{ixFile} // "$fname.ix.fits";
Condition50%1/2
$opts->{"ixFile"} // "$fname.ix.fits"
l!l
01
MC/DC0%0/1
$opts->{"ixFile"} // "$fname.ix.fits"
$opts->{"ixFile"}
Truth table50%1/2
A
A= $opts->{"ixFile"}
Aresult
11
00
84 1 ▶ my $nzFile = $opts->{nzFile} // "$fname.nz.fits";
Condition50%1/2
$opts->{"nzFile"} // "$fname.nz.fits"
l!l
01
MC/DC0%0/1
$opts->{"nzFile"} // "$fname.nz.fits"
$opts->{"nzFile"}
Truth table50%1/2
A
A= $opts->{"nzFile"}
Aresult
11
00
85  
86 ##-- write header
87 1 ▶ _ccsio_write_header($ccs, $hFile)
Branch: 1 branch
BranchTrueFalseTotal
_ccsio_write_header($ccs, $hFile) or confess("ccs_wfits(): failed to write header-file ${hFile}: $!") 1 0 1
88 or confess("ccs_wfits(): failed to write header-file $hFile: $!");
89  
90 ##-- write pdls
91 ## + hack: treat 'indx' as 'long' until PDL::IO::FITS supports it (PDL v2.014 .. v2.016)
92 1 ▶ my $ix = $ccs->_whichND->type->ioname eq 'indx' ? $ccs->_whichND->long : $ccs->_whichND;
Branch: 1 branch
BranchTrueFalseTotal
$ccs->_whichND->type->ioname eq 'indx' ? : 1 0 1
93 1 ▶ my $vals = $ccs->_vals->type->ioname eq 'indx' ? $ccs->_vals->long : $ccs->_vals;
Branch: 1 branch
BranchTrueFalseTotal
$ccs->_vals->type->ioname eq 'indx' ? : 0 1 1
94 1 ▶ PDL::wfits($ix, $ixFile)
Branch: 1 branch
BranchTrueFalseTotal
PDL::wfits($ix, $ixFile) or confess("ccs_wfits(): failed to write index-file ${ixFile}: $!") 1 0 1
95 or confess("ccs_wfits(): failed to write index-file $ixFile: $!");
96 1 ▶ PDL::wfits($vals, $nzFile)
Branch: 1 branch
BranchTrueFalseTotal
PDL::wfits($vals, $nzFile) or confess("ccs_wfits(): failed to write values-file ${nzFile}: $!") 1 0 1
97 or confess("ccs_wfits(): failed to write values-file $nzFile: $!");
98  
99 1 return 1;
100 }
101  
102  
103 ##---------------------------------------------------------------
104 ## ccs_rfits
105 =pod
106  
107 =head2 ccs_rfits
108  
109 Read a pair of FITS files using L<PDL::IO::FITS::rfits()|PDL::IO::FITS/rfits()>.
110  
111 $ccs = ccs_rfits($fname)
112 $ccs = ccs_rfits($fname,\%opts)
113  
114 Options %opts:
115  
116 Header => $Header, ##-- default="$fname.hdr"
117 ixFile => $ixFile, ##-- default="$fname.ix.fits"
118 nzFile => $nzFile, ##-- default="$fname.nz.fits"
119 sorted => $bool, ##-- is data on disk already sorted? (default=1)
120  
121 =cut
122  
123 1 *PDL::ccs_rfits = *PDL::CCS::Nd::rfits = \&ccs_rfits;
124 1 ▶sub ccs_rfits {
Subroutine ccs_rfits: called CC=10 SCAR=26.8
Pod documented
125 1 ▶ shift if (UNIVERSAL::isa($_[0],'PDL') || UNIVERSAL::isa($_[0],'PDL::CCS::Nd'));
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($_[0], "PDL") or UNIVERSAL::isa($_[0], "PDL::CCS::Nd") 0 1 1
Condition33%1/3
UNIVERSAL::isa($_[0], "PDL") or UNIVERSAL::isa($_[0], "PDL::CCS::Nd")
l!l&&r!l&&!r
001
MC/DC0%0/2
UNIVERSAL::isa($_[0], "PDL") or UNIVERSAL::isa($_[0], "PDL::CCS::Nd")
UNIVERSAL::isa($_[0], "PDL") UNIVERSAL::isa($_[0], "PDL::CCS::Nd")
Truth table33%1/3
A or B
A= UNIVERSAL::isa($_[0], "PDL")B= UNIVERSAL::isa($_[0], "PDL::CCS::Nd")
ABresult
1X1
011
000
126 1 my ($fname,$opts) = @_;
127  
128 ##-- get filenames
129 1 ▶ my $hFile = $opts->{Header} // "$fname.hdr";
Condition50%1/2
$opts->{"Header"} // "$fname.hdr"
l!l
01
MC/DC0%0/1
$opts->{"Header"} // "$fname.hdr"
$opts->{"Header"}
Truth table50%1/2
A
A= $opts->{"Header"}
Aresult
11
00
130 1 ▶ my $ixFile = $opts->{ixFile} // "$fname.ix.fits";
Condition50%1/2
$opts->{"ixFile"} // "$fname.ix.fits"
l!l
01
MC/DC0%0/1
$opts->{"ixFile"} // "$fname.ix.fits"
$opts->{"ixFile"}
Truth table50%1/2
A
A= $opts->{"ixFile"}
Aresult
11
00
131 1 ▶ my $nzFile = $opts->{nzFile} // "$fname.nz.fits";
Condition50%1/2
$opts->{"nzFile"} // "$fname.nz.fits"
l!l
01
MC/DC0%0/1
$opts->{"nzFile"} // "$fname.nz.fits"
$opts->{"nzFile"}
Truth table50%1/2
A
A= $opts->{"nzFile"}
Aresult
11
00
132  
133 ##-- read header
134 1 ▶ my $header = _ccsio_read_header($hFile)
Branch: 1 branch
BranchTrueFalseTotal
my $header = _ccsio_read_header($hFile) or confess("ccs_rfits(): failed to read header-file ${hFile}: $!") 1 0 1
135 or confess("ccs_rfits(): failed to read header-file $hFile: $!");
136  
137 ##-- read pdls
138 1 ▶ defined(my $ix = PDL->rfits($ixFile))
Branch: 1 branch
BranchTrueFalseTotal
defined(my $ix = "PDL"->rfits($ixFile)) or confess("ccs_rfits(): failed to read index-file ${ixFile}: $!") 1 0 1
139 or confess("ccs_rfits(): failed to read index-file $ixFile: $!");
140 1 ▶ defined(my $nz = PDL->rfits($nzFile))
Branch: 1 branch
BranchTrueFalseTotal
defined(my $nz = "PDL"->rfits($nzFile)) or confess("ccs_rfits(): failed to read values-file ${nzFile}: $!") 1 0 1
141 or confess("ccs_rfits(): failed to read values-file $nzFile: $!");
142  
143 ##-- construct and return
144 return PDL::CCS::Nd->newFromWhich($ix,$nz,
145 pdims=>$header->{pdims},
146 vdims=>$header->{vdims},
147 flags=>$header->{flags},
148 1 ▶ sorted=>($opts->{sorted}//1),
Condition50%1/2
$opts->{"sorted"} // 1
l!l
01
MC/DC0%0/1
$opts->{"sorted"} // 1
$opts->{"sorted"}
Truth table50%1/2
A
A= $opts->{"sorted"}
Aresult
11
00
149 steal=>1);
150 }
151  
152  
153  
154 1 1; ##-- be happy
155  
156 ##======================================================================
157 ## POD: footer
158 =pod
159  
160 =head1 ACKNOWLEDGEMENTS
161  
162 Perl by Larry Wall.
163  
164 PDL by Karl Glazebrook, Tuomas J. Lukka, Christian Soeller, and others.
165  
166 =cut
167  
168  
169 ##---------------------------------------------------------------------
170 =pod
171  
172 =head1 AUTHOR
173  
174 Bryan Jurish E<lt>moocow@cpan.orgE<gt>
175  
176 =head2 Copyright Policy
177  
178 Copyright (C) 2015-2024, Bryan Jurish. All rights reserved.
179  
180 This package is free software, and entirely without warranty.
181 You may redistribute it and/or modify it under the same terms
182 as Perl itself.
183  
184 =head1 SEE ALSO
185  
186 L<perl>,
187 L<PDL>,
188 L<PDL::CCS::Nd>,
189 L<PDL::CCS::IO::FastRaw>,
190 L<PDL::CCS::IO::MatrixMarket>,
191 L<PDL::CCS::IO::LDAC>,
192 ...
193  
194 =cut
195  
196  
197 1 1; ##-- make perl happy
« CCS/t/06_matops.t ↑ Summary t/common.plt »