Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IO::FITS doesn't support complex numbers, and maybe should allow memory-mapping on big-endian #496

Open
mohawk2 opened this issue Sep 6, 2024 · 4 comments

Comments

@mohawk2
Copy link
Member

mohawk2 commented Sep 6, 2024

See astropy/astropy#6778 for how to do complex numbers (spoiler: use the 0th dim for real/imaginary).

@mohawk2
Copy link
Member Author

mohawk2 commented Sep 26, 2024

Also, reading back a written-out-compressed byte array is wrong in at least one circumstance (RICE_1 is documented as lossless, https://www.irjet.net/archives/V3/i2/IRJET-V3I2267.pdf), and also can't handle 3D (inc RGB) data:

--- a/IO/FITS/t/fits.t
+++ b/IO/FITS/t/fits.t
@@ -345,6 +345,19 @@ ok all(approx $m51, $m51_2), 'read back written-out bintable FITS file' or diag
 $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;
+eval {$m51_2->wfits($fname, {compress=>1})};
+is $@, '', 'wfits can compress RGB image';
+if (eval 'use PDL::IO::Pic; 1') {
+my $shape = rpic(cfile(($fs->updir)x2, qw(Libtmp Transform Cartography earth_height-2048x1024.jpg)));
+$shape->wfits($fname, {compress=>1});
+my $shape2 = rfits($fname);
+ok all($shape == $shape2), 'rfits compress of byte OK'
+  or diag 'first non-matching indices', +($shape != $shape2)->whichND->slice(',0');
+}
 }
 }
 

@mohawk2
Copy link
Member Author

mohawk2 commented Sep 27, 2024

The current CFITSIO rcomp etc is in https://github.com/HEASARC/cfitsio/blob/develop/ricecomp.c, vs our copy https://github.com/PDLPorters/pdl/blob/master/Libtmp/Compression/ricecomp.c

Some issues on the HEASARC repo remind me that astropy has FITS capability (https://docs.astropy.org/en/stable/io/fits/index.html) so we can use that to compare behaviour.

@mohawk2
Copy link
Member Author

mohawk2 commented Oct 22, 2024

The above-linked commit fixes the decompression error. This was in fact a compression error, which was apparently fixed in CFITSIO in the meantime so I have just updated us to using their latest.

mohawk2 added a commit that referenced this issue Oct 23, 2024
@mohawk2
Copy link
Member Author

mohawk2 commented Oct 23, 2024

The above-linked commit fixes the 3D compression problem, by using the same strategy it looks like fpack etc do: clump higher data dims.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant