Skip to content

Commit

Permalink
better custom show for large ClimArrays
Browse files Browse the repository at this point in the history
  • Loading branch information
Datseris committed Mar 17, 2021
1 parent d6162bd commit 883fbd4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ClimateBase"
uuid = "35604d93-0fb8-4872-9436-495b01d137e2"
authors = ["Datseris <[email protected]>", "Philippe Roy <[email protected]>"]
version = "0.11.0"
version = "0.11.1"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
27 changes: 26 additions & 1 deletion src/core/coredefs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,13 @@ function Base.show(io::IO, A::ClimArray)
printstyled(io, " data: "; color=:green)
dataA = data(A)
print(io, summary(dataA), "\n")
DimensionalData.custom_show(io, data(A))
x = 2length(dims(A)) + attriblength(A.attrib) + 5
custom_show(io, data(A), x)
end

attriblength(d::AbstractDict) = length(d)
attriblength(d) = 0

# Define summary
function Base.summary(io::IO, A::ClimArray)
l = nameof(typeof(A))
Expand All @@ -163,3 +167,24 @@ function Base.summary(io::IO, A::ClimArray)
print(io, '\n')
end
end

# Thanks to Michael Abbott for the following function
function custom_show(io::IO, A::AbstractArray{T,0}, x) where T
Base.show(IOContext(io, :compact => true, :limit => true), A)
end
function custom_show(io::IO, A::AbstractArray{T,1}, x) where T
Base.show(IOContext(io, :compact => true, :limit => true, :displaysize => displaysize(io) .- (x, 0)), A)
end
function custom_show(io::IO, A::AbstractArray{T,2}, x) where T
Base.print_matrix(IOContext(io, :compact => true, :limit => true, :displaysize => displaysize(io) .- (x, 0)), A)
end
function custom_show(io::IO, A::AbstractArray{T,N}, x) where {T,N}
o = ones(Int, N-2)
frame = A[:, :, o...]
onestring = join(o, ", ")
println(io, "[:, :, $(onestring)]")
Base.print_matrix(
IOContext(io, :compact => true, :limit=>true, :displaysize => displaysize(io) .- (x, 0)),
frame)
print(io, "\n[and ", prod(size(A,d) for d=3:N) - 1," more slices...]")
end

0 comments on commit 883fbd4

Please sign in to comment.