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

V1.0fixes #6

Merged
merged 16 commits into from
Aug 10, 2020
Merged

V1.0fixes #6

merged 16 commits into from
Aug 10, 2020

Conversation

MLackner
Copy link
Contributor

I had to change quite a lot for the part where the reader was just skipping lines in the header of the file. I could only test with the files I have at hand. I included these in the test folder. I'm not sure if that's the right way to do it though.

@timholy
Copy link
Member

timholy commented Mar 8, 2019

For some reason src/AndorSIF.jl is listed as a binary file. That makes it difficult to review this PR (click the "Files changed" tab above to see what I mean). Can you explore changing those settings?

@MLackner
Copy link
Contributor Author

MLackner commented May 9, 2019

should be fixed now

Copy link
Member

@timholy timholy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this. Just small stuff and then I think this can be merged.


pixels = read(io, Float32, width, height, frames)
# two additional lines?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only part that seems concerning, assuming that it nominally worked before. (I've never tested this myself.) Since it's "weird," is there way to do a sanity check and make sure you're not accidentally consuming offset (below)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Including either one or both lines yields non-integer values for the test files I have at hand. Also, the data looks correct and if I remember correctly, I checked it against tif files generated alongside the sif files.

src/AndorSIF.jl Outdated
prop = Compat.@compat Dict(
"colorspace" => "Gray",
"spatialorder" => ["y", "x"],
"spatialorder" => ["x", "y"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty outdated now. I'd use permuteddimsview from ImageCore.jl. Likewise, returning Gray{Float32} takes care of the colorspace field. Finally, [1, 1] is the default pixelspacing, better not to include it since folks may want to provide the correct answer (e.g., in microns) using Unitful.jl and AxisArrays.jl. So the only need for the ImageMeta is the ixon header.

src/AndorSIF.jl Outdated
"ixon" => ixon,
"suppress" => Set{Any}(("ixon",)),
"pixelspacing" => [1, 1]
)
if frames > 1
prop["timedim"] = 3
end
Image(float64(pixels), prop)
ImageMeta(pixelmatrix .|> Float64, prop)
Copy link
Member

@timholy timholy May 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see that it's important to return Float64, Gray{Float32} seems entirely appropriate.

@timholy
Copy link
Member

timholy commented Sep 5, 2019

Bump. Given #7, best to get this merged a new version tagged. If there are some things you're uncertain of, just give it your best shot and I'll merge.

@timholy
Copy link
Member

timholy commented Mar 27, 2020

Thanks for continuing to take a crack at this. In .travis.yml, change release to 1. See also my review comments; the colorspace, spatialorder, and pixelspacing all dates from Images prior to version 0.6 (we're now on 0.22). See https://discourse.julialang.org/t/big-changes-in-images-jl-v0-6-0/1786 for more info. Unfortunately all the deprecation warnings are long gone (we kept them for about a year, and even that was hard to maintain while still advancing the package), but you could install Julia 0.6 and then Images 0.6 if you want to get them back to help you perform the upgrade.

src/AndorSIF.jl Outdated
numbytes = 4 * frames * width * height # number of bytes to read
pixelbytes = read(io, numbytes)
pixelarray = reinterpret(Gray{Float32}, pixelbytes)
pixelmatrix = reshape(pixelarray, (height, width)) |> collect
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if it is a good idea to collect the reshaped array. But returning the Reshaped type looked a bit messy.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also do this:

pixelmatrix = Matrix{Gray{Float32}}(undef, height, width)
read!(io, pixelmatrix)

and then it will immediately be in the shape and element type you want.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice trick! That made me realize that there currently was no support for multiple frames. Returning a 3D array would be a solution. I don't know if that's the best, though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's continuous on disk, that would be best. Even better would be to use Mmap.mmap: https://docs.julialang.org/en/latest/stdlib/Mmap/, since it would allow you to "load" a terabyte-sized file without saturating your memory. You can see examples in https://github.com/JuliaIO/NRRD.jl/blob/9202ea1d01c69413104e2e7328f2cbaca06f5ee2/src/NRRD.jl#L242-L243.

Copy link
Member

@timholy timholy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks largely ready to go, thanks!

src/AndorSIF.jl Outdated
numbytes = 4 * frames * width * height # number of bytes to read
pixelbytes = read(io, numbytes)
pixelarray = reinterpret(Gray{Float32}, pixelbytes)
pixelmatrix = reshape(pixelarray, (height, width)) |> collect
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also do this:

pixelmatrix = Matrix{Gray{Float32}}(undef, height, width)
read!(io, pixelmatrix)

and then it will immediately be in the shape and element type you want.

@timholy
Copy link
Member

timholy commented Aug 7, 2020

I think we could merge this as-is, unless you want to do the Mmap thing now. It could be a separate PR if you prefer. Just let me know.

@MLackner
Copy link
Contributor Author

I think we could merge this as-is, unless you want to do the Mmap thing now. It could be a separate PR if you prefer. Just let me know.

With Mmap thing you mean the pixelmatrix = Matrix{Gray{Float32}}(undef, height, width)? That should be in now. I would say ready to merge.

@timholy timholy merged commit ef3d444 into JuliaIO:master Aug 10, 2020
@timholy
Copy link
Member

timholy commented Aug 10, 2020

Well, the mmap could replace that. Here's the issue: Matrix{T}(undef, height, width) requires that you have an amount of RAM in your computer to store height*width objects of size sizeof(T). What if you don't have enough RAM? Well, in principle it should be solvable because the raw data are stored on disk: if you're playing a movie, for example, you only need to have the frame you're viewing at the current time, the rest of the data could stay on disk and you just load what you need "on demand."

That's what memory-mapping does: it "fakes" a giant array, without requiring that you be able to load the whole thing at once. Instead, data are loaded on-demand, but you get the convenience of not having to worry about that and getting to treat the array as if it's just a regular array.

@timholy
Copy link
Member

timholy commented Aug 10, 2020

Hmm, got this error: ef3d444#commitcomment-41335099

From here you can see that even 0.0.3 was released. I've changed this to v0.1.0 and submitted a registration, see JuliaRegistries/General#19264. Because this is now counted as a new package, it will take 3 days before that is merged.

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

Successfully merging this pull request may close these issues.

2 participants