rafaqz / DimensionalData.jl

Named dimensions and indexing for julia arrays and other data
https://rafaqz.github.io/DimensionalData.jl/stable/
MIT License
262 stars 38 forks source link

Dimension metadata #660

Closed xzackli closed 4 months ago

xzackli commented 4 months ago

I couldn't figure out how to attach metadata to a Dimension, is this possible? I can wrap a MetaArrays.jl or similar, but it seems like a lookup might already have this functionality?

I love your package! I use it to analyze astrophysical data (perhaps similar to ecological modeling). I spent some time today writing an extension with hackish FFT compatibility, as I'd like to preserve a phase in the fourier conjugate dimension so I can reconstruct the spatial frequencies when I inverse FFT.

rafaqz commented 4 months ago

You can! But it goes in the lookup, as Dimension is just a wrapper.

Theres even a helper to do it without constructing the lookup:

x =X(10:20; metadata=Dict())

When you put x in a DimArray format will put the metadata dict in the lookup for you.

For FFT you may also want to extend Lookup if you need anything more than metadata, like custom dispatch. You can extend AbstractSampled to keep most of the selectors etc working as normal.

xzackli commented 4 months ago

Thank you! Yes, that's just what I was looking for. I'd initially gotten confused by

ERROR: UndefVarError: `AutoLookup` not defined

when trying this out in my own Dimensions. That's my own error: I believe it's because the macro evaluates in the calling context, and I hadn't imported AutoLookup.

using DimensionalData: @dim, XDim, AutoLookup
@dim X2 XDim
x = X2(10:20; metadata=Dict())

Thank you again for writing such a useful package!

rafaqz commented 4 months ago

Probably should need to import that!

Maybe a bug in the macro.