Skip to content

Commit

Permalink
Merge pull request #435 from JuliaDataCubes/la/show_dataset
Browse files Browse the repository at this point in the history
do better show for Datasets
  • Loading branch information
lazarusA authored Sep 11, 2024
2 parents 0ccd686 + 48de7fd commit b6b8d14
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 27 deletions.
3 changes: 3 additions & 0 deletions docs/src/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export default defineConfig({
lastUpdated: true,
// cleanUrls: true,
outDir: 'REPLACE_ME_DOCUMENTER_VITEPRESS', // This is required for MarkdownVitepress to work correctly...
head: [
['link', { rel: 'icon', href: 'REPLACE_ME_DOCUMENTER_VITEPRESS_FAVICON' }],
],
// ignoreDeadLinks: true,

markdown: {
Expand Down
Binary file added docs/src/assets/favicon.ico
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/src/development/contributors.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const coreMembers = [
]
},
{
avatar: 'https://pbs.twimg.com/profile_images/1727075196962574336/zB09YH0s_400x400.jpg',
avatar: 'https://avatars.githubusercontent.com/u/19525261?v=4',
name: 'Lazaro Alonso',
title: 'Scientist. Data Visualization',
links: [
Expand Down
7 changes: 4 additions & 3 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ hero:
src: /logo.png
alt: VitePress
actions:
- theme: alt
- theme: brand
text: Get Started
link: /get_started
- theme: alt
Expand All @@ -24,12 +24,13 @@ hero:
features:
- title: Flexible I/O capabilities
details: Open and operate on <font color="#D27D2D">NetCDF</font> and <font color="#D27D2D">Zarr</font> datasets directly. Or bring in data from other sources with ArchGDAL.jl, GRIBDatasets.jl, GeoJSON.jl, HDF5.jl, Shapefile.jl, GeoParquet.jl, etc.
link: /UserGuide/openZarr
link: /UserGuide/read
- title: Interoperability
details: Well integrated with Julia's ecosystem, i.e., distributed operations are native. And plotting with <font color="#D27D2D">Makie.jl</font> is well supported.
- title: Named dimensions and GroupBy(in memory)
details: Apply operations over named dimensions, select values by labels and integers as well as efficient split-apply-combine operations with <font color="#D27D2D">groupby</font> via DimensionalData.jl.
link: /UserGuide/group_by
link: /UserGuide/group
- title: Efficiency
details: Efficient <font color="#D27D2D">mapslices(x) </font> and <font color="#D27D2D">mapCube</font> operations on huge multiple arrays, optimized for high-latency data access (object storage, compressed datasets).
link: /UserGuide/compute
```
86 changes: 63 additions & 23 deletions src/DatasetAPI/Datasets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,35 +91,75 @@ function to_dataset(c;datasetaxis = "Variable", layername = get(c.properties,"na
end

function Base.show(io::IO, ds::Dataset)
sharedaxs = intersect([caxes(c) for (n,c) in ds.cubes]...)
# Find axes shared by all cubes
sharedaxs = length(ds.cubes) > 0 ? intersect([caxes(c) for (n, c) in ds.cubes]...) : ()
# Create a dictionary to store groups of variables by their axes
axis_groups = Dict()
variables_with_shared_axes_only = [] # List to hold variables that share all axes
# Group variables by their axes, excluding shared axes
for (var_name, cube) in ds.cubes
axes = tuple(setdiff(caxes(cube), sharedaxs)...)
if isempty(axes)
push!(variables_with_shared_axes_only, var_name) # Track variables that share all axes
else
if haskey(axis_groups, axes)
push!(axis_groups[axes], var_name)
else
axis_groups[axes] = [var_name]
end
end
end
sorted_axis_groups = sort(collect(axis_groups), by = x -> length(x[2]))
# Print header
println(io, "YAXArray Dataset")

# Print shared axes
println(io, "Shared Axes: ")
show(io, MIME("text/plain"), tuple(sharedaxs...))
println(io,"")
println(io, "Variables: ")
for (k,c) in ds.cubes
specaxes = setdiff(caxes(c), sharedaxs)
println(io, k)
if !isempty(specaxes)
specaxes = setdiff(caxes(c), sharedaxs)
DD.Dimensions.print_dims(io, MIME("text/plain"), tuple(specaxes...))
println(io)
end
#for ax in specaxes
# println(io," └── ")
# DD.Dimensions.show_compact(io, MIME("text/plain"),ax)
#end
end
#foreach(i -> print(io, i, " "), keys(ds.cubes))
#show(io, ds.properties)
if !isempty(ds.properties)
if !isempty(sharedaxs)
DD.Dimensions.print_dims(io, MIME("text/plain"), tuple(sharedaxs...))
println(io, "\n")
else
printstyled(io, "None", color=:light_black)
print(io, "\n")
end
# Print variables that share all axes with sharedaxs (or variable without axis)
if !isempty(variables_with_shared_axes_only)
printstyled(io, "Variables: ", color=:light_blue)
print(io, "\n")
println(io, join(variables_with_shared_axes_only, ", "))
println(io)
print(io,"Properties: ")
end

# If there are additional axes, print variables grouped by those additional axes
if !isempty(sorted_axis_groups)
printstyled(io, "Variables with additional axes:", color=:light_yellow)
for (axes, variables) in sorted_axis_groups
print(io, "\n")
if !isempty(axes)
printstyled(io, " Additional Axes: ", color=:light_black)
print(io, "\n")
DD.Dimensions.print_dims(io, MIME("text/plain"), axes)
println(io)
else
print(io, "\n")
printstyled(io, " No additional axes:", color=:light_black)
print(io, "\n")
end
printstyled(io, " Variables: ", color=:light_blue)
padding = " " ^ 2 # Adjust this number to match the length of " Variables: "
variables_str = join(variables, ", ")
padded_variables = padding * variables_str
print(io, "\n")
println(io, padded_variables)
end
print(io, "\n")
end
# Print properties if they exist
if !isempty(ds.properties)
printstyled(io, "Properties: ", color=:light_yellow)
println(io, ds.properties)
# foreach(i -> print(io, i[1], " => ", i[2], " "), ds.properties)
end
end

function Base.propertynames(x::Dataset, private::Bool = false)
if private
Symbol[:cubes; :axes; :properties; collect(keys(x.cubes)); collect(keys(x.axes))]
Expand Down

0 comments on commit b6b8d14

Please sign in to comment.