-
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
Added a method to read an image into a pre-allocated array #122
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, this is an awesome first pull request, with documentation and a lot of tests! Thank you so much! This looks overall good to me, I only have two very minor comments, but I'd like to hear Kyle's comments, too 🙂
"Data has $(ndims(hdu)) dimensions whereas the output array has $N dimensions.")) | ||
end | ||
|
||
# Maybe this can be a ShapeMismatch when there's a decision on #16717 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this refers to JuliaLang/julia#16717, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that's what I had in mind
|
||
@testset "non-allocating read" begin | ||
fname1 = tempname() * ".fits" | ||
try |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that instead of using try
/finally
you can open the FITS file with
FITS(fname, "w") do f
# ...
end
which will automatically close it at the end. You can find some examples in this file.
The try
/finally
that you still see here are leftovers of the times where this FITS
method was not available, yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you still need this try...finally block to delete the temp file, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated the tests to use this method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kbarbary there is rm(fname1, force=true)
after the FITS ... do ... end
block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The try finally
might still be necessary to clean up if there's an error, in which case the rm
won't get called. I have fixed this in the latest commit
Additionally, Lines 799 to 801 in 450ddb6
Does
Similarly in |
Reading to a view is interesting, I happen to have this pending pull request for Julia to make |
Yesterday I tested this PR locally and observed that |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice PR! Just a couple minor comments.
|
||
@testset "non-allocating read" begin | ||
fname1 = tempname() * ".fits" | ||
try |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you still need this try...finally block to delete the temp file, no?
src/image.jl
Outdated
end | ||
|
||
fits_assert_open(hdu.fitsfile) | ||
fits_movabs_hdu(hdu.fitsfile, hdu.ext) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two lines should come first in the function, so that fits_get_img_equivtype operates on the intended extension
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have fixed this in the latest commit.
Looks good to me! |
Thank you so much! |
The read method currently used to allocate an array of the correct type and size and read from disk into it. This leads to temporary allocation that might hamper performance if data is read in a loop. In this PR a new method has been added to the non-allocating read! that lets us read from disk into a pre-allocated array.