Skip to content

Commit

Permalink
wfits handle compressing 3D data - #496
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Oct 23, 2024
1 parent 534bd4f commit 3691c2d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions IO/FITS/FITS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,8 @@ our $tile_compressors = {
die "rfits: error while loading PDL::Compression to pack tile-compressed image.\n\t$@\n" if $@;
my ($tiles, $tbl, $params) = @_;
my $blocksize = $params->{BLOCKSIZE} || 32;
my $tiles_ndims = $tiles->ndims;
$tiles = $tiles->clump(1..$tiles_ndims-1) if $tiles_ndims > 2;
my ($compressed,undef,undef,$len) = $tiles->rice_compress($blocksize);
$tbl->{ZNAME1} = "BLOCKSIZE";
$tbl->{ZVAL1} = $blocksize;
Expand Down
10 changes: 8 additions & 2 deletions IO/FITS/t/fits.t
Original file line number Diff line number Diff line change
Expand Up @@ -339,15 +339,21 @@ ok( sum(abs(convert($x,short)-$y)) < 1.0e-5, " and the values" );
my $m51 = rfits('t/m51.fits.fz');
is_deeply [$m51->dims], [384,384], 'right dims from compressed FITS file';
(undef, my $fname) = File::Temp::tempfile( 'delmeXXXXX', SUFFIX => '.fits', %tmp_opts );
my $m51_2;
if ($PDL::Astro_FITS_Header) {
my $m51_tbl = rfits('t/m51.fits.fz',{expand=>0});
wfits($m51_tbl, $fname);
$m51_2 = rfits($fname);
my $m51_2 = rfits($fname);
ok all(approx $m51, $m51_2), 'read back written-out bintable FITS file' or diag "got:", $m51_2->info;
$m51->wfits($fname, {compress=>1});
$m51_2 = rfits($fname);
ok all(approx $m51, $m51_2), 'read back written-out compressed FITS file' or diag "got:", $m51_2->info;
$m51_2->hdrcpy(1);
$m51_2 = $m51_2->dummy(2,3)->sever;
$m51_2->hdr->{NAXIS} = 3;
$m51_2->hdr->{NAXIS3} = 3;
$m51_2->wfits($fname, {compress=>1});
my $m51_3 = rfits($fname);
ok all(approx $m51_3, $m51_2), 'read back written-out compressed RGB FITS file' or diag "got:", $m51_3->info;
}
}

Expand Down

0 comments on commit 3691c2d

Please sign in to comment.