diff --git a/src/diskarrayresults.jl b/src/diskarrayresults.jl index a39a677..537764a 100644 --- a/src/diskarrayresults.jl +++ b/src/diskarrayresults.jl @@ -69,4 +69,9 @@ end end function compute(a::DiskArrayEngine.GMWOPResult;runner=LocalRunner,threaded=true,kwargs...) compute!(nothing,a;runner,threaded,kwargs...) +end + +function Base.show(io::IO,::MIME"text/plain",z::GMWOPResult) + println(io, "GMWOPResult of size $(size(z))") + println("Inputs:") end \ No newline at end of file diff --git a/src/mwops.jl b/src/mwops.jl index 3d7037c..657dd2e 100644 --- a/src/mwops.jl +++ b/src/mwops.jl @@ -28,11 +28,16 @@ function Base.show(io::IO,::MIME"text/plain",lw::LoopWindows) print(io,"$li: Window of length $(length(w)) [") showifthere(io,w,1,sep=false) showifthere(io,w,2) - print(io," ... ") - showifthere(io,w,max(length(w)-1,3),sep=false) + if length(w) > 4 + print(io," ... ") + elseif length(w) > 2 + print(io, ", ") + end + showifthere(io,w,max(length(w)-1,3), sep=false) showifthere(io,w,max(length(w),4)) end + print(io, "]") end function showifthere(io,w,i;sep=true) if length(w)>=i diff --git a/src/util/aggregate.jl b/src/util/aggregate.jl index aa58e76..b69e588 100644 --- a/src/util/aggregate.jl +++ b/src/util/aggregate.jl @@ -72,6 +72,17 @@ function gmwop_for_aggregator(agg,dimspec,inar;ismem=false,outchunks=nothing) return GMDWop(tuple(inars),tuple(outspecs),agg.f) end +# Todo Move function to first argument to enable do-blocks +""" + aggregate_diskarray(a, f, dimspec; skipmissing=false, strategy=:auto,outchunks=nothing) + +Aggregate a DiskArray `a` with the aggregation function f. + +Certain functions are special cased and will use OnlineStats if possible to speed up the computation. +This will never happen if you use a do-block. +```julia + aggregate_diskarray(a,mean,(2=>nothing,3=>4,4=>[1,1,1,2,2,2,3,3,3,4,4,4,4,4,5,5,5])) +""" function aggregate_diskarray(a, f, dimspec; skipmissing=false, strategy=:auto,outchunks=nothing) hasmissings = Missing <: eltype(a) @@ -101,7 +112,7 @@ function aggregate_diskarray(a, f, dimspec; skipmissing=false, strategy=:auto,ou p2 = optimize_loopranges(op2,5e8) c1 = actual_io_costs(p1) c2 = actual_io_costs(p2) - #we still prefer direct aggregatoin, so we giv it a slight lead: + #we still prefer direct aggregation, so we give it a slight lead: op = c1*0.9 < c2 ? op1 : op2 results_as_diskarrays(op)[1] else diff --git a/src/util/interpolate.jl b/src/util/interpolate.jl index 5065cad..753257a 100644 --- a/src/util/interpolate.jl +++ b/src/util/interpolate.jl @@ -1,9 +1,10 @@ using Interpolations: BSpline, Linear, NoInterp, extrapolate, interpolate, Flat export interpolate_diskarray, interpolate_diskarray! - +#= function getinterpinds(oldvals::AbstractRange, newvals::AbstractRange) (newvals.-first(oldvals))./step(oldvals).+1 end +=# function getinterpinds(r1,r2) rev = issorted(r1) ? false : issorted(r1,rev=true) ? true : error("Axis values are not sorted") map(r2) do ir diff --git a/test/Project.toml b/test/Project.toml index b77b8f4..0c8d77a 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -3,5 +3,6 @@ Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" DiskArrays = "3c3547ce-8d99-4f5e-a174-61eb10b00ae3" Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" +Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" Zarr = "0a941bbe-ad1d-11e8-39d9-ab76183a1d99" diff --git a/test/runtests.jl b/test/runtests.jl index 84b2b26..8556bfc 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -9,3 +9,4 @@ include("test_distribute.jl") include("test_restart.jl") include("test_graph.jl") include("test_mergeops.jl") +include("test_interpolation.jl") \ No newline at end of file diff --git a/test/test_interpolation.jl b/test/test_interpolation.jl index e69de29..e6f60c2 100644 --- a/test/test_interpolation.jl +++ b/test/test_interpolation.jl @@ -0,0 +1,43 @@ +@testset "Interpolation" begin + a = [i+j for i in 1:5, j in 1:7, k=1:6] + #source coordinates + x = 2.0:2.0:10.0 + y = 2.0:2.0:14.0 + #target coordinates + xedge = 2.0:1.0:10.0 + youter = -5:1.0:19. + redge = interpolate_diskarray(a,(1=>(x,xedge),)) + #compute(r) + @test redge[2,1,1] == 2.5 + @test size(redge) == (9,7, 6) + rout = interpolate_diskarray(a,(2=>(y,youter),)) + @test size(rout) == (5,25, 6) + @test rout[1,1,1] == a[1,1,1] + r = interpolate_diskarray(a, (1=>(x, xedge), 2=>(y, youter))) + @test compute(r)[2,1,1] == 2.5 + @test compute(r)[2,2,1] == 2.5 + @test r[1,13,1] == 4.5 +end + +@testset "Aggregate" begin + using Statistics + a = [i+j+k for i in 1:4, j in 1:5, k in 1:6] + agg_mean = aggregate_diskarray(a, mean, (1=>nothing,)) + @test size(agg_mean) == (1,5,6) + @test agg_mean[:,:,:] == mean(a, dims=1) + agg_max = aggregate_diskarray(a, maximum, (2=>nothing,), strategy=:reduce) + # This gives all ones for some reason + @test_broken agg_max[:,:,:] == maximum(a, dims=2) + agg_sec = aggregate_diskarray(a, mean, (2=>2,)) + # This should work but currently throws a bounds error + @test_throws BoundsError agg_sec[:,:,:] + agg_minimum = aggregate_diskarray(a, minimum, (3=>3,), strategy=:reduce) + @test agg_minimum[:,:,1] == minimum(a, dims=3)[:,:] + @test agg_minimum[:,:,2] == minimum(a, dims=3)[:,:] .+ 3 + @test_broken eltype(agg_minimum) == Int + agg_minimum_direct = aggregate_diskarray(a, minimum, (3=>3,), strategy=:reduce) + @test agg_minimum_direct[:,:,1] == minimum(a, dims=3)[:,:] + @test agg_minimum_direct[:,:,2] == minimum(a, dims=3)[:,:] .+ 3 + @test_broken eltype(agg_minimum_direct) == Int + # Why is the element type of minimum of an Int array Union{Missing, Float64}? +end \ No newline at end of file