HolyLab / BlockRegistrationScheduler.jl

Multi-core image registration scheduler
1 stars 0 forks source link

Bug: ImagineFormat.save_header during warping #34

Closed HaoyangRong closed 7 years ago

HaoyangRong commented 7 years ago

I'm reporting an bug with ImagineFormat.save_header(string(basename, ".imagine"), fn, img, Float32) during the warping phase and offering a temporary fix. The error message is as follows:

MethodError: no method matching round(::Type{Int64}, ::Unitful.Quantity{Float64,Unitful.Dimensions{(Unitful.Dimension{:Time}(-1//1),)},Unitful.FreeUnits{(Unitful.Unit{:Second,Unitful.Dimensions{(Unitful.Dimension{:Time}(1//1),)}}(-6,-1//1),),Unitful.Dimensions{(Unitful.Dimension{:Time}(-1//1),)}}})
Closest candidates are:
  round{T<:Integer}(::Type{T<:Integer}, !Matched::Integer) at int.jl:263
  round{T<:Integer}(::Type{T<:Integer}, !Matched::Float16) at float16.jl:107
  round{T<:Union{Signed,Unsigned}}(::Type{T<:Union{Signed,Unsigned}}, !Matched::BigFloat) at mpfr.jl:146
  ...
 in (::ImagineFormat.##62#65)(::IOStream, ::Float64) at ImagineFormat.jl:379
 in writefield(::IOStream, ::String, ::Float64) at ImagineFormat.jl:349
 in writekv(::IOStream, ::Dict{String,Any}, ::Tuple{String,String,String,String,String,String,String,String,String,String,String,String,String,String,String,String,String,String,String,String,String}) at ImagineFormat.jl:341
 in (::ImagineFormat.##59#60{Dict{String,Any}})(::IOStream) at ImagineFormat.jl:309
 in open(::ImagineFormat.##59#60{Dict{String,Any}}, ::String, ::String) at iostream.jl:113
 in save_header at ImagineFormat.jl:300 [inlined]
 in save_header(::String, ::String, ::ImageMetadata.ImageMeta{FixedPointNumbers.Normed{UInt16,14},4,AxisArrays.AxisArray{FixedPointNumbers.Normed{UInt16,14},4,SubArray{FixedPointNumbers.Normed{UInt16,14},4,SharedArray{FixedPointNumbers.Normed{UInt16,14},4},Tuple{UnitRange{Int64},UnitRange{Int64},UnitRange{Int64},Colon},false},Tuple{AxisArrays.Axis{:x,Ranges.LinSpace{Quantity{Float64, Dimensions:{𝐋}, Units:{μm}}}},AxisArrays.Axis{:l,Ranges.LinSpace{Quantity{Float64, Dimensions:{𝐋}, Units:{μm}}}},AxisArrays.Axis{:z,Ranges.LinSpace{Quantity{Float64, Dimensions:{𝐋}, Units:{μm}}}},AxisArrays.Axis{:time,Ranges.LinSpace{Quantity{Float64, Dimensions:{𝐓}, Units:{s}}}}}}}, ::Type{T}) at ImagineFormat.jl:319
 in include_string(::String, ::String) at loading.jl:441
 in include_string(::String, ::String, ::Int64) at eval.jl:28
 in include_string(::Module, ::String, ::String, ::Int64, ::Vararg{Int64,N}) at eval.jl:32
 in (::Atom.##53#56{String,Int64,String})() at eval.jl:40
 in withpath(::Atom.##53#56{String,Int64,String}, ::String) at utils.jl:30
 in withpath(::Function, ::String) at eval.jl:46
 in macro expansion at eval.jl:57 [inlined]
 in (::Atom.##52#55{Dict{String,Any}})() at task.jl:60

Basically, this function tries to read information from the original .imagine file and writes the new .imagine file for the newly created, warped image. If we dig into the source files:

writeus(io,x) = print(io, round(Int, x/μs), " us")
writeMHz(io,x) = print(io, round(Int, x/MHz), " MHz")

When these two functions are called to create a dictionary in ImagineFormat.jl, the round() function complains. If we look back to the original .imagine file, it seems the Imagine on neither OCPI1 or 2 writes anything following vertical shift speed= and readout rate=. So a quick fix is to add some number you make up along with the corresponding unit (in the original .imagine file), such as vertical shift speed= 1 us and readout rate= 0 MHz.

I'm not sure if these two fields could affect downstream data processing. If they are no longer useful, maybe they can be removed from the function for saving Imagine header. Or we can allow flexible reading and writing in that function.

timholy commented 7 years ago

They aren't useful anymore; they are relics of an old Andor CCD camera. We could expunge them from the header written by Imagine. CC @kdw503.

timholy commented 7 years ago

If someone can post a "modern" .imagine file one of us can add a fix for ImagineFormat.

kdw503 commented 7 years ago

This means we don't need these two fields in the .imagine header file anymore, right? I will remove the lines in the Imagine code.

Cody-G commented 7 years ago

Yes, I think they can safely be removed. Our CMOS cameras actually do have a readout rate, but this isn't really useful information--people will only use the exposure time. I've opened an issue in the Imagine repo.

timholy commented 7 years ago

https://github.com/timholy/ImagineFormat.jl/pull/8

timholy commented 7 years ago

The new version of ImagineFormat has been made the default in METADATA, and site packages have been updated on cannon. It doesn't seem that ImagineFormat was installed previously, so either delete your own copy or make sure you update your packages.