Skip to content

Conversation

@Beforerr
Copy link
Contributor

@Beforerr Beforerr commented Aug 21, 2025

Summary

This PR introduces CoordArray, a new dimensional array type that extends AbstractDimArray to support both dimension and non-dimension coordinates.

Key Features

🚀 Intuitive Construction Syntax

da = CoordArray(
    data, 
    (time_dim, x_dim, y_dim, z_dim),
    coords=(; 
        latitude = ((X, Y), lat_grid),
        longitude = ((X, Y), lon_grid),
        elevation = ((Z,), elevation)
    ),
    name="temperature"
)

🔄 Automatic Coordinate Slicing

When indexing a CoordArray, coordinates are automatically sliced to match: subset = da[X(1:2), Y(2:3), Ti(At(DateTime(2020,1,5)))] # coordinates are automatically sliced: lat_grid[1:2, 2:3], etc.

image

Co-Authored-By: Claude [email protected]

## Summary

This PR introduces CoordArray, a new dimensional array type that extends AbstractDimArray to support both dimension coordinates (for indexing and alignment) and non-dimension coordinates (for metadata and spatial information).

## Key Features

🚀 Intuitive Construction Syntax

da = CoordArray(
    data, 
    (time_dim, x_dim, y_dim, z_dim),
    coords=(; 
        latitude = ((X, Y), lat_grid),
        longitude = ((X, Y), lon_grid),
        elevation = ((Z,), elevation)
    ),
    name="temperature"
)

🔄 Automatic Coordinate Slicing

When indexing a CoordArray, coordinates are automatically sliced to match:
subset = da[X(1:2), Y(2:3), Ti(At(DateTime(2020,1,5)))]
# coordinates are automatically sliced: lat_grid[1:2, 2:3], etc.


Co-Authored-By: Claude [email protected]
@codecov
Copy link

codecov bot commented Aug 21, 2025

Codecov Report

❌ Patch coverage is 0% with 63 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@9d08d5e). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/coordarray/show.jl 0.00% 32 Missing ⚠️
src/coordarray/coordarray.jl 0.00% 31 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1086   +/-   ##
=======================================
  Coverage        ?   85.84%           
=======================================
  Files           ?       56           
  Lines           ?     5370           
  Branches        ?        0           
=======================================
  Hits            ?     4610           
  Misses          ?      760           
  Partials        ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rafaqz
Copy link
Owner

rafaqz commented Aug 21, 2025

Hang on a bit... we really try not to introduce new array types, because then your functionality is not available to Rasters.jl or YAXArrays.jl or the other major dependents of this package. Basically AbstractDimArray has to be able to do everything (A large fraction of our users and contributors rarely use DimArray let alone another new array type).

It also wont work in DimStack or DimTree without an explosion of new CoordStack, CoordTree etc etc objects.

So we need to build this functionality into the structure of the dimensions, then its generic.

I do like how simple the coords field makes this.

But if we can do it with just the dims Tuple then it works in all dependent packages automatically keeping a very clean interface. Thats really the number 1 priority for the package.

This means inverting the relationships in your coords objects and stuffing the extra dimensions into fields on the lookups of the main dims Dimensions. And in fact this kind of thing already works, see ArrayLookup.

(And I want to say otherwise this is a great contribution I'm honestly sorry to put the brakes on it like this!! But this package really differentiates itself from AxisArrays.jl, AxisKeys.jl and the other options by intentionally acting as the abstract infrastructure for an ecosystem of other packages with more specific goals. The original reason to write DD at all was that I couldn't extend the array or lookup types in the other package to add my own fields and method dispatches for functionality, plotting, etc specific to spatial data in Rasters.jl)

@Beforerr
Copy link
Contributor Author

Yes I understand. I am also concerned about the design here (so put into a draft and open space for discussion).

I have tried to play with ArrayLookup a little bit, but found it hard to make it work without some tricks (like mimicing a vector as a matrix) and honestly do not know how to put all coordinates into dimension.

I am wondering why it won't work with DimStack or DimTree, since it's just another AbstractDimArray.

@rafaqz
Copy link
Owner

rafaqz commented Aug 21, 2025

Yeah, the interface on these things could be improved. Did you read the tests?

As for why it won't work, both DimStack and DimTree decompose their content DimArrays to the parent objects, the dims Tuple, and lists if dims and metadata for each layer.

The reason for this is consistency: there can only be one source of truth for a dimension.

For example, if one layer has cords and the other does not, what would indexing with coord values mean? And what dimensions columns go into DataFrame(stack)?

There are endless problems like this if DimStack is a collection of DimArray

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.

2 participants