-
Notifications
You must be signed in to change notification settings - Fork 29
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
Compressed FITS images with >3 dimensions fail to read #125
Comments
As I already told Benjamin who contacted me privately, I have the feeling this is a CFITSIO bug. @kbarbary do you happen to know if that's the case? @bensetterholm are you able to open this kind of files with other CFITSIO-based software? |
I get the same error with fv, so it seems to be a CFITSIO bug. |
That's good to know, thanks! I think you should report the bug to CFITSIO, see the "Help desk" section of CFITSIO main page. |
I have been in contact with the CFITSIO help desk. They say that opening N-dimensional compressed tables was fixed in CFITSIO v3.47. Noticing that this was implemented in FITSIO.jl in #121 (after the most recent tagged version), I made sure to install the master branch and verified with
However, I still get the same error message as above. Additionally, I was asked by the help desk to try to open the compressed file in the program |
This doesn't sound like a great fix....
I guess you can use the low-level functions in |
I received the following update from the CFITSIO help desk:
I notice that the |
Based on a trick a colleague used in an python script to solve the same issue, I have implemented an extremely kludgy workaround. The idea is the make CFITSIO think that the compressed data is of lower dimension than it actually is and then read it in, which is accomplished by changing key values in the header. However, utilizing this solution in Julia using the high-level interface requires one to read the file twice and to overwrite the original data on the disk, which is risky. Is there any way to "fake" such a solution with the low-level CFITSIO without having to overwrite the original file on disk, i.e. only changing the header structure in RAM and not saving it on close? julia> using FITSIO
julia> function read_compressed(path::AbstractString)
f = FITS(path, "r+")
hdu = f["COMPRESSED_IMAGE"]
head = read_header(hdu)
naxes = head["ZNAXIS"]
naxis = [head["ZNAXIS$(i)"] for i ∈ 1:naxes]
write_key(hdu, "ZNAXIS", 1)
write_key(hdu, "ZNAXIS1", prod(naxis))
close(f)
fmod = FITS(path, "r+")
hdumod = fmod["COMPRESSED_IMAGE"]
data = read(hdumod)
write_key(hdumod, "ZNAXIS", naxes)
write_key(hdumod, "ZNAXIS1", naxis[1])
close(fmod)
return reshape(data, naxis...)
end
read_compressed (generic function with 1 method)
julia> begin
dc = FITS("test.fits", "w")
write(dc, rand(UInt16, (320, 40, 5, 2, 1, 2)))
close(dc)
rm("test.fits.fz", force=true)
run(`fpack test.fits`)
orig_data = FITS("test.fits") do d; read(d[1]); end
comp_data = read_compressed("test.fits.fz")
orig_data == comp_data
end
true
|
I don't think there is an easy way using the high-level interface. My understanding is that you could try calling |
I am able to open compressed FITS files with 1-3 dimension image data. However, for files with data cubes with more than 3 dimensions, trying to read the "image" produces
ERROR: error uncompressing image
.Minimal example:
The text was updated successfully, but these errors were encountered: