-
Notifications
You must be signed in to change notification settings - Fork 3
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
Improve Error message when dim
in bitinformation(data, dim)
too short
#39
Comments
I just add to this that I could imagine that BitInformation.jl would raise a user defined error, which could be as simple as type DimensionalityError <: Exception
end
type DimensionalityErrorTree <: Exception
var::String
end
Base.showerror(io::IO, e:: DimensionalityErrorTree) = print(io, "You try to calculate bitinformation along a (too) short dimension of",e.var, "elements.")
julia> throw(DimensionalityError(Len(data[dim]))) Not sure if this is the correct syntax. I just adapted it from here. This would be easier to catch from calling scripts. |
At the moment we are doing BitInformation.jl/src/mutual_information.jl Lines 103 to 105 in 5f3ebbd
So we count the bits but if the counter is still zero afterwards an AssertionError is triggered.
julia> using BitInformation
julia> A = rand(100);
julia> mask = A .== A;
julia> bitinformation(A,mask)
ERROR: AssertionError: Mask has 0 unmasked values, 0 entries are adjacent.
Stacktrace:
[1] bitinformation(A::Vector{Float64}, mask::BitVector; dim::Int64, set_zero_insignificant::Bool, confidence::Float64)
@ BitInformation ~/.julia/packages/BitInformation/VpaaY/src/mutual_information.jl:105
... Julia has a bunch of error types. I agree that an |
Feel free to suggest error messages. I'd rather have it short and on the point though. I don't think it's the job of an error message to explain how a function is used though, this should be part of the docstring / documentation. On that note I don't think the masked array support ever made it into the documentation ... 😞 |
What do you think about improving the error message when the dimension is too short to run
bitinformation
over it? i.e. when dim only have one or two elements, lets say the user wants to runbitinformation
over atime
dimension (where physically adjacent is recommended and should rather uselon
orlat
).Right now the error message is:
Mask has 347040 unmasked values, 0 entries are adjacent.
which is correct. But maybe the user can get a more explanatory return message or at least warning likeYou try to calculate bitinformation along a (too) short dimension of {length(data[dim])} elements.
Maybe even continuing... bitinformation assumes that adjacents analysis elements are also physically adjacent...
Came up in observingClouds/xbitinfo#97 (comment)
The text was updated successfully, but these errors were encountered: