Skip to content
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

preservedims in tables #917

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

preservedims in tables #917

wants to merge 3 commits into from

Conversation

rafaqz
Copy link
Owner

@rafaqz rafaqz commented Jan 30, 2025

Forgot to PR this a while ago

Closes #896

@asinghvi17 want to review?

@asinghvi17
Copy link
Collaborator

Will test it out, thanks! @alex-s-gardner this is thing number 1 for saving glacier height histogram as GeoJSON

@asinghvi17
Copy link
Collaborator

This works on this branch but fails when I merge it with master, just FYI

@asinghvi17
Copy link
Collaborator

Also this kind of works the other way around than I had expected, I thought that preservedims would make the dimarray of that dimension, but it makes a dimarray of the other dimensions. See this example:

julia> da = @d sin.(hypot.(X(LinRange(-9,9,100)), Y(LinRange(0, 18, 100))) .+ Ti(LinRange(0, 6pi, 100)))
┌ 100×100×100 DimArray{Float64, 3} ┐
├──────────────────────────────────┴─────────────────────────────────────────────────────────────────────────────── dims ┐
  ↓ X  Sampled{Float64} LinRange{Float64}(-9.0, 9.0, 100) ForwardOrdered Regular Points,
  → Y  Sampled{Float64} LinRange{Float64}(0.0, 18.0, 100) ForwardOrdered Regular Points,
  ↗ Ti Sampled{Float64} LinRange{Float64}(0.0, 18.84955592153876, 100) ForwardOrdered Regular Points
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
[:, :, 1]
 ⋮      ⋱  

julia> DimTable(da; preservedims=(Ti,))
DimTable with 100 rows, 2 columns, and schema:
 :Ti      …  Float64
 :layer1     DimMatrix{Float64, Tuple{X{Sampled{Float64, LinRange{Float64, Int64}, ForwardOrdered, Regular{Float64}, Points, NoMetadata}}, Y{Sampled{Float64, LinRange{Float64, Int64}, ForwardOrdered, Regular{Float64}, Points, NoMetadata}}}, Tuple{Ti{Sampled{Float64, LinRange{Float64, Int64}, ForwardOrdered, Regular{Float64}, Points, NoMetadata}}}, SubArray{Float64, 2, Array{Float64, 3}, Tuple{Slice{OneTo{Int64}}, Slice{OneTo{Int64}}, Int64}, true}, Symbol, NoMetadata}

where I would have expected the dimtable to have columns (X, Y, layer1) where layer1 was a vector of DimVectors in Ti.

src/tables.jl Outdated Show resolved Hide resolved
src/tables.jl Outdated Show resolved Hide resolved
@rafaqz
Copy link
Owner Author

rafaqz commented Jan 31, 2025

Thats what I thought it did too 😆

test/merged.jl Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add the option to not "expand"/flatten dimensions in DimTable
2 participants