@@ -4,6 +4,7 @@ use File::Basename;
4
4
use PDL::LiteF;
5
5
use PDL::Core ' :Internal' ; # For howbig()
6
6
use Test::More;
7
+ use Test::PDL;
7
8
use Test::Exception;
8
9
use PDL::IO::FITS;
9
10
require File::Spec;
@@ -21,24 +22,17 @@ my $t = long xvals(zeroes(11,20))-5;
21
22
wfits($t , $file ); # without a header
22
23
my $t2 = rfits $file ;
23
24
unlike $t2 -> hdr-> {COMMENT }, qr / HASH/ , ' no "HASH" garbage in written header' ;
24
-
25
25
# note: keywords are converted to uppercase
26
26
my %hdr = (' Foo' => ' foo' , ' Bar' => 42, ' NUM' => ' 0123' ,NUMSTR => [' 0123' ]);
27
27
$t -> sethdr(\%hdr );
28
-
29
28
wfits($t , $file );
30
29
$t2 = rfits $file ;
31
-
32
- is( sum($t -> slice(' 0:4,:' )), -sum($t2 -> slice(' 5:-1,:' )),
33
- " r/wfits: slice check" );
34
-
30
+ is_pdl $t2 , $t , ' w/rfits round-trip' ;
35
31
my $h = $t2 -> gethdr;
36
32
ok( $$h {FOO } eq " foo" && $$h {BAR } == 42,
37
33
" header check on FOO/BAR" );
38
-
39
34
ok( $$h {' NUM' }+1 == 124 && $$h {' NUMSTR' } eq ' 0123' ,
40
35
" header check on NUM/NUMSTR" );
41
-
42
36
unlink $file ;
43
37
44
38
SKIP: {
@@ -53,28 +47,6 @@ SKIP: {
53
47
# instead they write out a file, read it back in, and
54
48
# compare to the data used to create the file.
55
49
# So it is more of a "self consistent" test.
56
- #
57
- sub compare_ndarrays ($$$) {
58
- my $orig = shift ;
59
- my $new = shift ;
60
- my $label = shift ;
61
-
62
- TODO: {
63
- local $TODO = " Need to fix alias between PDL_IND and PDL_L or PDL_LL" ;
64
-
65
- is( $new -> type-> symbol, $orig -> type-> symbol, " $label has the correct type" );
66
- }
67
- is( $new -> nelem, $orig -> nelem, " and the right number of elements" );
68
- is( $new -> ndims, $orig -> ndims, " and the right number of dimensions" );
69
-
70
- my $flag ;
71
- if ( $orig -> type() < float() ) {
72
- $flag = all( $new == $orig );
73
- } else {
74
- $flag = all( approx( $orig , $new ) );
75
- }
76
- ok( $flag , " and all the values agree" );
77
- }
78
50
79
51
unless ($PDL::Astro_FITS_Header ) {
80
52
# Astro::FITS::Header is not present, ignore table tests
@@ -99,8 +71,8 @@ unless($PDL::Astro_FITS_Header) {
99
71
is( $$table2 {hdr }{TTYPE2 }, " COLB" , " column #2 is COLB" ); # 11
100
72
is( $$table2 {hdr }{TFORM2 }, " 1D" , " stored as 1D" ); # 12
101
73
102
- compare_ndarrays $x , $$table2 {COLA }, " COLA" ; # 13-16
103
- compare_ndarrays $y , $$table2 {COLB }, " COLB" ; # 17-20
74
+ is_pdl $x , $$table2 {COLA }, " COLA" ; # 13-16
75
+ is_pdl $y , $$table2 {COLB }, " COLB" ; # 17-20
104
76
105
77
$table = { BAR => $x , FOO => $y ,
106
78
hdr => { TTYPE1 => ' FOO' , TTYPE2 => ' BAR' } };
@@ -116,8 +88,8 @@ unless($PDL::Astro_FITS_Header) {
116
88
is( $$table2 {hdr }{TTYPE2 }, " BAR" , " column #2 is BAR" ); # 24
117
89
is( $$table2 {hdr }{TFORM2 }, " 1J" , " stored as 1J" ); # 25
118
90
119
- compare_ndarrays $x , $$table2 {BAR }, " BAR" ; # 26-29
120
- compare_ndarrays $y , $$table2 {FOO }, " FOO" ; # 30-33
91
+ is_pdl $x , $$table2 {BAR }, " BAR" ; # 26-29
92
+ is_pdl $y , $$table2 {FOO }, " FOO" ; # 30-33
121
93
122
94
# try out more "exotic" data types
123
95
@@ -139,12 +111,8 @@ unless($PDL::Astro_FITS_Header) {
139
111
ok( defined $table2 && ref ($table2 ) eq " HASH" && $$table2 {tbl } eq " binary" ,
140
112
" Read in the third binary table" ); # 34
141
113
my @elem = sort keys %$table2 ;
142
- # #my @expected = sort( qw( ACOL BCOL CCOL DCOL ECOL FCOL hdr tbl ) );
143
- # #is ( $#elem+1, 8, "hash contains 8 elements" );
144
114
my @expected = sort ( qw( ACOL BCOL CCOL DCOL ECOL hdr tbl ) );
145
- is ( $#elem +1, 7, " hash contains 7 elements" ); # 35
146
- ok( eq_array( \@elem , \@expected ), " hash contains expected
147
- keys" ); # 36
115
+ is_deeply \@elem , \@expected , " hash contains expected keys" ;
148
116
149
117
# convert the string array so that each element has the same length
150
118
# (and calculate the maximum length to use in the check below)
@@ -173,13 +141,12 @@ unless($PDL::Astro_FITS_Header) {
173
141
is( $$table2 {hdr }{" TFORM$i " }, $$colinfo [1], " and is stored as $$colinfo [1]" ); # 38,44,50,56,59
174
142
my $col = $$table2 {$$colinfo [0]};
175
143
if ( UNIVERSAL::isa($col ," PDL" ) ) {
176
- compare_ndarrays $col , $$colinfo [2], $$colinfo [0]; # 39-42,45-48,51-54,60-63
144
+ is_pdl $col , $$colinfo [2], $$colinfo [0]; # 39-42,45-48,51-54,60-63
177
145
} else {
178
146
# Need to somehow handle the arrays since the data read in from the
179
147
# file all have 15-character length strings (or whatever the length is)
180
148
#
181
- ok( eq_array($col , $$colinfo [2]),
182
- " $$colinfo [0] values agree (as an array reference)" );# 57
149
+ is_deeply $col , $$colinfo [2], " $$colinfo [0] values agree (as an array reference)" ;
183
150
}
184
151
$i ++;
185
152
}
@@ -321,39 +288,34 @@ if(-w dirname($tildefile)) {
321
288
{
322
289
(undef , my $fname ) = File::Temp::tempfile( ' delmeXXXXX' , SUFFIX => ' .fits' , %tmp_opts );
323
290
my $x = sequence(10)-> setbadat(0);
324
- # diag "Writing to fits: $x type = (", $x->get_datatype, ")\n";
325
291
$x -> wfits($fname );
326
292
my $y = rfits($fname );
327
- # diag "Read from fits: $y type = (", $y->get_datatype, ")\n";
328
- ok( $y -> slice(' 0:0' )-> isbad, " rfits/wfits propagated bad flag" );
329
- ok( sum(abs($x -$y )) < 1.0e-5, " and values" );
293
+ is_pdl $y , $x , " wfits/rfits propagated bad flag and values" ;
330
294
# now force to integer
331
295
$x -> wfits($fname ,16);
332
296
$y = rfits($fname );
333
- my $got = $y -> slice(' 0:0' );
334
- ok( $got -> isbad, " wfits coerced bad flag with integer datatype" ) or diag " got: $got (from $y )" ;
335
- ok( sum(abs(convert($x ,short)-$y )) < 1.0e-5, " and the values" );
297
+ is_pdl $y , $x -> short, " integer wfits/rfits propagated bad flag and values" ;
336
298
}
337
299
338
300
{
339
301
my $m51 = rfits(' t/m51.fits.fz' );
340
- is_deeply [ $m51 -> dims], [384,384], ' right dims from compressed FITS file' ;
302
+ is_pdl $m51 -> shape, indx( [384,384]) , ' right dims from compressed FITS file' ;
341
303
(undef , my $fname ) = File::Temp::tempfile( ' delmeXXXXX' , SUFFIX => ' .fits' , %tmp_opts );
342
304
if ($PDL::Astro_FITS_Header ) {
343
305
my $m51_tbl = rfits(' t/m51.fits.fz' ,{expand => 0});
344
306
wfits($m51_tbl , $fname );
345
307
my $m51_2 = rfits($fname );
346
- ok all(approx $m51 , $m51_2 ) , ' read back written-out bintable FITS file' or diag " got: " , $m51_2 -> info ;
308
+ is_pdl $m51_2 , $m51 , ' read back written-out bintable FITS file' ;
347
309
$m51 -> wfits($fname , {compress => 1});
348
310
$m51_2 = rfits($fname );
349
- ok all(approx $m51 , $m51_2 ) , ' read back written-out compressed FITS file' or diag " got: " , $m51_2 -> info ;
311
+ is_pdl $m51_2 , $m51 , ' read back written-out compressed FITS file' ;
350
312
$m51_2 -> hdrcpy(1);
351
313
$m51_2 = $m51_2 -> dummy(2,3)-> sever;
352
314
$m51_2 -> hdr-> {NAXIS } = 3;
353
315
$m51_2 -> hdr-> {NAXIS3 } = 3;
354
316
$m51_2 -> wfits($fname , {compress => 1});
355
317
my $m51_3 = rfits($fname );
356
- ok all(approx $m51_3 , $m51_2 ) , ' read back written-out compressed RGB FITS file' or diag " got: " , $m51_3 -> info ;
318
+ is_pdl $m51_3 , $m51_2 , ' read back written-out compressed RGB FITS file' ;
357
319
}
358
320
}
359
321
0 commit comments