You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm looking to simplify code for managing nested DimArrays and DimStacks.
E.g. feeding nested data to AlgebraOfGraphics.
Maybe a add_dims function? I've prototyped one below that I'm happy to PR.
Motivating Example
My work typically involves exploring nested data structures that are best not laid out as a long-format data table. A (non-obvious) example is visualised in the following plot:
where the titles are bearings [deg], the horizontal axis is sound speed [m/s], the vertical axis is depth [m] and the colour is range [m].
And this is still a simplified version of the type of data I manage probably half my days at work.
The data plotted above is generated by the following code:
##using DimensionalData
using CairoMakie, AlgebraOfGraphics
using DimensionalData: dims
##functionmunk_profile(z::Real; ϵ =7.37e-3)
z̃ =2(z/1300-1)
return1500(
1+ ϵ * (
z̃ -1+exp(-z̃)
)
)
endrand_munk_profile(z::Real) =munk_profile(z) +5rand()
##dimprofile(z, c) =DimArray(c, Dim{:z}(z); name =:c)
dimslice(r, zc) =DimArray(zc, Dim{:r}(r); name =:slice)
dimenvironment(θ, rzc) =DimArray(rzc, Dim{:θ}(θ); name =:environment)
rand_depths() = [0:10:50; 5e3rand(rand(20:30))] |> sort! |> unique!
rand_ranges() = [0; 10e3rand(rand(2:5))] |> sort! |> unique!
rand_dimprofile() =rand_depths() |> zs ->dimprofile(zs, rand_munk_profile.(zs))
rand_dimslice() =rand_ranges() |> rs ->dimslice(rs, [rand_dimprofile() for _ in rs])
rand_environment() = (45|> step ->0: step :360-step) |> θs ->dimenvironment(θs, [rand_dimslice() for _ in θs])
env =rand_environment()
Each bearing Dim{:θ} has a collection of ranges Dim{:r} whose values aren't shared between each θ.
Likewise each Dim{:r} has a collection of depth-sound speed Dim{:z}-Dim{:c} pairs whose z values aren't shared between each r.
(In other words, vector data I guess 😅 but with structures resembling raster data, DimensionalData is the best I've found so far for managing such data.)
I've played around with ways to efficiently and flexibly visualise the above in different ways.
My current preference involves the auxiliary function add_dims I've defined, which behaves like reshape but for DimArrays.
The idea for add_dims is that when you access a DimArray inside another DimArray, that inner DimArray doesn't hold information on the Dim(s) you used to call it.
draw(
sum(
add_dims(
env[θ =At(θ)][r =At(r)],
Dim{:θ}([θ]),
Dim{:r}([r])
) |> data
for θ in45|> step ->0: step :360-step
for r indims(env[θ =At(θ)], :r) |> reverse
)
# * mapping(:c, :z, color = :r, layout = :θ => (θ -> compass_directions[θ]) => presorted)*mapping(:c, :z, color =:r, layout =:θ=> nonnumeric)
*visual(Lines),
scales(;
Color = (; colormap =Reverse(:blues)),
Layout = (; palette = [compass_grid[θ] for θ in compass_bearings])
);
axis = (; yreversed =true)
)
Okay so, what's your question?
My question is, does anyone know any better ways to manage/handle this data, including interaction with AlgebraOfGraphics?
The above is still only a simplified example of the type of data I handle about half by work days.
Re AoG I'll be looking into pagination next as well, excited to see what it can do.
If you guys like add_dims I'm happy to PR it with docs and example of course.
I'm partially open to alternatives. I'd like to avoid pregrouped, it makes my soul hurt and in my opinion goes against the whole declarative syntax idea AoG was made for (but I still understand why pregrouped exists).
Are there other packages of storage structures that work better on this type of vector data but allows dimensional names and indexing, including grammar-of-graphics interoperability like what AoG provides?
The text was updated successfully, but these errors were encountered:
This makes me think refdims should also be table columns
Are you saying it doesn't implement the Tables.jl interface so it won't work out-of-the-box with AoG? I'm about to check it out now and see what it can do.
We could even add a DimNestedArray object that holds other DimArray/DimStack that updates refdims automatically on indexing?
I see. From my superficial understanding, DimArray already has the features for nesting multiple layers, but you have an idea for a new object that would work better?
The automatic refdims update upon indexing would indeed simplify the syntax for passing to AoG.data.
TL; DR
I'm looking to simplify code for managing nested
DimArray
s andDimStack
s.E.g. feeding nested data to
AlgebraOfGraphics
.Maybe a
add_dims
function? I've prototyped one below that I'm happy to PR.Motivating Example
My work typically involves exploring nested data structures that are best not laid out as a long-format data table. A (non-obvious) example is visualised in the following plot:
where the titles are bearings [deg], the horizontal axis is sound speed [m/s], the vertical axis is depth [m] and the colour is range [m].
And this is still a simplified version of the type of data I manage probably half my days at work.
The data plotted above is generated by the following code:
I can show the nested structures of
env
by:Each bearing
Dim{:θ}
has a collection of rangesDim{:r}
whose values aren't shared between eachθ
.Likewise each
Dim{:r}
has a collection of depth-sound speedDim{:z}
-Dim{:c}
pairs whosez
values aren't shared between eachr
.(In other words, vector data I guess 😅 but with structures resembling raster data,
DimensionalData
is the best I've found so far for managing such data.)I've played around with ways to efficiently and flexibly visualise the above in different ways.
My current preference involves the auxiliary function
add_dims
I've defined, which behaves likereshape
but forDimArray
s.The idea for
add_dims
is that when you access aDimArray
inside anotherDimArray
, that innerDimArray
doesn't hold information on theDim
(s) you used to call it.I'll define the compass bearing relationships:
and then plot like so:
Okay so, what's your question?
My question is, does anyone know any better ways to manage/handle this data, including interaction with
AlgebraOfGraphics
?The above is still only a simplified example of the type of data I handle about half by work days.
Re AoG I'll be looking into pagination next as well, excited to see what it can do.
If you guys like
add_dims
I'm happy to PR it with docs and example of course.I'm partially open to alternatives. I'd like to avoid
pregrouped
, it makes my soul hurt and in my opinion goes against the whole declarative syntax idea AoG was made for (but I still understand whypregrouped
exists).Are there other packages of storage structures that work better on this type of vector data but allows dimensional names and indexing, including grammar-of-graphics interoperability like what AoG provides?
The text was updated successfully, but these errors were encountered: